Hex and RGB: A Guide to Web Color Formats
In this guide
Colours on screens are made from red, green and blue light. Hex codes and RGB values are two ways of writing the same mixture, and designers and developers constantly move between them, along with HSL, which describes colour in a more intuitive way.
How hex maps to RGB
A hex colour like #1E90FF is three pairs of hexadecimal digits: 1E for red, 90 for green and FF for blue. Each pair is a number from 0 to 255, so 1E is 30, 90 is 144 and FF is 255, giving rgb(30, 144, 255). A three-digit shorthand such as #0AF doubles each digit to make #00AAFF.
When to use which
Hex is compact and common in CSS and design tools. RGB is convenient when you need transparency, as in rgba(30, 144, 255, 0.5), or when adjusting channels in code. HSL (hue, saturation, lightness) is easier for creating variations: change the lightness to make a darker or lighter shade of the same colour.
Contrast and accessibility
A colour that looks fine to you may be unreadable for others. The Web Content Accessibility Guidelines require a contrast ratio of at least 4.5 to 1 for normal text and 3 to 1 for large text. Check text and background pairs with a contrast checker rather than judging by eye.
Building a palette
Pick one main colour, derive lighter and darker shades from it, add one or two accent colours, and keep neutrals for backgrounds and text. Extracting colours from a logo or photo is a quick way to start.
Display differences
Colours look different on different screens, and hex codes describe screen colour, not print colour. For printed materials, ask the printer which colour system they require.
Worked example: #ff6600
The hex colour #ff6600 is three pairs of hexadecimal digits: ff, 66 and 00. In decimal those are 255, 102 and 0, so the Hex to RGB converter on this site returns rgb(255, 102, 0): full red, a little green, no blue, which is a strong orange.
You can check it by hand: ff is 15 x 16 + 15 = 255, and 66 is 6 x 16 + 6 = 102. Because each channel runs from 0 to 255, the largest hex pair is ff and the smallest is 00.
Key Takeaways
- Hex is three pairs: red, green, blue, each 0 to 255.
- Use rgba for transparency and HSL for shades.
- Aim for 4.5:1 contrast for body text.
- Print colour needs separate handling.
Frequently Asked Questions
How do I convert hex to RGB by hand?
Convert each pair of hex digits to decimal. For example, FF is 255 and 80 is 128.
What does the shorthand #FFF mean?
It expands each digit, so #FFF is #FFFFFF, which is white.
Why does my colour look different on another screen?
Displays vary in calibration and colour range.
Free tools mentioned in this guide
Browse every Converter Tools utility, or see all tools.