Skip to content
Hex Calculator

Hex to Tailwind Converter

Convert a hex color like #2563EB into Tailwind CSS arbitrary value syntax such as bg-[#2563EB] — exact, not the nearest named palette guess.

Tailwind class
bg-[#2563EB]
Swapnil Sanghvi

Built by

Swapnil Sanghvi

Full-Stack Web Developer & WordPress Developer

Swapnil Sanghvi is a full-stack web and WordPress developer, UI designer, and full-time freelancer who builds and maintains Hex Calculator.

Hex to Tailwind Converter tool preview card from Hex Calculator
Share preview: this is the card that appears when you share the Hex to Tailwind Converter page on social media.

Further reading: CSS Colors — W3Schools

How Hex to Tailwind Conversion Works

Tailwind CSS v3.1 and later support arbitrary value syntax: any utility prefix followed by a value in square brackets, like bg-[#2563EB]. This tool wraps your hex code in that syntax so the class works for the exact color you entered, rather than approximating it with one of Tailwind's named palette swatches.

Hex to Tailwind Example, Step by Step

#2563EB = bg-[#2563EB]

#2563EB (hex) = bg-[#2563EB] (Tailwind)

Hex input: #2563EB

Wrap in arbitrary value syntax: [#2563EB]

Prefix with a utility: bg-[#2563EB]
StepDescriptionResult
Take the hex code#2563EB#2563EB
Wrap in bracketsarbitrary value syntax[#2563EB]
Add a utility prefixbg-, text-, border-, etc.bg-[#2563EB]

Swap the bg- prefix for text-, border-, ring-, fill-, or stroke- to apply the same exact color to a different CSS property.

Where Hex to Tailwind Actually Comes Up

Implementing an Exact Brand Color

Brand guidelines specify precise hex values — converting to arbitrary value syntax guarantees the Tailwind class renders that exact color, not the closest named swatch.

brand #2563EB -> bg-[#2563EB]

Converting a Design File's Picked Color

Pulling a hex value straight from a Figma or Sketch color picker and converting it here gives you a ready-to-paste class for implementing that design pixel-for-pixel.

design tool hex -> Tailwind class

Adding a One-Off Color Without Editing Config

When a single component needs a color that isn't in the project's Tailwind config, arbitrary value syntax lets you use it directly without a config change.

one-off hex -> inline arbitrary class

Common Mistakes With Hex to Tailwind

  • Assuming a hex color always maps to a named Tailwind swatch like blue-600 — most hex values fall between named steps.
  • Forgetting the # inside the brackets, which produces an invalid class like bg-[2563EB].
  • Adding spaces inside the brackets, which Tailwind's JIT compiler won't recognize as a single arbitrary value.

Why Use This Calculator Instead of Writing It by Hand

  • Expands 3-digit shorthand hex automatically before wrapping it
  • Runs entirely in your browser — nothing you type gets sent anywhere
  • Produces exact-match syntax instead of an approximate named swatch
  • Ready to paste directly into a className

Limitations

  • Finds the closest match in a fixed swatch list using weighted color distance — this is an approximation, not an official conversion, since the underlying brand doesn't publish a public hex specification.

Frequently Asked Questions

How does hex convert to a Tailwind class?

Tailwind CSS v3.1+ supports arbitrary value syntax — wrapping any valid CSS value in square brackets after a utility prefix. A hex color becomes bg-[#2563EB], text-[#2563EB], border-[#2563EB], and so on.

Why not just snap to the nearest Tailwind color like blue-600?

This tool deliberately does not guess the nearest named Tailwind swatch. Named palette colors only approximately match a given hex value, and the palette itself changes between Tailwind versions — arbitrary value syntax is exact for any hex color, every version.

Does arbitrary value syntax work for any utility, not just bg-?

Yes — the [#RRGGBB] pattern works after any color-accepting prefix, including text-, border-, ring-, fill-, and stroke-.

Do I need to include the # inside the brackets?

Yes, Tailwind expects the full CSS color value inside the brackets, including the # for hex colors, e.g. bg-[#2563EB].

Does this work with 3-digit shorthand hex?

Yes — shorthand hex like #25E is expanded to its 6-digit form before being placed in the arbitrary value class.

How do I implement a brand color exactly in a Tailwind project?

Convert the brand's hex value here to get the exact arbitrary value class — this guarantees pixel-perfect brand color matching instead of settling for the closest named Tailwind swatch.

Can I use this for a color that's only in a design tool, not in code yet?

Yes — grab the hex value from your design file's color picker and convert it here to get a ready-to-use Tailwind class for implementing that exact design.