hexcolors

Learn / Blog / Developers

How to use custom hex colors in Tailwind CSS

One-off colors, theme colors and a full 50 to 950 scale built from a single hex code.

November 20, 20261 min readBy the hexcolors team

Key takeaways

  • Use square brackets like bg-[#1e90ff] for quick one-off colors.
  • Define theme colors once so you can change them in one place.
  • Build a 50 to 950 scale by keeping hue and changing lightness.

Tailwind works with any hex code. The question is how much structure you want around it. Here are the three levels, from a quick test to a full design system.

One-off colors

Square brackets let you use any value directly, for example bg-[#1e90ff] or text-[#1e90ff]. This is perfect for a quick experiment, but if the same hex appears in ten places, changing it later becomes a search-and-replace job.

Theme colors in Tailwind v4

Tailwind v4 reads theme values from CSS. Define a variable inside @theme and Tailwind generates the matching utilities:

@import "tailwindcss";

@theme {
  --color-brand: #1e90ff;
}

You can now write bg-brand, text-brand and border-brand. On Tailwind v3, the same idea lives in theme.extend.colors inside tailwind.config.js.

Build a full scale

Design systems usually offer a scale from 50 (lightest) to 950 (darkest), so you can pick a pale background, a mid-tone button and a dark text color from the same family. Keep the hue and saturation of your base color and change only the lightness. Using #1E90FF as the 500 step, a scale looks like this:

@theme {
  --color-brand-50: #f0f7ff;
  --color-brand-100: #dbedff;
  --color-brand-200: #b8dcff;
  --color-brand-300: #85c3ff;
  --color-brand-400: #52a9ff;
  --color-brand-500: #1e90ff;
  --color-brand-600: #0079f0;
  --color-brand-700: #0062c2;
  --color-brand-800: #004b94;
  --color-brand-900: #003466;
  --color-brand-950: #001f3d;
}

Treat generated steps as a starting point and adjust by eye. Every hex code on this site has a page with shades, tints and tones you can borrow from.

Check contrast before you ship

Pale steps like 100 and 200 are for backgrounds, and dark steps like 800 and 900 are for text. Mid-tones such as 400 to 600 often fail contrast with white text, so test your pairs in the contrast checker.

The hexcolors teamWe build free color tools and write practical guides. Follow us on X, Instagram and LinkedIn.