Colour converter: HEX, RGB and HSL
Convert between colour formats and check contrast against white.
Calculator inputs
Results
Enter your values and press “Calculate” to see the result.
In short
- What it calculates
- Convert between colour formats and check contrast against white.
- Formula used
Luminance = 0.2126·R + 0.7152·G + 0.0722·B (linearised)- Example
- The colour #2563eb is equivalent to:
HEX, RGB and HSL colour converter
Every design tool speaks a different language: hexadecimal in CSS, RGB in image editors and HSL when you want to shift the hue without losing saturation.
Contrast against white is calculated too, the figure that decides whether text will be readable.
How it works
The colour is read in any of the three formats and converted to the other two. Relative luminance follows the formula from the WCAG accessibility guidelines.
Formula
Luminance = 0.2126·R + 0.7152·G + 0.0722·B (linearised)
Contrast = (L1 + 0.05) ÷ (L2 + 0.05)
Worked example
The colour #2563eb is equivalent to:
rgb(37, 99, 235)
hsl(221, 83%, 53%)
Contrast against white: 5.17:1
Explanation
Contrast is not a matter of taste
The WCAG accessibility guidelines set a minimum ratio of 4.5 to 1 between text and background for normal text, and 3 to 1 for large text. It is not an aesthetic recommendation: below those values a significant share of the population cannot read comfortably, and in many countries it is a legal requirement for public sector sites.
Why HSL is easier to work with than RGB
In RGB, lightening a colour means adjusting three numbers at once and guessing. In HSL you simply raise the lightness leaving the hue untouched, which lets you build coherent palettes by changing a single value. It is why design systems prefer it for generating variants.
The alpha channel and transparency
A colour with alpha blends with whatever is beneath it, so real contrast depends on the background it sits on. Grey text at fifty per cent may pass on white and fail over an image.
Colour must not be the only signal
Around eight per cent of men have some form of colour blindness. Indicating an error only in red, or a status only in green, excludes those people. Always pair it with text, an icon or a shape.
Frequently asked questions
What contrast do I need?
WCAG 2.2 asks for 4.5:1 on normal text and 3:1 on large text at level AA.
Why use HSL?
Because it separates hue, saturation and lightness, which makes it easy to build consistent variants of one colour.
What contrast does text need?
At least 4.5 to 1 for normal text and 3 to 1 for large text, under the WCAG guidelines at level AA.
Why is colour alone not enough to show status?
Because around eight per cent of men have some form of colour blindness. Add an icon, a shape or text alongside the colour.
Need to calculate something else?
These tools are often used alongside this calculator.
Base converter
Convert numbers between bases 2, 8, 10, 16, 32 and 36.
Base64
Turn text into Base64 and recover the original text.
Slug generator
Turn a title into a clean URL with no accents or odd characters.
Passwords
Random passwords with calculated entropy, generated in your browser.
Timestamp
Convert between Unix timestamps and readable UTC dates.