Opacity modifiers let you make colors see-through. This helps create layers and softer looks on your website.
Opacity modifiers on colors in Tailwind
Start learning this pattern below
Jump into concepts and practice - no test required
bg-color/opacity text-color/opacity border-color/opacity
Opacity is added after a slash / following the color name.
Opacity values go from 0 (fully transparent) to 100 (fully solid).
bg-blue-500/50text-red-600/75border-green-400/30This page shows three examples: a blue box with half opacity background, red text with 75% opacity, and a button with a faint green border at 30% opacity. The button border becomes fully green on hover.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Opacity Modifiers Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="flex flex-col items-center justify-center min-h-screen gap-6 bg-gray-100 p-6"> <div class="w-64 h-24 bg-blue-500/50 flex items-center justify-center rounded"> <p class="text-white font-semibold">Blue 50% opacity</p> </div> <p class="text-red-600/75 font-bold text-lg">Red text 75% opacity</p> <button class="border-4 border-green-400/30 px-6 py-2 rounded hover:border-green-400 transition"> Green border 30% opacity </button> </body> </html>
Opacity modifiers only affect the color they are attached to, not the whole element.
You can combine opacity modifiers with hover or focus states for interactive effects.
Using opacity modifiers keeps your colors consistent but flexible in transparency.
Opacity modifiers add transparency to Tailwind colors using a slash and number.
Values range from 0 (invisible) to 100 (fully visible).
They help create layered, softer, or interactive color effects easily.
Practice
bg-blue-500/50 do to the background color?Solution
Step 1: Understand the opacity modifier syntax
The slash and number after the color (like /50) means opacity percentage in Tailwind.Step 2: Interpret the number 50
50 means 50% opacity, so the color is half transparent.Final Answer:
Sets the background color to blue with 50% opacity -> Option CQuick Check:
bg-blue-500/50 means 50% opacity [OK]
- Confusing 50 with 5 or 100
- Ignoring the slash and treating as normal color
- Thinking opacity is from 0 to 1 instead of 0 to 100
Solution
Step 1: Recall Tailwind opacity syntax
Opacity is added after color with a slash, e.g., /25 for 25% opacity.Step 2: Check each option
Onlybg-red-500/25uses correct slash syntax and valid color code.Final Answer:
bg-red-500/25 -> Option AQuick Check:
Slash before opacity number is correct [OK]
- Using dash instead of slash for opacity
- Putting opacity before color number
- Missing slash entirely
text-green-700/75 is applied?Solution
Step 1: Understand the opacity value in the class
The /75 means 75% opacity, so the color is mostly visible but slightly transparent.Step 2: Match opacity to options
75% opacity means mostly visible, not fully or half transparent.Final Answer:
75% opacity (mostly visible) -> Option AQuick Check:
text-green-700/75 means 75% opacity [OK]
- Mixing 75 with 25 or 50
- Thinking opacity means darkness instead of transparency
- Ignoring the slash and reading as normal color
bg-yellow-400/110 to set background opacity. What is wrong with this?Solution
Step 1: Check valid opacity range
Opacity in Tailwind must be between 0 and 100 inclusive.Step 2: Analyze the given value 110
110 is above 100, so it's invalid and will cause no effect or error.Final Answer:
Opacity value cannot be more than 100 -> Option DQuick Check:
Opacity max is 100, not above [OK]
- Using values above 100
- Confusing slash with dash
- Thinking opacity can be decimal over 1
Solution
Step 1: Set normal background fully visible
Usebg-blue-600for fully opaque blue background (default opacity 100%).Step 2: Set hover background with 40% opacity
Usehover:bg-blue-600/40to apply 40% opacity on hover.Step 3: Check other options for correctness
bg-blue-600/100 hover:bg-blue-600 uses unnecessary /100 and full opacity on hover (no change), bg-blue-600/40 hover:bg-blue-600 reverses opacity states, bg-blue-600 hover:bg-blue-600-40 uses wrong syntax.Final Answer:
bg-blue-600 hover:bg-blue-600/40 -> Option BQuick Check:
Normal full opacity, hover with /40 opacity [OK]
- Using dash instead of slash for opacity
- Setting opacity on normal state instead of hover
- Using /100 opacity unnecessarily
