Skip to content
Tutorials Center
My learning

Topics

Lesson 16 of 37 ยท Typography, Color and Effects

Colors and Opacity

Use Tailwind v4's OKLCH color palette on text, backgrounds, borders and SVG; apply the slash opacity modifier; understand currentColor and contrast.

Tailwind ships with a carefully tuned color palette, and the same color names work with every property that takes a color. Once you know the pattern (-{color}-{shade}) and the opacity modifier (/50), you can color anything. This lesson covers the palette, where colors apply, transparency, currentColor for icons, and how to pick accessible combinations.

The palette

The default palette has 22 colors, each in 11 shades from 50 (lightest) to 950 (darkest):

  • Grays: slate, gray, zinc, neutral, stone (with slightly different undertones: slate is cool and bluish, stone is warm).
  • Colors: red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose.

Special values: black, white, transparent, current (the current text color) and inherit.

In v4 the colors are defined in OKLCH, a perceptual color space with a wider gamut. On modern displays they look more vivid than v3's sRGB colors, and shades of different hues have similar perceived lightness, so -500 of any hue has similar visual weight. You do not need to know OKLCH to use them: Tailwind outputs fallbacks for older browsers.

A rule of thumb for shades:

Shade Typical use
50-100 Subtle backgrounds, tints, alert boxes
200-300 Borders, dividers, disabled states
400-500 Icons, accents, secondary text
600-700 Primary buttons, links, strong text
800-950 Headings, dark backgrounds

Where you can apply color

The color part is the same everywhere; the prefix chooses the property:

Prefix Property
text- text color
bg- background
border-, divide- borders and divider lines
ring-, outline- rings and outlines
fill-, stroke- SVG fill and stroke
shadow-, inset-shadow- shadow color
decoration- underline color
accent- checkbox, radio and range controls
caret- text input cursor
from-, via-, to- gradient stops
The palette in action

Opacity: the slash modifier

Add / and a number from 0 to 100 to any color utility to make that color transparent:

HTML
<div class="bg-black/60 text-white">60% black, text fully opaque</div>
<div class="border border-indigo-500/30 ring-indigo-500/20"></div>
<div class="bg-indigo-500/[.37] text-slate-900/(--text-alpha)"></div>

In v4 any whole number works (/37); for fractions use brackets (/[.375]), or take the value from a variable (/(--alpha)). v4 implements this with color-mix() in the oklab color space, so it works even for colors defined by variables, which the old approach could not.

The separate opacity-{n} utility fades the whole element, including its text, children and borders. Choose carefully:

/50 modifier vs opacity-50

Use opacity-* for fading whole components in and out (hover, disabled states: disabled:opacity-50), and the slash modifier for tinted backgrounds, overlays and soft borders.

currentColor: one color, many parts

currentColor means "whatever the color property is right now". Tailwind exposes it as current: border-current, fill-current, bg-current, ring-current. It makes an icon follow its text:

HTML
<a class="text-indigo-600 hover:text-indigo-800">
  <svg class="size-4 fill-current">...</svg> Link text
</a>

When the text color changes on hover, the icon changes with it, with no extra classes. In v4 a plain border already uses currentColor, which is why you add a color explicitly.

Icons that follow text color

Choosing colors that work

  • Start with one brand color and one gray. For example indigo plus slate. Use the gray for text and surfaces, the brand color for actions.
  • Check contrast. Text must reach a 4.5:1 contrast ratio (3:1 for large text). On white, slate-600 and darker pass for body text; slate-400 usually does not. Pairs such as bg-indigo-600 text-white pass, while bg-yellow-400 text-white fails.
  • Do not rely on color alone to convey state (error, success). Pair it with an icon or text.
  • Use 50-100 backgrounds with 700-800 text for friendly alert boxes: bg-amber-50 text-amber-800 ring-1 ring-amber-200.

Your own colors go into the theme. In chapter 6 you will add --color-brand-500 and get bg-brand-500 and friends for free.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does bg-black/60 do?

    The slash modifier changes the alpha of that one color, leaving text and children untouched.
  2. 2. Which class makes an SVG icon take the color of the surrounding text?

    fill-current sets fill: currentColor, which follows the text color, including on hover.
  3. 3. Which utility fades an element together with its text and children?

    opacity-* applies to the entire element. The slash modifier only changes one color.
  4. 4. Why add a color to border in v4?

    v4 changed the default border color from gray to currentColor, so be explicit.

Summary

  • 22 palette colors in shades 50-950 (OKLCH in v4), plus black, white, transparent and current.
  • The color part is shared across text-, bg-, border-, ring-, fill-, accent- and more.
  • /50 makes only that color transparent; opacity-50 fades the whole element.
  • currentColor utilities keep icons and borders in sync with text; always check contrast.

Next: Shadows, Filters and Backdrop