EthicalFusion
Data & Developers

HEX, RGB and HSL Color Codes Explained (With Conversions)

#7C5CFF, rgb(124, 92, 255) and hsl(252, 100%, 68%) are one colour. Learn each format, convert by hand both ways, add transparency and pick the right one.

By the EthicalFusion team Published Updated 7 min read

#7C5CFF, rgb(124, 92, 255) and hsl(252, 100%, 68%) are the same purple written three ways. HEX and RGB both give the amounts of red, green and blue light (HEX in base 16, RGB in ordinary numbers from 0 to 255), while HSL describes the colour as a hue on the colour wheel plus saturation and lightness percentages.

The site's colour converter turns a HEX or RGB value into all three formats at once. This guide explains what each format means, works the conversions by hand in both directions, covers transparency and CSS colour names, and explains how the converter rounds so you know why numbers can differ by one.

The formats at a glance

FormatExampleRangeBest for
HEX#7C5CFF00 to FF per channelSharing, brand guides, design hand-off
RGBrgb(124, 92, 255)0 to 255 per channelCode, transparency, canvas and image work
HSLhsl(252, 100%, 68%)Hue 0–360°, S and L 0–100%Quick manual tweaks
NamedtomatoAbout 150 namesPrototypes and quick tests

With 256 possible values for each of three channels, HEX and RGB can each describe 256 × 256 × 256 = 16,777,216 colours.

HEX codes

A hex code is a # followed by three pairs of base-16 digits: red, green, blue. Base 16 uses 0–9 and then A–F for 10 to 15, so each pair runs from 00 (0) to FF (255). Letters can be upper or lower case; #7c5cff and #7C5CFF are the same colour.

A three-digit code is shorthand that doubles each digit: #FFF is #FFFFFF (white), #000 is #000000 (black), and #ABC is #AABBCC. Only colours whose pairs repeat can be shortened, so #7C5CFF has no short form.

Converting HEX to RGB and back

HEX to RGB. Take each pair, multiply the first digit by 16 and add the second. For #7C5CFF:

  • 7C = 7 × 16 + 12 = 124
  • 5C = 5 × 16 + 12 = 92
  • FF = 15 × 16 + 15 = 255

So #7C5CFF is rgb(124, 92, 255).

RGB to HEX. Divide each value by 16: the whole-number answer is the first digit and the remainder is the second. For rgb(232, 93, 4), a warm orange:

  • 232 ÷ 16 = 14 remainder 8, giving E8
  • 93 ÷ 16 = 5 remainder 13, giving 5D
  • 4 ÷ 16 = 0 remainder 4, giving 04 (always keep two digits)

So rgb(232, 93, 4) is #E85D04. Check it backwards: E8 = 14 × 16 + 8 = 232. HEX and RGB convert exactly, with no rounding, because they hold the same three numbers.

RGB: how screens make colour

Each pixel on a screen has red, green and blue parts that light up by different amounts. rgb(255, 0, 0) is full red, rgb(255, 255, 0) is red plus green light, which the eye sees as yellow, and rgb(255, 255, 255) is all three at full strength: white. Equal values always give a grey, such as rgb(128, 128, 128).

That is why RGB is not intuitive for editing. To make a colour "a bit lighter" you have to raise all three numbers by different amounts, and there is no single value for "how blue" it is. HSL solves that.

HSL: hue, saturation and lightness

  • Hue is the position on the colour wheel in degrees: 0° red, 60° yellow, 120° green, 180° cyan, 240° blue, 300° magenta.
  • Saturation runs from 0% (grey) to 100% (full colour).
  • Lightness runs from 0% (black) through 50% (the pure colour) to 100% (white).

RGB to HSL, worked for rgb(124, 92, 255).

  1. Divide by 255: R = 0.486, G = 0.361, B = 1.000.
  2. Find the largest (1.000, blue) and smallest (0.361) values. Their difference is 0.639.
  3. Lightness = (largest + smallest) ÷ 2 = 1.361 ÷ 2 = 0.680, so 68%.
  4. Saturation = difference ÷ (1 − |2 × lightness − 1|) = 0.639 ÷ (1 − 0.361) = 1, so 100%.
  5. Hue depends on which channel is largest. Here it is blue, so hue = 60 × ((R − G) ÷ difference + 4) = 60 × (0.125 ÷ 0.639 + 4) = 60 × 4.196 = 251.8, so 252°. (If red is largest, use 60 × ((G − B) ÷ difference), adding 360 if negative; if green, use 60 × ((B − R) ÷ difference + 2).)

Result: hsl(252, 100%, 68%), matching the converter.

HSL to RGB, worked for hsl(30, 100%, 60%).

  1. Chroma C = (1 − |2 × 0.6 − 1|) × 1.00 = 0.8.
  2. X = C × (1 − |(30 ÷ 60) mod 2 − 1|) = 0.8 × (1 − 0.5) = 0.4.
  3. m = lightness − C ÷ 2 = 0.6 − 0.4 = 0.2.
  4. The hue sector decides the order. From 0° to 60° it is (C, X, 0); from 60° (X, C, 0); from 120° (0, C, X); from 180° (0, X, C); from 240° (X, 0, C); from 300° (C, 0, X). For 30° that gives (0.8, 0.4, 0).
  5. Add m and multiply by 255: (1.0, 0.6, 0.2) × 255 = (255, 153, 51), which is #FF9933, a saffron.

