Color Formats Explained: HEX, RGB and HSL (with Conversions)

5 min read · Published 1 November 2026 · Updated 2 November 2026

The same color can be written in several ways, and designers and developers move between them all day. HEX is compact, RGB matches how screens mix light, and HSL is the easiest to reason about when you want a lighter or a more muted version. This guide explains each format, shows a worked conversion and finishes with the contrast rules that keep text readable.

RGB: mixing light

Screens create color by mixing red, green and blue light. RGB writes the amount of each channel from 0 (none) to 255 (full). In CSS: rgb(255 87 51), or the older comma form rgb(255, 87, 51). Black is rgb(0 0 0), white is rgb(255 255 255) and pure red is rgb(255 0 0). Adding an alpha value sets transparency: rgb(255 87 51 / 50%).

HEX: RGB in base 16

A HEX color is the same three channel values written in hexadecimal, two digits each, after a # sign: #RRGGBB. Each pair runs from 00 (0) to FF (255). So #FF5733 means red FF = 255, green 57 = 87 and blue 33 = 51, exactly the RGB color above. A three-digit shorthand such as #F53 doubles each digit (it means #FF5533), and an eight-digit form #RRGGBBAA adds alpha at the end.

HSL: hue, saturation, lightness

HSL describes a color the way people think about it. Hue is the position on the color wheel in degrees (0 red, 120 green, 240 blue). Saturation is how vivid it is, from 0% (gray) to 100% (full color). Lightness runs from 0% (black) through 50% (the pure color) to 100% (white). The orange above is hsl(11 100% 60%).

A worked conversion

#FF5733 to RGB and HSL

#FF5733
R = FF = 255, G = 57 = 87, B = 33 = 51
rgb(255 87 51)

Lightness  = (max + min) / 2 = (1.00 + 0.20) / 2 = 60%
Saturation = (max - min) / (1 - |2L - 1|) = 0.80 / 0.80 = 100%
Hue        ≈ 60 × (G - B) / (max - min) ≈ 11 degrees
hsl(11 100% 60%)

Which format when

  • HEX: compact and universal in design tools and style sheets. Good for copying and pasting a single fixed color.
  • RGB: handy when you compute colors in code or need transparency in a simple form.
  • HSL: best for creating variations. To make a hover state, keep the hue and change lightness by 5–10 points. To make a muted version, lower saturation. To build a palette, keep saturation and lightness steady and rotate the hue.

Picking a color from an image

An eyedropper reads the color of one pixel. In photographs and gradients, neighbouring pixels differ slightly because of lighting and compression, so sample a few places or an area that is a flat color. Remember that a color on screen can look different on another display or after printing, because of color profiles and hardware differences.

Contrast and accessibility

Readable text needs enough contrast against its background. The Web Content Accessibility Guidelines (WCAG) define a contrast ratio from 1:1 (no contrast) to 21:1 (black on white). For normal body text, the AA level asks for at least 4.5:1, and for large text (about 24 px, or 19 px bold) at least 3:1. The stricter AAA level asks for 7:1 for body text. Light gray text on white and many pastel combinations fail these checks.

Do not rely on color alone

Around one in twelve men and a smaller share of women have some form of color vision deficiency. Do not use color as the only way to show an error, a required field or a chart category. Add an icon, a label or a pattern as well.

Practical tips

  1. Store brand colors once, as CSS variables, and reuse them.
  2. Keep a neutral base, one or two accent colors and use them sparingly.
  3. Check the contrast of every text and background pair, including the dark mode version.
  4. Prefer HSL when you need lighter or darker variations of the same color.

Building a palette with HSL

Because HSL separates hue from lightness, a whole set of related colors can be made from one base color. Starting from the orange hsl(11 100% 60%):

  • A darker hover color: lower the lightness, hsl(11 100% 50%).
  • A soft background tint: raise the lightness to hsl(11 100% 95%).
  • A muted version: reduce saturation, hsl(11 40% 60%).
  • A related accent: shift the hue by about 30 degrees, hsl(41 100% 60%).

Contrast ratios in practice

Black text on a white background has the maximum ratio of 21:1. A mid-gray such as #767676 on white is about 4.5:1, which is roughly the lightest gray that still passes the AA level for body text. A lighter gray such as #999999 on white is only about 2.85:1 and fails. Check the pairs you actually use, including text over images and the dark-mode versions of your colors.

Frequently asked questions

What is the difference between #FFF and #FFFFFF?
Nothing. The three-digit form repeats each digit, so #FFF means #FFFFFF (white) and #F53 means #FF5533.
What does the alpha value do?
Alpha sets opacity, from 0 (fully transparent) to 1 or 100% (fully opaque). It can be written in rgb(), hsl(), or as two extra hex digits, such as #FF573380 for about 50% opacity.
Are HSL and HSV the same?
No. They are different ways of organising the same colors. HSL uses lightness, where 50% is the pure color, while HSV (also called HSB) uses value or brightness, where 100% is the pure color. CSS uses HSL, many design tools show HSB.
Can CSS show colors outside the usual RGB range?
Yes. Newer CSS color spaces such as display-p3, oklch and oklab can describe a wider range of colors on supporting screens. They are useful for modern design systems, with a fallback for older browsers.

Sources and further reading

Try it yourself: Color Picker runs in your browser, free and with no sign-up.

More guides