Skip to content
Developer

Color Converter

A hex colour is three bytes written in base 16 — #4F46E5 is red 79, green 70, blue 229. HSL describes the same colour as a hue angle, a saturation percentage and a lightness percentage, which is easier to reason about by hand but converts to exactly the same sRGB values.

By Updated Runs in your browser — nothing is uploaded

Colour · convert and check

Hex, rgb() or hsl(). A leading hash is optional and three-digit shorthand works.

Use the colour the text will actually sit on, after any transparency has composited.

Hex

#4F46E5

rgb(79 70 229)

Sample text on this colour
HEX
#4F46E5
RGB
rgb(79 70 229)
HSL
hsl(243 75.4% 58.6%)
HSV / HSB
243°, 69.4%, 89.8%
CMYK (approximate)
66%, 69%, 0%, 10%
Relative luminance
0.1170

Contrast against the chosen background

6.29:1

Passes AA for normal text

Against white
6.29:1 — Passes AA for normal text
Against black
3.34:1 — Large text and UI components only
AA threshold, normal text
4.5:1
AA threshold, large text
3:1
AAA threshold, normal text
7:1

Large text means at least 18.66px bold or 24px regular. Contrast is computed from WCAG 2.2 relative luminance in sRGB; an alpha channel is ignored, so check the composited colour rather than the declared one when transparency is involved.

On this page
  1. Hex is just three bytes
  2. HSL is the same colour, described differently
  3. Contrast is about luminance, not about the numbers
  4. The failures that survive a design review
  5. CMYK, and why the figure here is only a guide
  6. Beyond sRGB
  7. What this converter does

Hex is just three bytes

#4F46E5 is not a colour name. It is three pairs of base-16 digits, one byte per channel, in the order red, green, blue.

  • 4F = 4×16 + 15 = 79 red
  • 46 = 4×16 + 6 = 70 green
  • E5 = 14×16 + 5 = 229 blue

So #4F46E5 is exactly rgb(79 70 229). The two notations carry identical information; hex is compact and RGB is readable, and neither can express anything the other cannot.

Three-digit hex is shorthand in which each digit is doubled: #F60 means #FF6600, not #F06000. That is why #FFF is white and why the shorthand can only reach 4,096 of the 16.7 million available colours — it is a convenience for round values, not a compression.

An eight-digit hex adds an alpha byte: #4F46E580 is the same colour at 50% opacity. This converter reads it and reports the opaque colour, because alpha has no meaning until it composites against something.

HSL is the same colour, described differently

RGB tells a screen what to do. HSL tells a person what the colour is.

  • Hue is an angle on the colour wheel, 0–360°. Red is 0, green 120, blue 240.
  • Saturation is 0% for grey through 100% for the pure hue.
  • Lightness is 0% for black, 50% for the pure hue, 100% for white.

The advantage is that it is manipulable by hand. A palette of related shades is the same hue and saturation at different lightness values. A complementary colour is the hue plus 180°. Neither operation has an obvious form in hex.

The catch is that lightness in HSL is not perceived brightness. hsl(60 100% 50%) is a blazing yellow and hsl(240 100% 50%) is a dark blue, yet both claim 50% lightness. That is the single biggest reason a palette built by rotating hue at fixed lightness looks uneven — and the reason the newer perceptual spaces exist.

HSV (also called HSB) uses the same hue but redefines the third axis: 100% value is the brightest form of the hue, and white requires saturation at zero as well. Design tools tend to expose HSV; CSS uses HSL. Mixing them up produces colours that are close but consistently wrong.

Contrast is about luminance, not about the numbers

Two colours can have similar hex values and wildly different visual weight, because human vision is not equally sensitive across the spectrum. WCAG's contrast formula is built on that fact.

First each channel is normalised to 0–1 and linearised, undoing the sRGB transfer curve:

C = c/12.92 if c ≤ 0.03928, otherwise ((c + 0.055) / 1.055)^2.4

