Guides Websites and SEO
HEX, RGB and HSL Colour Codes, and Accessible Contrast
How the main colour code systems work, how to convert between them and how to choose text colours everyone can read.
Designers, developers, shopkeepers making social media posts and students formatting presentations all meet colour codes sooner or later. A brand guide lists #2453E6, a website theme asks for RGB values, a printer wants CMYK and an accessibility report complains that your grey text has a contrast ratio of only 3.9:1. These are different ways of describing the same thing, and once you understand how each one works, choosing and converting colours becomes straightforward.
This guide explains HEX, RGB, HSL and CMYK, shows how to convert between them and covers the contrast rules that make text readable for everyone.
RGB: mixing light
Screens create colour by mixing red, green and blue light. In the RGB system, each channel has a value from 0 (off) to 255 (full brightness).
- rgb(255, 0, 0) is pure red
- rgb(0, 0, 0) is black, with all channels off
- rgb(255, 255, 255) is white, with all channels at full
- rgb(36, 83, 230) is a strong blue
Because it mixes light, RGB is an additive system: adding more of each channel makes the colour lighter.
HEX: RGB written in hexadecimal
A HEX code is simply RGB written in base 16. The code #RRGGBB has two digits for each channel, from 00 (0) to FF (255).
Example: #2453E6 breaks into 24, 53 and E6. In decimal, 24 is 36, 53 is 83 and E6 is 230, so #2453E6 is rgb(36, 83, 230).
A few shortcuts and extensions are worth knowing:
- Three-digit codes double each digit: #FFF is #FFFFFF and #09C is #0099CC.
- Eight-digit codes add transparency: #2453E680 is the same blue at about 50 per cent opacity.
- Case does not matter: #2453e6 and #2453E6 are identical.
The HEX to RGB converter and the Color Converter translate between formats instantly.
HSL: colour the way people think about it
HSL describes a colour by hue, saturation and lightness:
- Hue is the position on the colour wheel, from 0 to 360 degrees: 0 is red, 120 is green and 240 is blue.
- Saturation runs from 0% (grey) to 100% (fully vivid).
- Lightness runs from 0% (black) through 50% (the pure colour) to 100% (white).
Our example blue, #2453E6, is about hsl(225, 80%, 52%). HSL makes it easy to create related colours: keep the hue and saturation and change only the lightness to get lighter tints for backgrounds and darker shades for hover states. The Color Shades Generator produces a full range this way.
CMYK: colour on paper
Printers mix cyan, magenta, yellow and black inks. Ink absorbs light, so CMYK is a subtractive system: more ink makes a darker colour. Screens can show some bright colours, especially vivid blues and greens, that ink cannot reproduce, so a colour may look duller in print than on screen.
The RGB to CMYK converter gives a mathematical conversion, which is a useful starting point. For important print jobs such as packaging or brand stationery, ask your printer which colour profile they use and request a printed proof before the full run.
Contrast: making text readable
Colour choice is not only about looks. Text that does not stand out enough from its background is hard to read in sunlight, on cheap screens and for people with low vision. The Web Content Accessibility Guidelines (WCAG) define contrast as a ratio between the relative brightness of two colours, from 1:1 (no contrast) to 21:1 (black on white).
The main thresholds are:
| Requirement | Normal text | Large text |
|---|---|---|
| WCAG AA (the usual target) | at least 4.5:1 | at least 3:1 |
| WCAG AAA (enhanced) | at least 7:1 | at least 4.5:1 |
Large text means at least 24 pixels at normal weight, or about 18.7 pixels in bold. Buttons, form borders and icons that people need to see should reach at least 3:1 against what surrounds them.
Worked contrast examples
All on a white background:
| Text colour | Contrast ratio | Result for normal text |
|---|---|---|
| #777777 (mid grey) | 4.48:1 | Just fails AA |
| #767676 (a shade darker) | 4.54:1 | Passes AA |
| #595959 (dark grey) | 7.0:1 | Passes AAA |
| #FF0000 (pure red) | 4.0:1 | Fails AA |
| #2453E6 (strong blue) | 6.08:1 | Passes AA |
| #FFD700 (gold) | 1.4:1 | Fails badly |
The first two rows show how fine the line can be: #777777 and #767676 look identical, yet one passes and one does not. The gold row shows why yellow text on white is almost unreadable. Pakistan's flag green, often given as #01411C, has a contrast ratio of about 11.8:1 with white, which is why white text on that green reads so clearly. The Color Contrast Checker calculates any pair and suggests the nearest colour that passes.
Designing for colour blindness
Colour vision deficiency is common, affecting roughly 1 in 12 men and 1 in 200 women of Northern European ancestry according to commonly cited figures, with red-green types the most frequent. Two rules prevent most problems:
- Never use colour alone to carry meaning. Mark errors with an icon or text as well as red, and label chart lines directly rather than relying on a colour legend.
- Check your design. The Color Blindness Simulator shows how an image looks with different types of colour vision deficiency.
Building a simple palette
A practical palette for a website, shop or presentation usually needs:
- one brand colour for buttons, links and highlights
- a few neutrals, such as near-black text, mid-grey secondary text and light grey borders and backgrounds
- one accent for occasional emphasis
- status colours for success, warning and error messages
A common guideline is the 60-30-10 rule: about 60 per cent of a design in a dominant neutral, 30 per cent in a secondary colour and 10 per cent in an accent. Start from your brand colour in the Color Palette Generator, then check every text and background pair for contrast. The Color Picker helps you find exact codes from your own images and designs.
Dark mode
Dark themes need their own checks. Pure white text on pure black can feel harsh, so many designs use off-white text on a very dark grey. Colours that work on white often need lighter versions on dark backgrounds to keep enough contrast, so test both themes rather than assuming one palette fits both.
Text on photos and social graphics
Text placed over photographs is one of the most common contrast failures, because a photo has light and dark areas behind different letters. Three fixes work reliably: place a semi-transparent dark band behind the text, choose a calm part of the image with even tone, or put the text on a solid colour block beside the photo. Always check the finished graphic on a phone at normal brightness, since that is how most people will see it.
Common mistakes
- Light grey text for a "clean" look. It often fails contrast and is hard to read on phones outdoors.
- Brand colours on white without checking. Many bright brand colours fail as text colours; use them for backgrounds or large elements instead.
- Relying on colour alone for errors, required fields or chart lines.
- Expecting screen colours in print. Ask for a proof.
- Copying codes inaccurately. One wrong digit changes the colour; copy and paste rather than retyping.
Privacy
The colour tools on this site run in your browser. Images you pick colours from are processed on your device and are not uploaded.