Menu

Hex to Tailwind: how to map any brand color to the nearest palette shade
📰

Hex to Tailwind: how to map any brand color to the nearest palette shade

DEV Community: tailwindcss·Sanjaya Sahu·7 days ago
#y8KUYPDe
#devtotailwindcss#devto#dev#shade#tailwind
Reading 0:00
15s threshold

Designers hand you a brand hex like #3B82F6-ish, and your Tailwind config has 11 shades per color. Which one is "closest"? Eyeballing it leads to inconsistent UIs.

Why simple RGB distance misleads

Euclidean distance in RGB treats all channels equally, but human vision doesn't. Two colors can be numerically close and look different (especially in greens). A better approach is to compare in a perceptual space such as CIELAB (deltaE).

A quick recipe

Convert your hex to sRGB, then to linear RGB, then to Lab.

Do the same for every Tailwind shade (50-950 across all families).

Pick the smallest deltaE.

If deltaE is under ~2, it's visually the same; between 2 and 10 it's a close match; above that, consider extending your config with a custom shade.

Don't forget contrast

Nearest shade is only half the story. Check the text/background pair against WCAG 4.5:1 for body text.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.