Effects
Opacity
Utilities for controlling the opacity of an element.
Quick reference
Class | Properties |
---|---|
opacity-0 | opacity: 0; |
opacity-5 | opacity: 0.05; |
opacity-10 | opacity: 0.1; |
opacity-20 | opacity: 0.2; |
opacity-25 | opacity: 0.25; |
opacity-30 | opacity: 0.3; |
opacity-40 | opacity: 0.4; |
opacity-50 | opacity: 0.5; |
opacity-60 | opacity: 0.6; |
opacity-70 | opacity: 0.7; |
opacity-75 | opacity: 0.75; |
opacity-80 | opacity: 0.8; |
opacity-90 | opacity: 0.9; |
opacity-95 | opacity: 0.95; |
opacity-100 | opacity: 1; |
Show all classes
Basic usage
Changing an element’s opacity
Control the opacity of an element using the opacity-{amount}
utilities.
<button class="bg-indigo-500 opacity-100 ..."></button>
<button class="bg-indigo-500 opacity-75 ..."></button>
<button class="bg-indigo-500 opacity-50 ..."></button>
<button class="bg-indigo-500 opacity-25 ..."></button>
Applying conditionally
Hover, focus, and other states
Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:opacity-100
to only apply the opacity-100
utility on hover.
<div class="opacity-50 hover:opacity-100">
<!-- ... -->
</div>
For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.
Breakpoints and media queries
You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:opacity-100
to apply the opacity-100
utility at only medium screen sizes and above.
<div class="opacity-50 md:opacity-100">
<!-- ... -->
</div>
To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.
Using custom values
Customizing your theme
By default, Tailwind provides several opacity utilities for general purpose use. You can customize these values by editing theme.opacity
or theme.extend.opacity
in your tailwind.config.js
file.
tailwind.config.js
module.exports = { theme: { extend: { opacity: { '67': '.67', } } }}
Learn more about customizing the default theme in the theme customization documentation.
Arbitrary values
If you need to use a one-off opacity
value that doesn’t make sense to include in your theme, use square brackets to generate a property on the fly using any arbitrary value.
<div class="opacity-[.67]">
<!-- ... -->
</div>
Learn more about arbitrary value support in the arbitrary values documentation.