Design Tools

HEX, RGB and HSL: three ways to write the same colour, and which to use

The indigo #6366f1 is also rgb(99, 102, 241) and hsl(239, 84%, 67%). This guide explains how each format works, how to convert between them by hand, and why HSL is the friendliest one when you want a lighter, darker or matching shade.

By the Toolcloak team8 October 20264 min read
In this article
  1. Same colour, three spellings
  2. RGB: mixing three lights
  3. HEX: the same numbers in base 16
  4. HSL: describing colour like a person
  5. Why HSL makes shades easy
  6. How big is the colour space?
  7. Quick practice

A colour on a screen is three small lights, red, green and blue, each shining at some strength. HEX, RGB and HSL are different ways to write down the same three strengths. Knowing which to pick makes everyday design jobs much easier, such as making a button hover colour or a matching border.

Same colour, three spellings

One indigo, written three ways
#6366f1HEXCompact, the usual choice in design files and CSS
rgb(99, 102, 241)RGBRed, green and blue strengths from 0 to 255
hsl(239, 84%, 67%)HSLHue, saturation, lightness

These all produce the exact same pixels on screen. Pick the format that makes your next change easy.

Paste a colour in any format and get the others instantly, ready to copy.Open Color Converter

RGB: mixing three lights

Each of the three channels runs from 0 (off) to 255 (full). Full red, no green, no blue is pure red. All three at 255 makes white, and all at 0 makes black. When the three values are equal, you get a grey. Our indigo has little red (99), a bit more green (102) and a lot of blue (241), so it leans strongly blue.

Channel strengths of #6366f1 (out of 255)
99Red102Green241Blue

Blue dominates at 241, so the colour reads as blue-violet. Red and green are close to each other and far lower.

ColourRGBHEXHSL
Red255, 0, 0#ff00000°, 100%, 50%
Orange255, 128, 0#ff800030°, 100%, 50%
Green0, 255, 0#00ff00120°, 100%, 50%
Blue0, 0, 255#0000ff240°, 100%, 50%
White255, 255, 255#ffffff0°, 0%, 100%
Black0, 0, 0#0000000°, 0%, 0%

Pure white and black have equal channels, so they have no hue, and their saturation is 0 by convention. In HSL, white is always L = 100% and black L = 0%.

HEX: the same numbers in base 16

A hex code is just RGB with each number written as two characters in base 16, where the digits go 0–9 then A–F. 99 becomes 63, 102 becomes 66 and 241 becomes F1. Put them together after a hash: #6366f1.

RGB 99 to HEX 63
  1. 1Divide by 1699 ÷ 16 = 6 remainder 3.
  2. 2Write both digitsThe quotient is the first digit (6), the remainder the second (3).
  3. 3Repeat for each channel102 → 66, and 241 → F1 (15 × 16 + 1). Join: 63 66 F1.

To learn more about counting in base 16, see binary, hex and decimal.

HSL: describing colour like a person

Ask someone to describe a colour and they say “a bright blue” or “a pale pink”. HSL matches that language. Hue is the position on the colour wheel in degrees (red at 0°, green at 120°, blue at 240°). Saturation is how vivid it is, from grey (0%) to full colour (100%). Lightness goes from black (0%) through the pure colour (50%) to white (100%).

The hue wheel, laid flat (degrees)
Red
Orange
Yellow
Green
Cyan
Blue
Purple
Pink
239°
060120180240300360

Our indigo sits at 239°, in the blue band, close to violet. Turn the dial and you move around the rainbow without changing how vivid or light it is.

Saturation of #6366f1: 84%
84%
  • Grey0–20%
  • Muted20–60%
  • Vivid60–100%

The bands are only a rough guide. At 84%, this indigo is quite vivid, which is why it is popular for buttons and links.

Three dials, three questions
Hue (H)Which colour? 0° red, 60° yellow, 120° green, 180° cyan, 240° blue, 300° magenta.
Saturation (S)How strong? 0% is grey, 100% is the purest version of the hue.
Lightness (L)How bright? 0% black, 50% pure colour, 100% white.
Alpha (A)How opaque? 1 is solid and 0 is invisible. Written hsla or as a fourth value.

Changing one dial leaves the other two alone, which is exactly why HSL is easier to edit by hand.

Why HSL makes shades easy

Keep the hue (239°) and saturation (84%) the same and slide only the lightness. You get a full family of shades that obviously belong together, which is the idea behind most design systems.

LightnessHSLHEXTypical use
95%hsl(239, 84%, 95%)#e8e8fdBackgrounds, tints
85%hsl(239, 84%, 85%)#b9baf9Backgrounds, tints
75%hsl(239, 84%, 75%)#8a8bf5Borders, icons
65%hsl(239, 84%, 65%)#5b5df1Borders, icons
55%hsl(239, 84%, 55%)#2c2fedBorders, icons
45%hsl(239, 84%, 45%)#1216d3Buttons, links
35%hsl(239, 84%, 35%)#0e11a4Hover and dark text
25%hsl(239, 84%, 25%)#0a0c75Hover and dark text

Only the L value changes from row to row. Trying to do this by editing HEX digits is much harder.

Making a hover colour 10% darker
In HEX or RGB3 numbers
  • Change red, green and blue together
  • Easy to shift the hue by accident
  • Needs a tool or a lot of trial
In HSL1 number
  • Lower L from 67% to 57%
  • Hue and saturation stay put
  • Result is the same family of colour

Both end as the same kind of pixels, but HSL gets you there with one edit.

For a matching accent, add 180° to the hue to get the opposite colour on the wheel. For our indigo that is hsl(59, 84%, 67%), or #f2ef64, a bright yellow that contrasts strongly.

How big is the colour space?

Counting colours
256Levels per channel0 to 255, which is 8 bits
16.7 millionColours in total256 × 256 × 256 = 16,777,216
24 bitsStorage per pixelThree bytes, one per channel

More than enough colours for ordinary screens, which is why 8 bits per channel became the standard.

Quick practice

  1. What is #ff0000 in RGB? rgb(255, 0, 0), pure red.
  2. What is #808080? rgb(128, 128, 128), a mid grey with saturation 0%.
  3. What is #f60 written in full? #ff6600, which is rgb(255, 102, 0).
  4. You want a lighter version of hsl(239, 84%, 67%). Raise L, for example to 77% for a softer tint.

Use HEX to copy and paste, RGB when working with code that needs numbers, and HSL when you want to adjust a colour by hand. A converter lets you switch whenever it helps.

Questions people ask

How do you convert HEX to RGB?

Split the code into three pairs and convert each from base 16 to decimal. For #6366f1: 63 → 99, 66 → 102, f1 → 241, so rgb(99, 102, 241).

What is the difference between RGB and HSL?

They describe the same colours. RGB mixes red, green and blue light. HSL uses hue, saturation and lightness, which is closer to how people think about colour.

What does #fff mean?

It is shorthand for #ffffff, which is white. Each digit is doubled, so #f60 is #ff6600.

How do I make a colour lighter?

In HSL, raise the lightness value. In RGB or HEX you would need to move all three channels closer to 255.

How many colours can HEX codes represent?

16,777,216 (256³), since each of the three channels has 256 levels.

How do I add transparency to a HEX colour?

Add two more hex digits for alpha: 00 is invisible and ff is solid. For example, #6366f180 is about 50% opaque.