The Complete Guide to Web Colors: HEX, RGB, HSL and How to Build a Palette That Works
Every button, background and line of text on a website has a color value behind it. Understanding how those values work helps you pick colors faster, avoid readability problems and keep your design consistent.
How computers describe color
Screens create color by mixing red, green and blue light. Each channel has 256 levels, from 0 (off) to 255 (full strength). Three channels with 256 levels each give 16,777,216 possible colors. Every web color format is just a different way of writing those same three numbers.
HEX, RGB and HSL compared
HEX
A HEX code is a # followed by six characters. The pairs stand for red, green and blue, written in base 16. For example, #5B4BFF means red 5B (91), green 4B (75) and blue FF (255). A shorter three-character form such as #fff works when each pair repeats. HEX is compact and is the format most design tools export.
RGB
RGB writes the same values in plain decimals: rgb(91, 75, 255). It is easy to read and easy to calculate with. Adding a fourth value gives transparency, as in rgba(91, 75, 255, 0.5), where 0 is invisible and 1 is solid.
HSL
HSL describes hue (the position on the color wheel from 0 to 360), saturation (how vivid it is) and lightness (how light or dark it is). The same color is hsl(245, 100%, 65%). HSL is the most natural format for adjustments: keep the hue, change the lightness, and you get a matching shade or tint.
| Format | Example | Best used for |
|---|---|---|
| HEX | #5B4BFF | Sharing and storing brand colors |
| RGB / RGBA | rgb(91, 75, 255) | Transparency and code calculations |
| HSL | hsl(245, 100%, 65%) | Creating shades, tints and themes |
One hue at five lightness levels. Only the L value changed in HSL.
You can convert between all three formats with the Color Picker above or with the Color Code Converter.
Color schemes from the color wheel
Most professional palettes follow a simple relationship on the color wheel. Using one of these gives your design a reason to look balanced.
- Monochromatic: one hue in several lightness levels. Calm and safe.
- Analogous: hues that sit next to each other, about 30 degrees apart. Smooth and harmonious.
- Complementary: two hues opposite each other, 180 degrees apart. High energy, good for call-to-action buttons.
- Triadic: three hues spaced 120 degrees apart. Colorful and balanced when one color leads.
- Tetradic: two complementary pairs. Rich, but needs careful control to avoid chaos.
In CSS the idea is easy to test. To find the complement of hsl(245, 100%, 65%), add 180 to the hue:
--main: hsl(245, 100%, 65%);
--complement: hsl(65, 100%, 65%); /* 245 + 180 = 425, minus 360 = 65 */
The 60-30-10 rule
Designers often split a layout by proportion: about 60% a dominant neutral (backgrounds), 30% a secondary color (cards, headers, sections) and 10% an accent (buttons, links, highlights). It is a guide, not a law, but it stops every color from competing for attention and makes your accent stand out.
Contrast and accessibility
A beautiful color pair is useless if people cannot read it. The Web Content Accessibility Guidelines (WCAG) measure contrast as a ratio from 1:1 (no difference) to 21:1 (black on white).
- Level AA, normal text: at least 4.5:1.
- Level AA, large text and interface components: at least 3:1.
- Level AAA, normal text: at least 7:1.
Tip: Never use color alone to carry meaning. Pair red error states with an icon or message so people with color blindness do not miss them.
Test your text and background pair with the Color Contrast Checker before you publish.
Build a palette step by step
- Pick one main color. Choose a hue that fits the mood of your project, such as blue for trust or green for growth.
- Choose a scheme. Use the wheel relationships above to find one or two supporting hues.
- Add neutrals. Pick a near-white background, a dark text color and a mid-gray for borders.
- Create shades and tints. Adjust lightness in HSL to build hover states, backgrounds and disabled styles.
- Check contrast. Test every text and background pairing against WCAG.
- Save it as variables. Store the final colors as CSS custom properties so the whole site stays consistent.
:root {
--color-main: #5B4BFF;
--color-main-dark: #3A2FD1;
--color-bg: #FFFFFF;
--color-text: #14173A;
}
Start quickly with the Color Palette Generator and refine the result in the picker.
Common mistakes
- Using too many bright colors at once, so nothing stands out.
- Placing light gray text on a white background.
- Choosing colors on one screen only. Check your design on a phone and in dark mode too.
- Forgetting hover, focus and disabled states.
- Changing hex codes by hand without a system, which slowly makes a brand look inconsistent.
Final thoughts
Good color work is less about talent and more about a repeatable process: understand the formats, choose a scheme, respect the proportions and test readability. All the tools you need for each step are on this site, and every one of them is 100% free with no registration. Browse all color tools.