Skip to main content

HEX vs RGB vs HSL: Colour Codes Explained

HEX, RGB, HSL, and CMYK describe the same color in different ways. Learn what each format means, when to use it, and how to convert between them.

CompressMyPic Editorial Team · Published Nov 17, 2026 · 11 min read

HEX vs RGB vs HSL: Colour Codes Explained

Every color on your screen has several names. The same blue can be #2563EB, rgb(37, 99, 235), or hsl(221, 83%, 53%), and all three describe exactly the same pixels.

That overlap confuses beginners. If the codes are interchangeable, why do four formats exist, and which one should you actually use?

This article explains HEX, RGB, HSL, and CMYK side by side: what each one means, where it is used, and how to choose the right format for your work.

Why Do Multiple Color Formats Exist?

Different jobs need different descriptions of color. A web developer wants a short code to paste into CSS, while a designer wants to describe a color as a hue with a lightness.

HEX grew out of how computers store color: three bytes, one each for red, green, and blue, written as six hexadecimal digits. It is compact and copy-friendly.

RGB grew out of how screens produce color: three lamps of red, green, and blue light, each with an intensity from 0 to 255. It is direct and readable.

HSL grew out of how humans think about color: first the hue, then how rich it is, then how light or dark. It matches the sliders in most design tools.

HEX Explained

A HEX code starts with a hash sign followed by six hexadecimal digits, such as #2563EB. The first two digits are red, the next two are green, and the last two are blue.

Each pair ranges from 00 to FF in hexadecimal, which equals 0 to 255 in decimal. So #FF0000 is pure red, #00FF00 is pure green, and #000000 is black.

HEX is the default format for CSS and for most design tools. It is short, it pastes cleanly into a stylesheet, and it is easy to copy from a color picker.

Some codes can be shortened: #336699 becomes #369, because each pair has two identical digits. The short form means the same color, but most tools show the full six digits.

RGB Explained

RGB writes the same three values as decimal numbers, such as rgb(37, 99, 235). Each number runs from 0, meaning none of that light, to 255, meaning full strength.

RGB is the most literal description of what a screen does. It says exactly how much red, green, and blue light to mix, which is why image editors and cameras use it internally.

RGB also supports transparency through RGBA, which adds a fourth number for opacity. rgba(37, 99, 235, 0.5) is the same blue at half opacity.

Most office software and document tools ask for RGB values. When a brand guide lists a color as three numbers, it is usually giving you the RGB form.

HSL Explained

HSL describes color with three different ideas: hue, saturation, and lightness. A typical value looks like hsl(221, 83%, 53%).

Hue is an angle on a color wheel, from 0 to 360 degrees. Red sits near 0, green near 120, blue near 240, and the wheel wraps back to red at 360.

Saturation is a percentage: 0 percent is gray, 100 percent is the most vivid version of the hue. Lightness is also a percentage: 0 is black, 50 is the pure hue, and 100 is white.

HSL shines when you need variations of one color. To make a lighter button hover state, keep the hue and saturation and raise the lightness. That is one small edit, not a new color to invent.

CMYK Explained

CMYK describes color as ink on paper: cyan, magenta, yellow, and black, each as a percentage. A typical value is cmyk(84%, 58%, 0%, 8%).

Printers mix inks subtractively, which is the opposite of screens. Where a screen adds light to reach white, a printer starts with white paper and adds ink to darken it.

That difference means some screen colors cannot be printed exactly. Very bright blues and greens often fall outside the range of inks, so the printed result looks duller.

The CMYK values shown by the image color picker are an approximation computed from the screen color. Treat them as a starting point for a print conversation, not as a guaranteed match.

HEX vs RGB: Which Should You Use?

HEX and RGB describe the same color with the same three numbers, only written differently. #2563EB and rgb(37, 99, 235) are the same blue in two notations.

Choose HEX for CSS and for sharing. It is shorter, it is the convention in stylesheets, and it copies cleanly into design tools and chat messages.

Choose RGB when a tool asks for three numbers, or when you need transparency. RGBA is the standard way to write a semi-transparent color in CSS.

