Color & Hex Codes Explained: RGB, Hex, HSL & Picking Palettes

Every colour on your screen is three numbers β€” red, green, blue β€” and a hex code is just those numbers written in base 16. Learn to read #6D28D9 at a glance, when HSL is easier, and how to pick colours people can actually read.

πŸ“‚ Images & Design ⏱ About 9 minutes πŸ“Ά Beginner πŸ› οΈ Pairs with: Color Picker

What you will learn

  • Explain how a screen makes any colour from red, green and blue
  • Read a hex code and picture the colour it describes
  • Use shorthand hex and the alpha channel
  • Switch between RGB and HSL β€” and know when HSL wins
  • Check contrast so text stays readable for everyone
In this guide
  1. How screens make colour
  2. Hex codes: the same numbers, in base 16
  3. HSL: the human-friendly notation
  4. Contrast: can people actually read it?
  5. Building a palette that works
  6. Common mistakes
  7. Try it: Color Picker
  8. Frequently asked questions

How screens make colour

Your screen is a grid of tiny lights in three colours: red, green and blue. Each pixel has one red, one green and one blue sub-pixel, and each can shine at 256 levels of brightness (0–255). Mix them and you get every colour the screen can show β€” 256 Γ— 256 Γ— 256 = 16.7 million colours.

It is additive colour: adding light makes things brighter. Red + green light makes yellow; red + green + blue at full brightness makes white; all three off makes black. That is the opposite of paint, where mixing colours makes things darker β€” and the reason screen colours and print colours (CMYK) never quite match.

Those three numbers are the whole story. Everything else β€” hex codes, HSL, colour names β€” is just a different notation for the same three numbers.

Hex codes: the same numbers, in base 16

A hex code writes the three RGB numbers in hexadecimal (base 16, digits 0–9 then a–f), prefixed with #:

#6D28D9
β”‚  β”‚  β”‚
β”‚  β”‚  └─ Blue:  D9 = 217
β”‚  └──── Green: 28 = 40
└─────── Red:   6D = 109
So #6D28D9 is rgb(109, 40, 217) β€” a vivid violet.

Each pair of hex digits is one channel: 00 is off, FF (255) is full. Read a hex code left to right and you can picture the colour: high red + high green + low blue is a yellow; equal values are a grey (#808080 is mid-grey, #FFFFFF white, #000000 black); one channel high and the others low is a saturated colour.

HexRGBColour
#FF0000255, 0, 0Pure red
#00FF000, 255, 0Pure green
#0000FF0, 0, 255Pure blue
#FFFF00255, 255, 0Yellow (red + green)
#FF00FF255, 0, 255Magenta (red + blue)
#00FFFF0, 255, 255Cyan (green + blue)
#6D28D9109, 40, 217Violet β€” our guides brand colour

Two shorthands: when each pair has identical digits, you can write three digits instead of six (#FFF = #FFFFFF, #09C = #0099CC). And an optional fourth pair (or digit) adds an alpha channel for transparency: #6D28D980 is the same violet at 50% opacity.

HSL: the human-friendly notation

RGB describes what the screen does; HSL describes what a human thinks: Hue (the colour, 0–360Β° around a wheel), Saturation (how vivid, 0–100%), Lightness (how bright, 0–100%). Our violet is hsl(262, 69%, 50%) β€” hue 262Β° (violet), fairly saturated, mid-lightness.

HSL wins whenever you need to adjust a colour: make it lighter (raise L), mute it (lower S), or find a matching colour (shift H by 180Β° for the complement). Try doing that in hex and you'll see why designers think in HSL and machines store RGB. Convert freely β€” they describe the same colour.

Contrast: can people actually read it?

A beautiful palette that nobody can read is a failed palette. The WCAG accessibility standard measures the contrast ratio between text and background: 4.5:1 for normal text, 3:1 for large text. Grey text on a white background (#94A3B8 on white, ratio ~2.7:1) fails; dark slate (#0F172A, ratio ~14:1) passes easily.

Practical rules: body text should be dark on light or light on dark, never mid-on-mid; never use colour alone to convey meaning (add an icon or label, for colour-blind readers β€” about 1 in 12 men have some colour-vision deficiency); and test your palette in greyscale β€” if the design still works, the colours were doing decoration, not communication.

Building a palette that works

  1. Start with one brand colour

    Pick the colour people should remember β€” one hue, mid-saturation, mid-lightness. Everything else supports it.

  2. Derive, don't decorate

    Lighter and darker versions of the same hue (same H, different L) for backgrounds and hover states; a complement or near-complement for accents. Three hues is plenty for most sites.

  3. Add neutrals

    Greys with a hint of your brand hue feel designed; pure greys feel default. Our pages use slate neutrals for exactly this reason.

  4. Check the pairs

    Every text/background combination should pass 4.5:1. Check the button text too β€” white on a light brand colour is the most common failure.

Common mistakes

  • Pure black text on pure white. Maximum contrast, maximum eye strain. Very dark grey on off-white reads better for long text.
  • Too many colours. Five competing hues look like a warning sign. One brand colour + neutrals + one accent is the professional default.
  • Colour as the only signal. β€œRed means error” fails for colour-blind users and for anyone printing in greyscale β€” pair colour with text or an icon.
  • Forgetting the #. 6D28D9 without the hash is not a colour in CSS β€” and in some tools it's read as a number.
  • Trusting your screen. The same hex code looks different on a phone, a laptop and a projector. For brand work, check on the cheapest screen your audience uses.
  • Low-contrast placeholders. Light-grey placeholder text in inputs is often below 4.5:1 β€” and placeholders disappear when you type, so never put instructions only in one.

Try it: Color Picker

Open the Color Picker, click any pixel of a photo, and it hands you the hex code β€” then use this guide to read that code and build a palette around it.

Open the Color Picker β†’

Keep learning

Frequently asked questions

What is the difference between hex and RGB?

None in meaning β€” they are two notations for the same three numbers. #FF0000 and rgb(255, 0, 0) are the same red. Hex is shorter to write; rgb() is easier to read when a value is computed in code. Use whichever your tool expects.

How many colours can a hex code express?

16.7 million: 256 levels per channel, three channels. Six hex digits (24 bits) cover them all β€” that is why it is often called 24-bit or true colour.

What does #FFF mean? Is it the same as #FFFFFF?

Yes β€” when each pair of digits is identical, the 3-digit shorthand is allowed: #FFF is #FFFFFF (white), #09C is #0099CC. Four digits add alpha: #FFF8 is white at about 53% opacity.

How do I pick colours that go together?

Start from one hue and vary lightness and saturation, or use a colour wheel: analogous colours (neighbours on the wheel) feel calm, complementary colours (opposites) feel energetic. Then check every text/background pair for 4.5:1 contrast.

Why do colours look different on different screens?

Screens differ in brightness, colour gamut and calibration, and the same hex code is rendered through each screen's own physics. The hex code is exact; the light coming off the panel is not. For critical brand colours, check on several real devices.