HSL is handy for tweaks: lower the lightness for a darker version, change only the hue for a matching colour. But its lightness does not match how bright colours look, so yellow and blue at the same lightness look nothing alike. The guide to tints, shades and colour scales covers this, and the newer OKLCH format that fixes it.

Transparency: alpha values

An alpha value sets opacity, from fully transparent to fully solid. The same 50% transparent purple can be written as:

  • rgba(124, 92, 255, 0.5), the older comma style
  • rgb(124 92 255 / 50%), the modern CSS style; hsl() takes "/ alpha" the same way
  • #7C5CFF80, an 8-digit hex code, where the last pair is the alpha

To get the hex alpha pair, multiply the opacity by 255 and convert: 0.5 × 255 = 127.5, rounded to 128, which is 80. MDN lists the 4- and 8-digit hex forms as standard CSS, and current browsers support them.

OpacityHex pairOpacityHex pair
100%FF50%80
90%E625%40
80%CC20%33
75%BF10%1A

For accessibility checks, remember that a semi-transparent colour's real appearance depends on what is behind it, so test the solid colour it produces on your actual background.

CSS named colours

CSS also accepts colour names. MDN describes 16 basic names, such as red, navy and teal, plus about 150 more, from aliceblue to yellowgreen. A few examples: tomato is #FF6347, dodgerblue is #1E90FF, and rebeccapurple, added in CSS Color Level 4, is #663399. The keyword transparent means fully transparent black.

Names are fine for prototypes, but the names do not follow a system. darkgray (#A9A9A9) is actually lighter than gray (#808080), and gray and grey are both accepted. For a real design, use exact codes.

How the site's colour converter works

Paste a value and press Convert. The tool accepts a 3- or 6-digit hex code, with or without the #, or any text containing three numbers, such as rgb(124, 92, 255) or just 124 92 255. It returns lowercase HEX, rgb() and hsl() lines. Things to know:

  • Rounding. Hue is rounded to the nearest degree, and saturation and lightness to whole percentages. That is enough for everyday use, but converting back can be one step off. The tool's own default purple, #6D48F5, shows as hsl(253, 90%, 62%), and that HSL value converts back to #6D47F5. #7F7F7F and #808080 both show as hsl(0, 0%, 50%).
  • No HSL input. If you paste hsl(252, 100%, 68%), the tool reads the three numbers as red, green and blue and returns #fc6444, an orange-red. Convert HSL by hand using the steps above.
  • No alpha. The fourth number in rgba() is dropped, and an 8-digit hex code is misread (#7C5CFF80 came out as #070550), so strip the alpha before converting.
  • No range check and no names. Values above 255 are not rejected (rgb(300, 0, 0) gives an invalid code), and colour names give an error.

The contrast checker and shades and tints generator also take hex only, so the converter is the usual first step when you start from an RGB value.

Which format to use when

  • HEX to store and share colours: brand guides, design files, messages to a developer.
  • RGB when a tool or script needs numbers, such as image editing or JavaScript canvas code, and for transparency in older code.
  • HSL to nudge a colour by hand: lighter, darker or a neighbouring hue.
  • OKLCH, written oklch() in CSS, to build even colour scales.
  • Names only for quick tests and examples.

All of these produce the same pixels on screen; the choice is about which is easiest for the job. To build a whole palette from one code, see the guide to creating a brand colour palette.

Frequently asked questions

Is a hex code the same as RGB?

Yes. Both store the same three channel values; hex writes them in base 16. That is why HEX to RGB conversion is exact in both directions.

Why do two tools give slightly different HSL values for the same colour?

Rounding. HSL is calculated with decimals, and tools round hue, saturation and lightness differently, so one may show 252° and another 251.8°. The HEX and RGB values stay identical.

What do #000 and #FFF mean?

They are shorthand for #000000 (black) and #FFFFFF (white). Each digit of a 3-digit code is doubled.

Are hex colour codes case-sensitive?

No. #ff9933 and #FF9933 are the same colour. Pick one style and use it consistently in your files.

How do I convert HEX to CMYK for printing?

There is no single exact answer, because CMYK depends on the printer, paper and ink. The site's converter does not do CMYK. Give your printer the hex code and ask for a proof, especially for bright oranges, greens and blues, which often print duller than they look on screen.

Sources: MDN Web Docs, <hex-color>, <named-color>, rgb() and hsl() (checked October 2026); W3C, CSS Color Module Level 4; outputs from the site's colour converter, October 2026.

  • #hex colour codes
  • #RGB
  • #HSL
  • #CSS colours
  • #colour conversion

Tools used in this guide

Free, no sign-up, and they run in your browser.

About EthicalFusion

EthicalFusion offers 321 free online tools for money, documents, images, writing and code. This guide was written by the team that builds them. Calculators give estimates, so confirm important figures with your bank, CA or doctor.

About us Suggest a correction

Keep reading

All articles