In Tailwind CSS, you add opacity to colors by appending a slash and the opacity value (0-100) after the color class, like bg-blue-500/50 for 50% opacity.
Option B is invalid syntax, C applies opacity to the whole element, not just background color, and D is not a valid class.
bg-red-600/30 to a div with white text on a black background?<div class="bg-red-600/30 text-white p-4">Hello</div>The class bg-red-600/30 sets the background color to red with 30% opacity, so the black background behind will show through, making the red appear transparent. The white text remains fully opaque.
opacity-50 and bg-blue-500/50 in Tailwind CSS?opacity-50 changes the opacity of the entire element, including text and children, making everything semi-transparent.
bg-blue-500/50 changes only the background color's opacity, leaving text and other content fully opaque.
<div class="bg-green-400/40">Green</div> <div class="bg-green-400/50">Green</div> <div class="bg-green-400">Green</div>
In CSS, the slash character (/) must be escaped with a backslash when used in class selectors. So .bg-green-400\/40 correctly targets elements with that class.
Option C matches any class containing the string, but could match unintended classes. Option C is invalid syntax. Option C matches only exact class attribute, which is fragile.
bg-gray-900/10 behind text in Tailwind CSS?Using very transparent backgrounds can lower the contrast between text and background, which can make reading difficult for people with low vision or color blindness.
Good accessibility practice requires sufficient contrast to ensure text is readable by everyone.