Here's what you'll build: a frosted glass card on a colourful background, with a shadow that makes the card seem to float. All of it comes from three kinds of class: shadows, see-through, and the glass effect.
A shadow is the dark area under a box. It makes the box look "lifted" off the page, so the eye knows what's in front. Look at a sheet of paper on a desk. When it lies flat on the desk, its shadow is thin and sharp. The higher you lift it, the wider, softer and further down its shadow gets. shadow-sm is the paper lying on the desk, shadow-2xl is the paper lifted high. The two other effects are opacity (see-through) and backdrop-blur (frosted glass, like a bathroom window: you can still see shapes behind it, but blurred).
Shadows: shadow-sm to shadow-2xl
This is a white card with the shadow shadow-lg:
<div class="bg-white rounded-xl p-6 shadow-lg">
Card
</div>
In Tailwind v4, shadow-lg makes this CSS:
box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
- One shadow is written with four sizes: how far it moves sideways (
0), how far down (10px), how blurry it is (15px), and how far it spreads (-3px, a minus means it shrinks). rgb(0 0 0 / 0.1)is black at 10% strength (an opacity of 10%). Tailwind's shadows are faint on purpose, so they look natural.- There are two shadows at once, separated by a comma: a big soft one and a small one close to the box. Together they feel more real.
| Class | How it feels |
|---|---|
shadow-2xs, shadow-xs |
a very thin line of shadow |
shadow-sm |
lying on the page, for an ordinary card |
shadow-md |
lifted a little |
shadow-lg |
clearly lifted, for a dropdown (a menu that opens downward) or a hovered card |
shadow-xl, shadow-2xl |
floating high, for a modal or a dialog (a window that appears on top of the page) |
shadow-none |
no shadow at all (box-shadow: 0 0 #0000) |
In Tailwind v4 the names moved one step from v3: shadow with no size is now the same as shadow-sm, and the old shadow-sm is now shadow-xs.
Shadows can have a colour too: shadow-lg shadow-blue-500/50 makes a blue shadow at 50% strength. shadow-none is useful for removing a shadow in one state, for example active:shadow-none so a button feels "pressed in".
Opacity: see-through
opacity-50 makes opacity: 50%: the whole element becomes half see-through, its text included. The number is a percentage: opacity-0 is gone, opacity-100 is solid.
If only the background should be see-through, write the strength on the background colour after a slash: bg-white/30 means white at 30% strength. The text stays crisp.
| Class | What becomes see-through |
|---|---|
opacity-50 |
the whole element: background, text, border, what's inside |
bg-white/30 |
the background only |
The glass effect: backdrop-blur
backdrop-blur-md blurs whatever is behind the element, by 12px. For that back part to show, the element's background has to be see-through. This is the card from the exercise and the Lab, on a colourful background:
<div class="relative bg-gradient-to-br from-pink-400 to-blue-500 p-8">
<div class="absolute left-6 top-6 h-20 w-20 rounded-full bg-amber-300"></div>
<div id="glass" class="relative backdrop-blur-md bg-white/30 rounded-xl p-6 shadow-xl">
Glass Effect
</div>
</div>
bg-gradient-to-br from-pink-400 to-blue-500paints the parent (the outer<div>) with a pink to blue gradient. In Tailwind v4, its new name isbg-linear-to-br.- A yellow circle (
absolute ... rounded-full bg-amber-300) sits behind the card. A sharp shape like this circle is needed, because a smooth gradient hardly changes when it's blurred. relativeon the card puts it in front of theabsolutecircle, because the card is written after the circle in the HTML (as in the position and z-index lesson).backdrop-blur-mdblurs the circle and the gradient behind the card.bg-white/30adds a thin white layer, so the card looks like frosted glass.rounded-xlgives 12px corners,p-624px of padding,shadow-xla shadow that makes the card float.
If the background is solid bg-white, the picture behind it doesn't show at all, let alone blurred. Solid white covers everything. blur-md (without backdrop-) is something else: that class blurs the element itself, text included.
⚠️ Effects you can't see, or that land on the wrong part
- Solid
bg-whitein a glass effect.backdrop-bluris useless if the background isn't see-through. Usebg-white/30or similar. opacity-50for a see-through background. The text fades too and gets hard to read. Usebg-white/50when only the background should be see-through.- Shadows on a dark background. A black shadow on a black page is almost invisible. In dark mode, give the card a background colour lighter than the page, or a thin border, so the card still looks separate.
- The wrong sizes in the exercise. The exercise checker looks for
24pxof padding (p-6) and12pxcorners (rounded-xl).p-4(16px) orrounded-lg(8px) won't pass.
TL;DR: shadow-sm to shadow-2xl give a shadow under a box, from faint to floating high, and shadow-none removes it. opacity-50 makes the whole element half see-through, text included. bg-white/30 makes only the background see-through: white at 30% strength. The glass effect = backdrop-blur-md (blurs whatever is behind the element) + a see-through background like bg-white/30 + something colourful behind it. With a solid bg-white, nothing behind it shows, so there's nothing to blur.
⚡ A shadow lifts it up
Write:
<div class="bg-white rounded-xl p-6 shadow-lg">
Card
</div>
Meaning: A shadow-* class gives a shadow under a box, so the box looks lifted off the page. shadow-sm sits flat on the page, shadow-lg is clearly lifted, and shadow-2xl floats high. shadow-none removes the shadow.
⚡ Which part goes see-through
Guess first: opacity-50 makes an element half see-through. On a card, does the text fade too?
Yes. opacity makes the whole element see-through. For the background only, use bg-white/50.
Meaning: A slash on a background colour sets its strength (how solid the colour is): bg-white/30 means white at 30%, and the text stays clear.
⚡ The glass effect
Write:
<div id="glass" class="relative backdrop-blur-md bg-white/30 rounded-xl p-6 shadow-xl">
Glass Effect
</div>
Guess first: backdrop-blur-md blurs whatever is behind the card. Replace bg-white/30 with bg-white. Is the glass still frosted?
No, you see nothing behind it. Solid white covers everything, so there's nothing to blur.
Meaning: backdrop-blur-md blurs whatever is behind the element. This effect needs a see-through background and something colourful behind it.
In the exercise, the checker looks for 24px of padding (p-6) and 12px corners (rounded-xl).