Converting between them is simple arithmetic. Each HEX pair converts to one decimal number, so #25 becomes 37, #63 becomes 99, and #EB becomes 235.

HSL vs HEX and RGB: When HSL Wins

HSL wins when you are designing a color system rather than naming one color. A palette built in HSL stays coherent because the hue stays fixed while lightness varies.

Consider a button with three states: normal, hover, and disabled. In HSL you keep hue 221 and saturation 83 percent, then set lightness to 53, 45, and 70 percent.

Doing the same in HEX means inventing three unrelated codes. They might look fine, but nothing in the codes tells you they belong together.

Many design tools now accept HSL input directly, and CSS supports it natively. If your workflow involves shades and tints, HSL is the format that keeps them organized.

Converting Between Formats

You rarely need to convert by hand, because the color picker shows all formats at once. Still, understanding the conversion helps you trust the numbers.

HEX to RGB is a base conversion: each pair of hex digits becomes a decimal from 0 to 255. FF is 255, 80 is 128, and 00 is 0.

RGB to HSL is a formula, not a lookup. It finds the largest and smallest of the three values, derives lightness from their average, and computes hue from which channel is largest.

RGB to CMYK is also a formula. It inverts the RGB values, finds the smallest as the black key, then scales the rest. That is why the CMYK result is an approximation, not a measurement.

Which Format Should You Use on the Web?

For most websites, HEX is the safe default. It is short, universally supported, and every developer recognizes it at a glance.

Use RGBA when you need transparency. A semi-transparent overlay or a soft shadow is simplest as rgba with an opacity value below 1.

Use HSL when you build a theme with systematic shades. Design systems that generate light and dark variants from one hue are far easier to maintain in HSL.

Modern CSS also supports newer formats such as OKLCH, which describe color more evenly. They are promising, but HEX, RGB, and HSL remain the formats every tool and browser supports today.

Which Format Should You Use for Print?

For print, CMYK is the working language. Printers think in ink percentages, and a file prepared in CMYK avoids surprises at the press.

Start from the screen color, note the CMYK approximation from the picker, and then confirm with a printed proof. The proof is the only true test.

Never send a print job with only a HEX code and no CMYK discussion. The printer will convert it, but the conversion may choose ink values you would not have chosen.

For brand work, ask the printer for their color profile. A profile maps screen colors to inks for a specific press and paper, and it beats any generic formula.

Which Format Should You Use in Design Tools?

Figma, Photoshop, and Canva accept HEX pasted into their color fields, so HEX is the fastest way to move a picked color into a design.

When you adjust a color inside the tool, you will usually drag HSL-style sliders for hue, saturation, and lightness. The tool shows HEX, but you edit in HSL terms.

Brand guides often list all three: HEX for developers, RGB for documents, and CMYK for print. That is good practice, because each audience uses a different format.

If you extract a palette with the image color palette extractor, the export includes HEX, RGB, and HSL for every swatch, so you never have to convert anything yourself.

Common Mistakes with Color Formats

The most common mistake is assuming HEX and RGB are different colors. They are two spellings of the same value, so #2563EB and rgb(37, 99, 235) will always match.

Another mistake is treating a CMYK approximation as exact. The screen-to-print conversion is a formula, and the real printed color depends on the press, the ink, and the paper.

People also forget that lightness is not brightness. In HSL, raising lightness toward 100 percent washes the color toward white, while lowering it toward 0 pushes it toward black.

Finally, do not compare colors across different screens by eye alone. Two monitors can show the same HEX code differently, so trust the numbers when exactness matters.

Reading a Color Picker Output

When you sample a pixel, the picker shows every format at once. The HEX code is the one to copy for web work, and the RGB numbers are the ones to copy for documents.

The HSL values tell you where the color sits on the wheel and how vivid it is. A hue near 0 or 360 is red, near 120 is green, and near 240 is blue.

The CMYK percentages tell you how much ink the color would need. A color with high cyan and magenta and no yellow is a blue, while high yellow with some magenta is an orange.

Learning to read all four at a glance takes practice, but it pays off. You will be able to look at a code and picture the color before you ever paste it anywhere.

Building a Palette Across Formats

