Skip to contentSkip to the inputSkip to the result

Colour code converter

Convert HEX, RGB and HSL colours

Loading tool

Instructions

Colour code converter

How to use

  1. Enter a colour as #1e90ff, rgb(30,144,255), hsl(210,100%,56%) or a name such as tomato, or pick one.

Supported input

  • 3-, 4-, 6- and 8-digit HEX (4 and 8 carry alpha), RGB and RGBA 0–255, HSL and HSLA, and the 148 CSS colour names.
  • Contrast uses the WCAG 2 relative luminance formula on the colour without its alpha.

Input example

#1e90ff

Result example

rgb(30, 144, 255) · hsl(209.6, 100%, 55.9%)

Troubleshooting

  • Values that are not numbers or are out of range are not calculated; the message says what to fix.

Limitations

  • Wide-gamut (P3) colours and inputs such as oklch() or lab() are not read; OKLCH is given as a result only.

How it works

  • Converts a colour between HEX, RGB, HSL, HSV and OKLCH and measures its contrast with white and black text.

One colour in HEX, HSL and OKLCH, and what its contrast numbers mean

Where it earns its keep

  • A mock-up gives you #ff6347 and the stylesheet needs it at 40% opacity, as rgba() or an eight-digit HEX
  • You want to know whether white text on the brand colour will pass an accessibility review before anyone files a ticket
  • A hover state should be "a bit lighter", and you want to nudge one lightness number instead of guessing a new HEX
  • Your design tool shows HSB values that never match the HSL in the CSS, and you want to see why

How the numbers are derived

HEX is just red, green and blue written as two hex digits each, 0 to 255, so it holds exactly what rgb() holds. A three-digit code doubles each digit: #f80 is #ff8800, or rgb(255, 136, 0). HSL takes the largest and smallest of the three channels: their average is the lightness, their spread sets the saturation, and which channel is largest decides the hue angle. HSV instead uses the largest channel directly as its value. That is why tomato (#ff6347) is hsl(9.1, 100%, 63.9%) but hsv(9.1, 72.2%, 100%), and why the HSB panel in a design tool never agrees with the HSL in your CSS.

OKLCH starts by removing the sRGB gamma curve to get linear light, passes that through the OKLab transform (the matrices Björn Ottosson published, which CSS Color 4 adopted) and reports lightness, chroma and hue. HSL results carry one decimal place, because HSL needs that much to land back on the same HEX. Round #1e90ff to whole numbers, hsl(210, 100%, 56%), and you get #1f8fff back, one step off in two channels.

Worked example: two colours at "50% lightness"

  1. 1Enter hsl(60, 100%, 50%). It is #ffff00, pure yellow, with an OKLCH lightness of 96.8% and a contrast of 19.56 : 1 against black text.
  2. 2Enter hsl(240, 100%, 50%). It is #0000ff, pure blue, with an OKLCH lightness of 45.2% and 8.59 : 1 against white text.
  3. 3HSL calls both of them 50% light, yet one looks more than twice as bright as the other. HSL lightness is an average of channel values and knows nothing about the eye.
  4. 4For a palette whose hues change while the perceived brightness stays put, hold the first OKLCH number steady and vary the hue.

Reading the contrast ratio

Contrast follows WCAG 2.2: (lighter luminance + 0.05) ÷ (darker luminance + 0.05). Luminance weights the linearised channels by 0.2126 for red, 0.7152 for green and 0.0722 for blue, so green does most of the work. The tool still uses the older gamma threshold of 0.03928; WCAG 2.2 changed it to 0.04045 and notes that this makes no practical difference. For 8-bit colours it makes none at all, because no channel value falls between 10/255 (0.0392) and 11/255 (0.0431).

A pair of greys shows how sharp the line is. #767676 on white is 4.54 : 1; one step lighter, #777777, is 4.48 : 1. That makes #767676 the lightest neutral grey that clears 4.5 : 1 for body text on white, and it is why a ratio shown as 4.48 must never be read as "about 4.5". At the other end, #595959 on white is 7.00 : 1 (7.005 before rounding).

What it will not read, and what to do instead

  • Percentage RGB such as rgb(100%, 0%, 0%), the keywords transparent and currentcolor, and hue units like turn or rad are not read. Convert to 0–255 or degrees first.
  • The hsv(…) line is for design tools only; CSS has no hsv() function. Paste the HEX, rgb(), hsl() or oklch() line, or use hwb(), which CSS does have.
  • Alpha in an eight-digit HEX has 256 steps, so exact percentages do not survive: 25% is written 40, and #ff000040 reads back as 25.1%.
  • Text over a gradient or a photo has no single background colour. Check the lightest and the darkest spot behind the text separately.
  • Borders, icons and other graphics are judged by WCAG 2.2 criterion 1.4.11 at 3 : 1. The two ratios shown are against white and black only; for any other background, convert that colour as well and compare.

Checked

Frequently asked questions

How do I convert a HEX colour to RGB?

Split it into pairs and read each pair as a hex number. #1e90ff is 1e = 30, 90 = 144, ff = 255, so rgb(30, 144, 255).

What contrast ratio does text need?

Under WCAG 2, AA asks for 4.5:1 for body text and 3:1 for large text; AAA asks for 7:1 for body text. #1e90ff gives 3.24:1 with white and 6.49:1 with black, so black body text passes on it.

Is a code with alpha, such as #ff880080, read?

Yes. The last two digits of an 8-digit HEX, or the last digit of a 4-digit one, are the alpha, so #ff880080 is rgba(255, 136, 0, 0.502), 50.2% opaque. rgba(), hsla() and CSS names such as tomato are read too. Contrast is worked out without the alpha, so the real contrast depends on what is behind.