Then the three linear channels are weighted into a single relative luminance:

L = 0.2126·R + 0.7152·G + 0.0722·B

Those coefficients are the whole story. Green carries 71.5% of perceived brightness, red 21.3%, blue 7.2%. Pure blue on black gives a contrast ratio of about 2.4:1 and fails for text. Pure yellow on black gives about 19.6:1 and passes everything. Both are fully saturated primaries at maximum channel values.

Finally the ratio:

Contrast = (L_lighter + 0.05) ÷ (L_darker + 0.05)

The 0.05 term models ambient light reflecting off the screen, which is why the scale tops out at 21:1 for black on white rather than running to infinity.

The thresholds worth memorising

RequirementRatioApplies to
WCAG 2.2 AA, normal text4.5:1Body copy below the large-text size
WCAG 2.2 AA, large text3:118.66px bold or 24px regular and above
WCAG 2.2 AA, non-text3:1UI component boundaries, meaningful graphics
WCAG 2.2 AAA, normal text7:1Enhanced conformance
WCAG 2.2 AAA, large text4.5:1Enhanced conformance

Large text is defined by rendered size, not by heading level. An <h3> set at 16px is normal text and needs 4.5:1.

The failures that survive a design review

Placeholder text. Almost every default placeholder colour fails. It is still text, and the criterion still applies.

Disabled controls. WCAG exempts inactive components from the contrast requirements, which is why so many disabled buttons are unreadable. Exempt is not the same as good; if a user has to read the label to know what they cannot do, it needs contrast.

Text over images. The ratio depends on which pixel the letter lands on. A photograph with a bright patch will fail somewhere even if the average passes. A scrim — a semi-transparent overlay between image and text — is the usual fix, and its effect must be measured on the composited result.

Brand colours on white. A large share of corporate palettes fail at body-text sizes. The standard workaround is a darker variant of the brand colour reserved for text, with the original kept for large display use and non-text elements.

Semi-transparent colours. rgba(0 0 0 / 0.5) over white is #808080, and that is the value to test. Testing the declared colour instead reports a ratio the user never actually sees.

Focus indicators. These are non-text UI and need 3:1 against the adjacent background — including in whichever state the component happens to be in when focused.

CMYK, and why the figure here is only a guide

The CMYK values this tool reports come from the standard naive conversion: subtract each channel from one, extract the common black, and scale what remains.

That conversion knows nothing about the press, the ink set, the paper stock or the colour profile — all of which move the result substantially. A colour that looks right on a coated sheet can look muddy on uncoated stock with the same numbers.

RGB is also a fundamentally larger space than CMYK for saturated colours. Vivid greens, oranges and blues that a screen shows happily are simply not printable, and the profile has to decide what to substitute. That decision is what an ICC profile encodes and what no formula can supply.

Use the figure here to sanity-check a colour, not to specify one for print. For real print work, convert in software with the profile for the actual press and stock.

Beyond sRGB

Everything above assumes sRGB, the colour space the web was built on and the one hex and rgb() can describe. CSS Color Level 4 goes further, and the additions are worth knowing about:

  • oklch() — a perceptual space where lightness means what it looks like. Rotating hue at fixed lightness produces colours of genuinely equal weight, which sRGB and HSL do not.
  • display-p3 — a wider gamut supported by most recent screens, reaching saturated reds and greens sRGB cannot express at all.
  • lab() and lch() — device-independent spaces derived from CIELAB, useful for colour matching across media.
  • color-mix() — mixing in a named space, so a blend can be specified in OKLCH and rendered correctly rather than being averaged channel by channel in sRGB.

The practical payoff shows up in gradients. A blue-to-yellow gradient in sRGB passes through a desaturated grey in the middle, because the channel-wise average of two opposing colours is grey. The same gradient in OKLCH stays saturated the whole way. If a gradient in your design looks dead in the middle, that is what happened.

