Tailwind CSS Opacity
Control element transparency in Tailwind CSS with opacity-0 to opacity-100 utilities. Includes hover effects, conditional opacity, and responsive usage examples.
Interactive Opacity Playground
Try each class live and inspect the CSS output.
opacity-75opacity: 0.75;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).
1<div class="grid grid-cols-3 gap-2">2 <div class="bg-red-500 opacity-100 text-white text-center py-4 font-bold">3 A4 </div>5 <div class="bg-red-500 opacity-50 text-white text-center py-4 font-bold">6 B7 </div>8 <div class="bg-red-500 opacity-25 text-white text-center py-4 font-bold">9 C10 </div>11</div>
Use when: You want to visually separate elements, create hover effects, or layer content without changing their position.
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.
1<div2 class="opacity-0 hover:opacity-100 transition-opacity duration-500 bg-blue-500 text-white font-semibold p-4 rounded"3>4 Hover to Reveal5</div>
Use when: You want to fade elements in or out — like tooltips, modals, buttons, or image overlays.
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.
1<div class="opacity-25 md:opacity-50 lg:opacity-100">2 Responsive Opacity Example3</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
1<img2 src="image.jpg"3 class="opacity-70 hover:opacity-100 transition-opacity duration-300 rounded-lg"4/>
_Note: _Fades an image in when hovered — great for creating focus or interactivity.
2. Background Overlays
1<div class="relative">2 <img src="background.jpg" class="w-full h-64 object-cover" />3 <div class="absolute inset-0 bg-black opacity-50"></div>4 <h25 class="absolute inset-0 flex items-center justify-center text-white font-bold text-xl"6 >7 Overlay Text8 </h2>9</div>
Overlay Text
_Note: _ The semi-transparent overlay helps text stand out over an image background.
3. Disabled Buttons or Elements
1<button2 class="bg-gray-400 text-white px-4 py-2 rounded opacity-50 cursor-not-allowed"3>4 Disabled5</button>
_Note: _Lower opacity visually indicates that an element is inactive or unavailable.
4. Subtle UI Layers
1<div class="bg-white opacity-90 backdrop-blur-md p-6 rounded-lg shadow-lg">2 <p class="text-gray-800">3 This semi-transparent panel blends naturally with the background.4 </p>5</div>
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!

