Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 37 ยท Animation and Advanced Features

Filters, Gradients, Masks and Shadows

Create depth and polish with Tailwind CSS v4: linear, radial and conic gradients, blur and backdrop-blur, drop shadows, text shadows, masks and gradient text.

Flat colors and boxes get you far, but modern interfaces also use gradients, frosted glass, soft shadows and fading edges. Tailwind covers all of these with utilities, and version 4 added several: radial and conic gradients, angle gradients, text shadows and mask utilities. This lesson puts them together with small, reusable recipes.

Gradients

A gradient has a direction, a start color (from-*), an optional middle (via-*) and an end (to-*).

HTML
<div class="bg-linear-to-r from-indigo-500 via-purple-500 to-pink-500"></div>
  • Direction keywords: bg-linear-to-t, -to-tr, -to-r, -to-br, -to-b, -to-bl, -to-l, -to-tl.
  • Exact angles: bg-linear-45, bg-linear-135, or negative -bg-linear-45.
  • Radial: bg-radial (centered circle) or bg-radial-[at_25%_25%] for a custom center.
  • Conic: bg-conic or bg-conic-180, good for color wheels and gauges.
  • Positions: from-10%, via-30%, to-90%.
  • Interpolation: add /oklch, /srgb or /hsl to choose the color space, as in bg-linear-to-r/oklch. OKLCH blends avoid the muddy gray midpoint that some sRGB gradients show.
Linear, radial and conic gradients

Gradient text

Clip the gradient to the letters with bg-clip-text and make the text color transparent:

HTML
<h1 class="bg-linear-to-r from-sky-500 to-violet-600 bg-clip-text text-5xl font-extrabold text-transparent">
  Gradient headline
</h1>

Shadows

Tailwind has separate shadow families, which can be stacked:

Family Utilities Applies to
Box shadow shadow-sm, shadow-md, shadow-xl, shadow-indigo-500/40 the element's box
Inset shadow inset-shadow-sm, inset-shadow-indigo-500 inside the box
Ring ring, ring-2, ring-indigo-500, inset-ring a crisp outline that follows the box
Drop shadow drop-shadow-md, drop-shadow-lg the shape of the content, transparent PNG and SVG included
Text shadow text-shadow-sm, text-shadow-lg, text-shadow-black/30 text

Use drop-shadow when the shape is not a rectangle (a logo with a transparent background). A box shadow would draw a rectangle around it.

Stacked shadows and a colored glow

Filters and backdrop filters

Filters change the element itself: blur-sm, blur-xl, brightness-75, contrast-125, grayscale, saturate-150, sepia, hue-rotate-90, invert. Backdrop filters change what is behind the element: backdrop-blur-md, backdrop-brightness-90, backdrop-saturate-150. Combine a translucent background with backdrop-blur for the "frosted glass" look.

Frosted glass over a colorful background

Filters can be expensive on large areas and on low-power devices. Use them on small surfaces such as navbars and cards, not on a full-screen layer that animates.

Hover filters make simple image effects: grayscale transition hover:grayscale-0 shows a black-and-white photo that colors on hover.

Masks

Masks hide parts of an element using a gradient or an image, which is how you fade the edge of a scroll area. Tailwind v4.1 added utilities for it: mask-t-from-50% fades the top edge starting at 50%, and mask-b-to-90%, mask-r-from-70% do the same for other edges. mask-radial-* and mask-linear-* produce general masks, and mask-[url(...)] uses an image.

Faded scroll edges with mask utilities

Other handy visual utilities

  • mix-blend-multiply, mix-blend-screen, bg-blend-overlay blend an element with what is behind it; combined with an image they make duotone effects.
  • aspect-video, aspect-square, aspect-[4/3] fix an element's ratio so images do not cause layout shifts.
  • outline-*, outline-offset-* and ring-offset-* build focus indicators.
  • field-sizing-content makes a <textarea> grow with its text, with no JavaScript.
  • scheme-dark tells the browser to render built-in controls in dark style.
A textarea that grows

field-sizing is newer than most of Tailwind's features, so treat it as progressive enhancement: the textarea still works if the browser ignores it.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which classes make a left-to-right gradient from indigo to pink?

    A direction utility such as bg-linear-to-r plus from-* and to-* colors defines the gradient.
  2. 2. How do you make gradient text?

    Clip the background to the text and make the glyph color transparent so the background shows through.
  3. 3. When is drop-shadow-* better than shadow-*?

    drop-shadow is a filter that follows the visible shape; box-shadow always follows the rectangle.
  4. 4. What produces a frosted glass effect?

    backdrop-blur blurs what is behind the element, so the translucent background lets it show.

Summary

  • Gradients use bg-linear-*, bg-radial, bg-conic with from-*, via-*, to-*; add /oklch to choose interpolation; clip to text for gradient headlines.
  • Shadows come in box, inset, ring, drop and text varieties; use drop-shadow for non-rectangular shapes.
  • Filters change the element, backdrop filters change what is behind it; use them sparingly on large animated areas.
  • Mask utilities fade edges, aspect-* prevents layout shifts, and field-sizing-content auto-grows textareas.

Next: Build Tools and Upgrading