Support is now broad, but a fallback in sRGB is still the safe pattern for anything critical.

What this converter does

It reads hex — with or without a leading hash, three, six or eight digits — as well as rgb() and hsl() in comma or space-separated form. It reports the same colour as HEX, RGB, HSL, HSV and approximate CMYK, gives the WCAG relative luminance, and computes contrast against white, against black, and against any background you enter.

It does not convert to or from OKLCH, Lab or display-p3, all of which need a working colour-management path to be meaningful rather than decorative. It ignores alpha, for the reason given above: an alpha value has no colour until it composites.

Everything runs in your browser. Nothing you paste is sent anywhere.

Common questions

Frequently asked questions

How do I convert a hex colour to RGB by hand?

Split the six digits into three pairs and read each pair as a base-16 number. In #4F46E5, 4F is 4×16 + 15 = 79, 46 is 4×16 + 6 = 70, and E5 is 14×16 + 5 = 229, giving rgb(79, 70, 229). A three-digit hex is shorthand in which each digit is doubled, so #F60 means #FF6600.

What is the difference between HSL and HSV?

Both use the same hue angle, but they differ in what the third component means. In HSL, 100% lightness is always white and 50% is the pure hue. In HSV, 100% value is the brightest version of the hue and white only appears when saturation is also zero. Design tools tend to expose HSV; CSS uses HSL.

What contrast ratio do I need to meet WCAG?

WCAG 2.2 Success Criterion 1.4.3 requires a ratio of at least 4.5:1 for normal text and 3:1 for large text, which means 18.66px bold or 24px and above. The enhanced criterion 1.4.6 raises these to 7:1 and 4.5:1. User interface components and meaningful graphics need at least 3:1 under 1.4.11.

How is the contrast ratio calculated?

From relative luminance, not from the hex values directly. Each channel is divided by 255, linearised with the sRGB transfer function, then combined as 0.2126×R + 0.7152×G + 0.0722×B. The ratio is (lighter + 0.05) ÷ (darker + 0.05), which ranges from 1:1 for identical colours to 21:1 for black on white.

Why does green look brighter than blue at the same value?

Because human vision is not equally sensitive across the spectrum. The luminance coefficients reflect that: green carries 71.5% of perceived brightness, red 21.3%, and blue only 7.2%. Pure blue on black fails contrast requirements badly, while pure yellow on black passes easily, despite both being fully saturated.

Is CMYK conversion accurate for print?

No, and no simple formula can be. The naive conversion shown here ignores the printing process, the ink set, the paper and the colour profile, all of which change the result substantially. It is useful as an approximation only. Real print work uses an ICC profile for the specific press and stock.

What do the newer CSS colour spaces do that hex cannot?

Hex and rgb() can only describe colours inside the sRGB gamut. CSS Color Level 4 adds spaces such as oklch(), lab() and display-p3, which reach colours modern wide-gamut screens can show but sRGB cannot express, and which interpolate more evenly — a gradient in OKLCH avoids the muddy midpoint that the same gradient in sRGB produces.

Does the alpha channel affect contrast?

Yes, and it is a common source of accidental failures. A semi-transparent colour composites with whatever is behind it, so its effective contrast depends on the background. Check the ratio using the final composited colour rather than the declared one, particularly for text over images or gradients.

References

Sources

The formulas and reference ranges on this page come from the following publications. Where a source has been revised, we cite the current edition.

  1. 1CSS Color Module Level 4World Wide Web Consortium (W3C)
  2. 2Web Content Accessibility Guidelines (WCAG) 2.2 — Contrast (Minimum)World Wide Web Consortium (W3C)
  3. 3Understanding Success Criterion 1.4.3: Contrast (Minimum)W3C Web Accessibility Initiative
  4. 4A Standard Default Color Space for the Internet — sRGBWorld Wide Web Consortium (W3C)

Keep going