Tailwind CSS Opacity
The opacity utility class in Tailwind CSS allows you to control the transparency of an element.
Tailwind CSS Opacity Utility
The opacity utility in Tailwind CSS controls how transparent or opaque an element appears. It’s a simple yet powerful way to create depth, layering, and emphasis in your designs without writing custom CSS.
How Opacity Works in Tailwind
You can apply transparency to any element using the opacity-value class.
Each value represents a percentage level of visibility, ranging from completely transparent to fully opaque.
Here are the most common opacity classes:
-
opacity-0– Fully transparent (invisible). -
opacity-25– 25% visible. -
opacity-50– 50% visible (semi-transparent). -
opacity-75– 75% visible. -
opacity-100– Fully opaque (default visibility).
<div class="grid grid-cols-3 gap-2"> <div class="bg-red-500 opacity-100 text-white text-center py-4 font-bold"> A </div> <div class="bg-red-500 opacity-50 text-white text-center py-4 font-bold"> B </div> <div class="bg-red-500 opacity-25 text-white text-center py-4 font-bold"> C </div></div>Use when: You want to visually separate elements, create hover effects, or layer content without changing their position.
Preview
A
B
C
Adding Smooth Opacity Transitions
Tailwind also makes it easy to animate opacity changes with transition utilities.
You can use the transition-opacity class to add smooth fading effects when an element’s opacity changes — for example, during hover or state changes.
<div class="opacity-0 hover:opacity-100 transition-opacity duration-500 bg-blue-500 text-white font-semibold p-4 rounded"> Hover to Reveal</div>Use when: You want to fade elements in or out — like tooltips, modals, buttons, or image overlays.
Preview
Hover Me
Responsive Opacity
Like most utilities in Tailwind, opacity classes can be applied responsively at different breakpoints. To do this, prepend the breakpoint prefix (such as sm:, md:, or lg:) to the opacity class.
<div class="opacity-25 md:opacity-50 lg:opacity-100"> Responsive Opacity Example</div>By default, the element has 25% opacity. On medium screens and larger, it becomes 50%, and on large screens, it turns fully opaque. This is useful for creating responsive overlays or adjusting visibility based on screen size.
Real-World Applications of Opacity
Opacity utilities are incredibly versatile in front-end design. Here are a few common use cases:
1. Hover Effects on Images
<img src="image.jpg" class="opacity-70 hover:opacity-100 transition-opacity duration-300 rounded-lg"/>Preview
_Note: _Fades an image in when hovered — great for creating focus or interactivity.
2. Background Overlays
<div class="relative"> <img src="background.jpg" class="w-full h-64 object-cover" /> <div class="absolute inset-0 bg-black opacity-50"></div> <h2 class="absolute inset-0 flex items-center justify-center text-white font-bold text-xl" > Overlay Text </h2></div>Preview
Overlay Text
_Note: _ The semi-transparent overlay helps text stand out over an image background.
3. Disabled Buttons or Elements
<button class="bg-gray-400 text-white px-4 py-2 rounded opacity-50 cursor-not-allowed"> Disabled</button>Preview
_Note: _Lower opacity visually indicates that an element is inactive or unavailable.
4. Subtle UI Layers
<div class="bg-white opacity-90 backdrop-blur-md p-6 rounded-lg shadow-lg"> <p class="text-gray-800"> This semi-transparent panel blends naturally with the background. </p></div>Preview
This semi-transparent panel blends naturally with the background.
_Note: _Commonly used in modals or glassmorphism designs to create layered depth.
Tailwind CSS OPacity Class Table
| 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; |
✨ What's Next?
Windframe Tailwind blocks
Windframe is an AI visual editor for rapidly building stunning web UIs & websites
Start building stunning web UIs & websites!

