Free online tool

HEX ↔ RGB Color Converter

Convert HEX color codes to RGB and see a live preview swatch of your color.

RGB: rgb(59, 130, 246)
CSS: #3b82f6

HEX vs RGB — same color, different notation

HEX and RGB are two ways of expressing the same thing: how much red, green and blue make up a color. RGB uses three decimal numbers from 0 to 255, while HEX packs those three values into a six-digit hexadecimal string. Designers tend to prefer HEX because it's shorter and easier to paste; developers often need RGB because it composes naturally with CSS features like rgba() for opacity.

How to use the tool

Type or paste a HEX code — with or without the leading #, and with either three-digit shorthand (#f0a) or the full six-digit form. The tool immediately shows you the equivalent RGB values and a live color swatch so you can confirm you've got the right one. Everything runs in your browser; nothing about your color choices ever leaves the page.

+Does it support 8-digit HEX with alpha?

Not yet. This version handles opaque colors only. If you need alpha, tell us on the contact page.

+Why does #FFF look the same as #FFFFFF?

Three-digit HEX is shorthand — each digit is doubled internally. #F0A means #FF00AA.

Two ways of writing the same three numbers

HEX and RGB describe the identical sRGB color space, just formatted differently — HEX packs three bytes into a six-digit base-16 string, RGB spells the same bytes out as three base-10 numbers from 0 to 255. Converting between them is pure arithmetic, no color science involved, but the details around alpha and shorthand notation trip people up constantly.

Designers tend to think in hex because that's what design tools display by default, while code that manipulates colors programmatically — blending, darkening, or interpolating between two swatches — is usually easier to reason about in RGB's numeric triplet form, which is why a fast converter between the two ends up on so many developers' bookmark bars.

Reading the hex pairs correctly

A hex code like 2f8f5c splits into three two-digit hex pairs — 2f, 8f, 5c — each converted from base 16 to base 10 to get red, green, and blue values, here 47, 143, 92. The shorthand three-digit form, like 2f8, expands by duplicating each digit rather than padding with zero, so 2f8 becomes 22ff88, not 20f080 — an easy mistake if you write the conversion by hand.

Alpha channels complicate the picture

An eight-digit hex code appends a fourth byte for alpha, as in 2f8f5cff, while RGB expresses the same thing as a separate rgba() function with a 0-to-1 opacity value rather than a 0-to-255 byte. Mixing these up — treating the alpha byte as part of the color, or forgetting it's on a different numeric scale — produces colors that render correctly but composite wrong against a background.

Why this matters for accessibility

Converting to RGB is usually the first step before computing relative luminance and contrast ratio for WCAG compliance checks, since the standard's math operates on linearized 0-to-1 RGB channels, not on hex strings. If your design system stores colors as hex, converting here before running a contrast check saves you from doing the base conversion by hand every time. WCAG AA requires a 4.5:1 contrast ratio for normal body text and 3:1 for large text, and that ratio is only meaningful once both foreground and background are expressed as the same RGB-derived luminance value, so skipping the conversion step and eyeballing two hex codes side by side is not a reliable substitute.

HSL as a third representation worth knowing

Neither HEX nor RGB directly expresses how a color would look lighter, darker, or more saturated, which is where HSL — hue, saturation, lightness — earns its place; nudging the lightness value up or down is a far more intuitive way to build a color palette than guessing which RGB channel to adjust. Converters that support all three formats side by side make it easy to pick a hue in HSL and then hand a designer the resulting hex value for a spec document.

People also search for

  • hex to rgb converter
  • rgb to hex online
  • color code converter
  • hex color to rgba
  • css color format converter
  • hex shorthand expansion
  • contrast ratio color check
  • hsl to hex conversion