Color Converter

Paste a HEX, RGB or HSL color and get every format back, plus its contrast ratio against black and white.

How to use

  1. Paste a color as a hex code, rgb()/rgba(), or hsl()/hsla(), or pick one with the swatch next to the box. The format is auto-detected.
  2. The preview shows the color with black and with white sample text on it; each carries its contrast ratio, labelled AA, AAA or a fail, and the better of the two is marked best.
  3. Read the HEX, RGB and HSL values under the preview, all computed from the same parsed color, and the Darker and lighter strip: the same hue in 10-point lightness steps.
  4. Click any value or any swatch in the strip to copy it; Load sample inserts a worked example.

One color, every format design tools expect

Design tools, CSS, and image editors each tend to default to a different color notation: a design file exports hex, a CSS-in-JS library wants an rgba() string, a design system's tokens are defined in HSL because it is easier for a human to reason about ("a bit darker" is just a lower lightness number). Converting by hand between them means re-deriving the math each time; this tool parses whichever one you paste and shows all three at once, plus whether it is safe to put text on top of.

Example

The color #3366ff is, in every format:

#3366ff
rgb(51, 102, 255)
hsl(225, 100%, 60%)

and has a contrast ratio of 4.49 against black text and 4.68 against white text.

Options explained

Edge cases and common errors

Do the same thing in code

// CSS itself understands all of these natively: no conversion needed at all
// if the value only needs to reach a browser:
.button { background: #3366ff; }
.button { background: rgb(51, 102, 255); }
.button { background: hsl(225, 100%, 60%); }

Conversion only matters once something other than CSS needs the value in a specific format: a design token file, an image-processing library, or a contrast check like the one this page runs.

Color Converter FAQ

What do the AA and AAA labels mean?

They are the WCAG 2 contrast thresholds for normal-size text against a background: 4.5:1 or higher passes AA, 7:1 or higher passes AAA, and anything below 4.5:1 fails both. Large text (about 18pt or 14pt bold and up) has lower thresholds, 3:1 and 4.5:1, which this page does not compute separately; a background that fails for normal text may still be fine for a large heading.

Why does converting to HSL and back change the numbers slightly?

HSL rounds hue to a whole degree and saturation/lightness to a whole percent, so a small amount of rounding drift is normal: rgb(30, 144, 255) converted to HSL and back becomes rgb(31, 143, 255) (each channel off by at most 1). This is a property of HSL itself, not a bug in the conversion.

Does the # matter in a hex code?

No. It is optional. Both "#3366ff" and "3366ff" parse the same way, so you can paste a hex value straight out of a design tool’s color picker without editing it first.

What does the “best” label on the preview mean?

It marks whichever of pure black or pure white text has the higher contrast ratio against the color you entered, a quick answer to "should this button’s label be black or white text" without comparing two numbers yourself.

Runs entirely in your browser: this page is a static file with no server behind it, so nothing you paste can be uploaded. Last reviewed by Parthesh Gupta. Implements CSS Color Module Level 4.