Effects

Opacity

Utilities for controlling the opacity of an element.

Quick reference

Class
Properties
opacity-0opacity: 0;
opacity-5opacity: 0.05;
opacity-10opacity: 0.1;
opacity-20opacity: 0.2;
opacity-25opacity: 0.25;
opacity-30opacity: 0.3;
opacity-40opacity: 0.4;
opacity-50opacity: 0.5;
opacity-60opacity: 0.6;
opacity-70opacity: 0.7;
opacity-75opacity: 0.75;
opacity-80opacity: 0.8;
opacity-90opacity: 0.9;
opacity-95opacity: 0.95;
opacity-100opacity: 1;

Show all classes

Basic usage

Changing an element’s opacity

Control the opacity of an element using the opacity-{amount} utilities.

Opacity - 图1

  1. <button class="bg-indigo-500 opacity-100 ..."></button>
  2. <button class="bg-indigo-500 opacity-75 ..."></button>
  3. <button class="bg-indigo-500 opacity-50 ..."></button>
  4. <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.

  1. <div class="opacity-50 hover:opacity-100">
  2. <!-- ... -->
  3. </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.

  1. <div class="opacity-50 md:opacity-100">
  2. <!-- ... -->
  3. </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

  1. module.exports = {
  2. theme: {
  3. extend: {
  4. opacity: {
  5. '67': '.67',
  6. }
  7. }
  8. }
  9. }

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.

  1. <div class="opacity-[.67]">
  2. <!-- ... -->
  3. </div>

Learn more about arbitrary value support in the arbitrary values documentation.