Hex to Tailwind CSS Color Converter

Your color #3B82F6
blue-500 #2B7FFF
#

Paste a brand hex, or use the picker to dial one in

Try a brand color

Use it as any utility

Need the exact hex instead? Arbitrary value:

bg-[#3b82f6]

Closest Tailwind class

bg-blue-500

Near-identical·ΔEOK 0.019

Nearest 5 shades, ranked by perceptual distance

The full blue scale — matched shade outlined

50100200300400500600700800900950

How to Use This Tool

  1. 1.Paste your hex code into the field (or click the color picker) — for example a brand color like #1DA1F2.
  2. 2.Read the closest Tailwind class in the blue panel, with its quality label and ΔEOK distance — anything under 0.02 is near-identical.
  3. 3.Compare the ranked top 5 if the first match isn't quite right — a neighboring shade or family may suit your design better.
  4. 4.Copy the utility you need — bg-, text-, border-, ring-, and more are generated for you.
  5. 5.If no shade is close enough, grab the arbitrary class like bg-[#1da1f2] to use the exact color.

Rate this tool

Hex to Tailwind: Snapping Any Color to the Closest Utility Class

A hex to Tailwind CSS color converter answers one narrow question: which of Tailwind's 242 preset shades sits closest to the #1DA1F2 your designer just handed you? Tailwind doesn't let you type a raw hex into a normal utility class — you write bg-blue-500, not bg-#2b7fff. So when a brand color lands on your desk, you either find the nearest class in the palette or reach for an escape hatch. This tool does the finding, and the math below explains why "nearest" is trickier than comparing two hex strings.

Hex to Tailwind color converter showing a brand hex swatch matched to the nearest Tailwind shade with its bg-blue-500 class name

What "Closest Tailwind Color" Actually Means

Tailwind ships 22 color families, each with 11 shades from 50 to 950 — 242 fixed points scattered through a space of 16,777,216 possible hex colors. The odds that your exact brand color is one of those 242 points are tiny. Twitter's old #1DA1F2, for instance, isn't any Tailwind shade; the nearest is sky-500 at #00A6F4— close, but a touch deeper and more saturated. "Closest" means the shade your eye would call the most similar, not an identical code.

That word "eye" is the catch. Two colors that look equally far apart to a human can have wildly different distances if you just subtract their red, green, and blue numbers. Pure RGB distance treats a jump in green as mattering exactly as much as the same jump in blue — but human vision is far more sensitive to green. A naive nearest-match in RGB regularly picks a shade that's numerically close yet obviously wrong to look at.

How the Tool Measures the Distance

To match the way people actually see color, this converter works in the OKLab color space rather than raw RGB. OKLab is a perceptual model — equal numeric distances in it correspond to roughly equal visible differences. The pipeline for every comparison is: take the hex, convert each channel to linear light, run it through the OKLab matrices, then measure the straight-line distance between your color and all 242 shades. The smallest distance wins.

Here's a worked example. Your input is #3B82F6 (the old Tailwind v3 blue-500). Converted to OKLab it's L 0.623, a −0.033, b −0.185. The current blue-500 (#2B7FFF) sits at L 0.619, a −0.039, b −0.203. The straight-line distance between them works out to 0.019 — just inside the threshold where most people see them as the same blue. The tool labels that "Near-identical" and reports the figure as ΔEOK, the OKLab delta. As a rule of thumb, under 0.02 is near-indistinguishable, 0.02–0.045 is very close, and anything past 0.10 is an approximation you should eyeball before trusting. If you want to see the underlying channel values, our hex to RGB converter breaks any code into its three components.

Tailwind v4 Moved Every Hex Value

Upgrade a project from Tailwind v3 to v4 and your colors shift — quietly. Version 4 redefined the entire default palette in OKLCH to squeeze more vividness out of modern wide-gamut screens. The class names stayed the same, but the rendered hex codes changed. blue-500 went from #3B82F6 to #2B7FFF. red-500 moved from #EF4444 to #FB2C36. green-500 jumped from #22C55E to #00C950.

Classv3 hex (sRGB)v4 hex (OKLCH)
blue-500#3B82F6#2B7FFF
red-500#EF4444#FB2C36
green-500#22C55E#00C950
amber-500#F59E0B#FE9A00
slate-700#334155#314158

This converter uses the v4 values, so its matches reflect what you actually ship today. If your design system is still pinned to v3 and a perfect match matters, copy the exact hex into an arbitrary class instead of trusting the class name to mean what it did two years ago. To go the other direction and read a shade as standard channels, the RGB to hex converter is handy.

Reading the 50–950 Shade Scale

The number after a family name is a lightness step, not a saturation or hue control. 50 is the palest tint, 950 is nearly black, and the steps in between are spaced so each looks like a similar visual jump to the last. That even spacing is deliberate: it's why gray-100 to gray-200 feels like the same size change as gray-800 to gray-900, even though the raw RGB gaps differ.

  • 50–200: backgrounds, subtle fills, hover states on light UIs
  • 300–400: borders, dividers, disabled text, placeholder copy
  • 500–600: primary buttons, links, and brand accents — the workhorse range
  • 700–950: body text on light backgrounds, dark-mode surfaces, deep shadows

When the tool returns, say, indigo-600, it's telling you both the hue family and where on that lightness ramp your color falls. If the match is close on hue but you want it lighter or darker, slide one shade up or down the scale rather than switching families — the family row under the result lets you do exactly that.

Arbitrary Values vs. Extending the Theme

When no shade is close enough, Tailwind gives you two ways to use the real hex, and they serve different purposes.

ApproachSyntaxBest for
Arbitrary valuebg-[#1da1f2]One-off colors, prototypes, a single button
Theme token (v4)@theme { --color-brand: #1da1f2; }Reusable brand colors used across the app
Nearest presetbg-sky-500When "close enough" keeps your palette consistent

The arbitrary form is fast but scatters raw hex codes through your markup, so changing the brand color later means a find-and-replace across files. A theme token defines the color once — write bg-brandeverywhere, change it in a single line. Reach for arbitrary values while you're sketching, and promote a color to a token the moment you use it more than twice.

Mistakes When Mapping Brand Colors

Matching in RGB instead of a perceptual space. Sort the palette by plain RGB distance and you'll sometimes get a shade that's numerically nearest but a different hue to the eye — picking cyan-500 when a human would clearly say sky-500. Always match perceptually, which is why this tool uses OKLab.

Trusting a v3 hex inside a v4 project. If your brand guide says "we use Tailwind blue-500" and lists #3B82F6, that note is now wrong by about a 0.03 OKLab step. The class still exists; its color moved. Re-check brand-critical colors after upgrading.

Forcing a match that isn't there. A logo color with an ΔEOK of 0.12 to its nearest shade is not a match — it's the least-bad option. Shipping it as bg-purple-500 can make a careful brand look off. Use the arbitrary value when the distance number is large.

Ignoring lowercase rules in arbitrary classes. Tailwind is case-insensitive about the hex inside brackets, but mixing bg-[#1DA1F2] and bg-[#1da1f2] in the same file generates two separate classes in some tooling and can defeat deduplication. Pick one case — lowercase is the convention.

When NOT to Snap to the Nearest Shade

Don't round to a preset for colors that carry legal or brand weight. A bank's exact corporate blue, a sports team's licensed colors, or a Pantone-matched print color should be reproduced precisely with an arbitrary value or a theme token, not approximated to blue-600 because it's "basically the same." If you're coming from print, run the value through our CMYK to RGB converter first to get a screen-accurate hex before matching.

Also skip the nearest-shade approach for accessibility-tuned colors. If you've hand-picked a text color to hit a specific WCAG contrast ratio against a background, snapping it to the closest Tailwind shade can quietly drop you below the 4.5:1 threshold for normal text. Verify the matched color, not the original, with our WCAG contrast checker. For the precise OKLCH definitions behind every default shade, the official Tailwind color documentation lists them all, and the W3C CSS Color 4 spec defines the OKLab math the matcher relies on.

Marko Sinko
Marko SinkoTechnical Tools Editor

Croatian developer with a Computer Science degree from University of Zagreb and expertise in advanced algorithms. Marko builds and verifies the technical tools, number system converters, and scientific calculators across UnitCalcTools, ensuring mathematical precision and developer-friendly interfaces.

Last updated: June 22, 2026LinkedIn

Frequently Asked Questions

In Tailwind v4, the closest class to #3B82F6 is blue-500, which is now #2B7FFF. The two are perceptually near-identical but not the same — #3B82F6 was the exact blue-500 hex in Tailwind v3, and v4 shifted it when the palette moved to the OKLCH color model. If you need the old value precisely, write the arbitrary class bg-[#3B82F6] instead.
Tailwind ships 22 color families — slate, gray, zinc, neutral, stone, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, and rose — each with 11 shades from 50 to 950. That is 242 named colors, plus black, white, transparent, and currentColor. This tool searches all 242 shades to find your nearest match.
The number is the shade's lightness step, running 50, 100, 200, up to 950. Lower numbers are lighter (50 is near-white) and higher numbers are darker (950 is near-black), with 500 sitting roughly in the middle as the family's most saturated reference tone. The steps are spaced perceptually, so 100 to 200 looks like a similar jump to 800 to 900.
Use Tailwind's arbitrary value syntax: write the hex inside square brackets after the utility prefix, like bg-[#1DA1F2] or text-[#1DA1F2]. This generates the exact color with no rounding to the nearest palette shade. For a color you reuse often, it's cleaner to add it to your theme with a CSS @theme block so you can write bg-brand instead.
Tailwind's 242 shades are specific points in a huge space of 16.7 million possible hex colors, so an exact hit is rare unless you copied the value from Tailwind itself. The converter measures perceptual distance in the OKLab color space and returns the nearest shade, with a quality label like 'Very close' or 'Approximate.' A distance under about 0.02 is close enough that most people can't tell them apart.
No. In Tailwind v3, blue-500 was #3B82F6, defined in sRGB hex. In v4 the entire palette was redefined in OKLCH for more vivid colors on modern displays, making blue-500 render as #2B7FFF. Most shades shifted by a small but visible amount, so a design pinned to v3 hex values won't line up perfectly after upgrading.
bg-[#1DA1F2] is a one-off arbitrary value compiled only where you use it — fine for a single button, but it scatters raw hex codes through your markup. Extending the theme (adding the color in an @theme block in v4 or theme.extend.colors in v3) creates a reusable token like bg-brand that you change in one place. Use arbitrary values for prototypes and theme tokens for production brand colors.

Related Tools