Home / Blog / What Is a HEX Color Code? Complete Beginner Guide

What Is a HEX Color Code? Complete Beginner Guide

By Editorial Team | Nov 18, 2026

Learn how six characters describe millions of colors, pair by pair.

If you have ever copied a colour from a website or a brand guide, you have almost certainly copied a HEX code. It looks small and cryptic — six letters and numbers after a hash sign, such as #FF5733 — yet it tells a browser exactly which colour to show, and the same code produces the same colour every time. Web designers use it in CSS, and brand designers use it to keep logos consistent. Once you know how to read one, you can guess the colour before you see it.

What Is a HEX Colour Code?

HEX is short for hexadecimal, a base-16 counting system. Everyday counting uses ten digits, 0 to 9; hexadecimal needs sixteen, so after 9 it uses letters: A is 10, B is 11, C is 12, D is 13, E is 14, and F is 15.

A standard HEX code has six characters after a hash sign, describing a colour as red, green, and blue light. The first two characters set the red, the middle two the green, and the last two the blue. Each pair runs from 00 to FF, or 0 to 255. So #000000 appears black and #FFFFFF appears white.

Take #FF5733, a vivid orange: FF is maximum red, 57 is medium green, and 33 is a smaller blue. Red dominates, green softens it, and blue is kept low. Designers like HEX codes because they are short, exact, and easy to share — #5B4BFF, a bright brand purple, fits in one short string for CSS, messages, or a style guide.

How to Read a HEX Code, Pair by Pair

Split a HEX code into three pairs, read left to right as red, green, and blue. To turn a pair into an ordinary number, multiply the first character by 16 and add the second (A is 10, B is 11, F is 15). For #FF5733: Red: FF = 15 x 16 + 15 = 255; Green: 57 = 5 x 16 + 7 = 87; Blue: 33 = 3 x 16 + 3 = 51. So #FF5733 is rgb(255, 87, 51): strong red, some green, much less blue — a vivid orange. Now try #5B4BFF: Red: 5B = 5 x 16 + 11 = 91; Green: 4B = 4 x 16 + 11 = 75; Blue: FF = 15 x 16 + 15 = 255. That gives rgb(91, 75, 255) — a vivid purple-blue, with blue at its maximum. In HSL, the same colour is hsl(245, 100%, 65%), describing hue, saturation, and lightness instead.

A dark example: #12153A splits into 12, 15, and 3A — 18, 21, and 58 — so it is rgb(18, 21, 58), a very dark navy. If you would rather check a conversion than calculate it, use the HEX to RGB converter or the HEX to HSL converter.

Shorter and Longer HEX Codes

Three-digit shorthand writes a colour shorter when each pair is made of two identical characters. Expand it by doubling each character: #fff becomes #FFFFFF, white, and #000 becomes #000000, black. Less obviously, #5B4 expands to #55BB44 — a mid green, because the green pair is strongest.

Shorthand does not work for every colour: #FF5733 cannot be shortened, because its pairs are FF, 57, and 33, and only two have matching characters. Writing it as #F53 would give #FF5533, a different colour. Use shorthand only when doubling each character gives the six-digit code you started with.

An eight-digit HEX code adds a fourth pair for transparency, or alpha. The last two characters describe how see-through the colour is: FF means fully solid, 00 means fully transparent, and 80 means roughly half transparent. So #FF573380 is the same vivid orange as #FF5733, but at about half opacity. A four-digit code works the same way. Check that your tool supports eight-digit HEX first; older tools may ignore the last pair.

HEX vs RGB vs HSL in Practice

HEX, RGB, and HSL all describe the same colours, but they suit different jobs. HEX is the most compact — easy to copy, paste, and store in a style guide — making it a good default for CSS and brand colours.

RGB is the most direct description of how a screen makes a colour, listing red, green, and blue as ordinary numbers from 0 to 255, as in rgb(255, 87, 51) for #FF5733. To move between the two, use the colour code converter to change HEX to RGB, or the RGB to HEX converter for the reverse.

HSL is often the easiest format for adjusting a colour by feel, describing hue, saturation, and lightness. To make the same purple lighter, raise the lightness in HSL, then convert back to HEX for CSS. None is better in every case: choose HEX for short, shareable codes, RGB for clear channel values, and HSL for controlled adjustments.

How to Use HEX in CSS: Step by Step

  1. Pick the colour. Choose one with the online colour picker. Click the shade you want, then copy the HEX code it shows, keeping the hash sign.
  2. Decide where it will be used. Use color for text, background-color for a background, and border-color for a border. The property tells the browser which part to change.
  3. Add it to your CSS. Paste the code as the value, with a semicolon at the end: h1 { color: #5B4BFF; } .button { background-color: #FF5733; color: #FFFFFF; border: 2px solid #12153A; } Here, headings use #5B4BFF, buttons use #FF5733 with white text, and the border uses #12153A. White text on orange is an example only — always check contrast first.
  4. Save colours as variables. Store a colour once and reuse it, so changing it later means changing one line: :root { --brand: #5B4BFF; --accent: #FF5733; --dark: #12153A; } h1 { color: var(--brand); }
  5. Check the result and the contrast. Open the page and look at the colour at its real size, then check that text is easy to read against its background with the colour contrast checker.

Common Mistakes to Avoid

Leaving out the hash sign. In CSS, #FF5733 is a colour, but FF5733 on its own is not. Without the hash, the browser will not recognise the value and the style will be ignored.

Using the wrong length. A standard HEX code has three, four, six, or eight characters after the hash. Five or seven characters is not valid, and neither is a letter outside A to F, such as G or Z. If a colour is not showing, count the characters first.

Assuming upper and lower case change the colour. They do not: #ff5733 and #FF5733 are the same colour. Upper case is often used because it is easier to read, but either works — pick one and use it consistently.

Copying a colour from a screenshot. Compression, screen settings, and resizing can shift the exact values, so the result may be close but not identical. Where possible, copy the code from the original design file, brand guide, or stylesheet instead.

Frequently Asked Questions

What does HEX stand for? HEX is short for hexadecimal, a base-16 system using the digits 0 to 9 and the letters A to F, where A is 10 and F is 15. A HEX code uses it to write red, green, and blue values in a short string.

Is #FF5733 the same in every browser? Yes. #FF5733 always means red 255, green 87, and blue 51, although screens can show it slightly differently because of their settings.

Can I use a HEX code without a hash sign? In CSS, no. The hash is part of the value and tells the browser the characters that follow are a HEX code. Some tools add it for you, but in CSS always write it yourself.

What is the difference between #fff and #FFFFFF? None. #fff is shorthand for #FFFFFF, and both mean white. Shorthand doubles each character, so #000 expands to #000000 and #5B4 to #55BB44.

Should I use HEX, RGB, or HSL? Use whichever fits the job. HEX is best for short codes in CSS and style guides, RGB when you need the separate channel values, and HSL when you want to adjust lightness, vividness, or muting. You can convert between them without changing the colour.

Once you can read a HEX code pair by pair, it stops looking like a random string and starts working like a short set of instructions: how much red, green, and blue, and, in eight-digit form, how see-through it should be. Start with a colour you like, copy its code, and try it in CSS. Next, pick a colour with the online colour picker, convert it with the HEX to RGB converter, and check its contrast before using it as text.

More articles

Dec 2, 2026

Colour Blindness and Accessible Design

Read More
Dec 2, 2026

How to Create CSS Gradients: A Practical Guide

Read More
Dec 2, 2026

Colour Psychology in Web Design: What Different Colours Mean

Read More