A good palette keeps one format as its source of truth and derives the rest. Most teams keep HEX as the source, since it is the format developers paste into code.

From the HEX base, generate lighter and darker variants in HSL by changing only the lightness. That keeps the hue family intact and the palette coherent.

Record the RGB values for documents and the CMYK approximations for print. A brand guide with all four formats serves every team without anyone converting on the fly.

Export your picked colors as CSS variables from the picker, then document the variants beside them. The stylesheet becomes the single reference everyone trusts.

HSL and Accessibility: Contrast by Lightness

Accessibility rules care about contrast, and HSL makes contrast easy to reason about. Two colors with lightness values far apart will usually pass a contrast check, while two with similar lightness will fail it.

Consider dark text on a light background. If the text has a lightness near 15 percent and the background sits near 95 percent, the gap is large and the text will be easy to read for almost everyone.

The same logic applies in reverse for dark mode. Light text at 90 percent lightness on a dark background at 10 percent gives the same large gap, and the same comfortable reading experience.

HSL also helps you fix a failing combination without changing its character. If a colored button fails a contrast check, lower its lightness by ten points and test again, keeping the hue and saturation untouched.

This is far easier than guessing a new HEX code. In HEX, a darker version of a color is a new set of digits with no visible relationship to the original, so each attempt is a fresh guess.

When you audit a design, convert its key colors to HSL and sort them by lightness. The sorted list shows at a glance whether your text, background, and accent colors have enough separation to be readable.

Remember that hue and saturation barely affect contrast on their own. A vivid red and a vivid green can have nearly identical lightness, which is why color-blind users struggle with red-green pairs even when the hues are far apart.

Quick Reference: Format Cheat Sheet

HEX is six digits after a hash, such as #2563EB. Use it in CSS, in design tools, and whenever you share a color in writing.

RGB is three numbers from 0 to 255, such as rgb(37, 99, 235). Use it in documents, in office software, and when you need transparency through RGBA.

HSL is a hue angle plus saturation and lightness percentages, such as hsl(221, 83%, 53%). Use it when building shades, tints, and theme variations.

CMYK is four ink percentages for print. Use it as a starting approximation for printed work, and always confirm with a proof. For the hands-on side, see the Image Color Picker: Complete Guide and the practical steps in How to Pick a Color from an Image.

Frequently asked questions

Is HEX or RGB better for website colors?

Neither is better in terms of the color itself, since they describe the same value. HEX is shorter and is the convention in stylesheets, so most developers prefer it. RGB is better when you need transparency, because RGBA adds an opacity value that HEX cannot express as simply.

Why does my brand color look different in print than on screen?

Screens create color with light and printers create it with ink, and the two systems cover different ranges. Bright screen blues and greens often fall outside what inks can reproduce. The CMYK value from a picker is an approximation, so always check a printed proof before a large run.

Can I convert a HEX code to HSL without a tool?

Yes, but it takes two steps: convert HEX to RGB first, then apply the RGB-to-HSL formula. The picker does both steps instantly and shows every format at once. For one-off conversions, any online converter or the picker itself is faster than doing the math by hand.

What does the hue number in HSL actually mean?

Hue is an angle from 0 to 360 degrees on the color wheel. Red is near 0, yellow near 60, green near 120, cyan near 180, blue near 240, and magenta near 300. Two colors with hues 30 degrees apart look related, while hues 180 degrees apart look complementary.

Do I need CMYK values for a website or social media graphic?

No. Websites, apps, and social graphics are all screen media, so HEX, RGB, or HSL is enough. CMYK only matters when ink touches paper. Keep the CMYK approximation on file in case the same brand color is ever printed.

Why do some HEX codes have only three digits?

A three-digit HEX code is a shorthand for a six-digit code where each pair has two identical digits. #369 means #336699, because 3 doubles to 33, 6 to 66, and 9 to 99. Not every six-digit code can be shortened, only those with matching pairs.

Related guides

Developer Tools

How to Extract a Colour Palette

Extract a colour palette from any photo in five steps: upload, pick 3–12 swatches, read the percentages, and copy CSS or JSON — free, in your browser.

Nov 17, 2026 · 10 min readRead the guide →

Share this guide

← Back to the blog