HEX vs RGB vs HSL: Understanding Color Formats

Featured graphic for “HEX vs RGB vs HSL” showing color swatches and HEX codes

Open any design tool or stylesheet and you will see colors written in several ways: #6C5CE7, rgb(108, 92, 231) or hsl(247, 75%, 63%). All three describe exactly the same violet. This guide explains what each format means, how they relate, and which one to use in different situations.

How Screens Create Color

Every pixel on your screen mixes three lights: red, green and blue. Each channel can be set from 0 (off) to 255 (full brightness). Mixing them produces about 16.7 million combinations (256 × 256 × 256). HEX and RGB are two ways of writing these three numbers. HSL describes the same colors in a way that is closer to how people think about color.

RGB: Red, Green, Blue

RGB writes each channel as a decimal number:

  • #FF0000 rgb(255, 0, 0) — pure red
  • #000000 rgb(0, 0, 0) — black (all lights off)
  • #FFFFFF rgb(255, 255, 255) — white (all lights full)
  • #6C5CE7 rgb(108, 92, 231) — a strong violet

RGB is useful when you need transparency, because rgba(108, 92, 231, 0.5) adds an alpha value from 0 to 1. Modern CSS also accepts rgb(108 92 231 / 50%).

HEX: The Same Numbers in Base 16

A HEX code is RGB written in hexadecimal. Each channel uses two characters from 0–9 and A–F, so 00 is 0 and FF is 255.

Take #6C5CE7:

  • 6C = 6 × 16 + 12 = 108 (red)
  • 5C = 5 × 16 + 12 = 92 (green)
  • E7 = 14 × 16 + 7 = 231 (blue)

HEX codes are compact and easy to copy, which is why design tools, brand guides and most CSS use them. There is also a three-digit shorthand: #FFF means #FFFFFF. An eight-digit form such as #6C5CE780 adds transparency.

HSL: Hue, Saturation, Lightness

HSL describes color using three intuitive properties:

  • Hue (0–360°) — the position on the color wheel. 0° is red, 120° is green, 240° is blue.
  • Saturation (0–100%) — how vivid the color is. 0% is grey.
  • Lightness (0–100%) — how light or dark. 0% is black, 100% is white, 50% is the pure hue.

The violet above is hsl(247, 75%, 63%). Want a darker version for a button hover? Lower the lightness: #4B38E0 hsl(247, 75%, 55%). Want a soft background tint? Raise it: #E4E1FA hsl(247, 75%, 93%). The hue stays the same, so the colors look related.

Side-by-Side Comparison

FormatExampleStrengthsWeaknesses
HEX#6C5CE7Short, universal, easy to copyHard to adjust by eye
RGBrgb(108, 92, 231)Clear channel values, easy transparencyLonger to write
HSLhsl(247, 75%, 63%)Easy to create tints, shades and variationsLess common in design hand-offs

Which Format Should You Use?

  • Brand colors and design hand-off: HEX. It is what designers and clients expect.
  • Transparent overlays and shadows: RGB with alpha, for example rgba(17, 24, 39, 0.5).
  • Building a color system: HSL. Keep the hue fixed and step lightness to create a scale.

All three formats work in every modern browser, and you can mix them in one stylesheet.

Converting Between Formats

Preparing a file for print? Use the RGB to CMYK Converter. You can convert by hand using the math above, but it is faster to paste any value into our Color Converter. To explore visually and copy all three formats at once, use the Color Picker.

RGBA and HSLA: Adding Transparency

Each of the three main formats can describe transparency through a fourth value called alpha. Alpha ranges from 0 (fully transparent) to 1 (fully opaque) in RGB and HSL, or from 00 to FF in HEX.

  • RGBA: rgba(37, 99, 235, 0.5) — blue at 50% opacity.
  • HSLA: hsla(221, 83%, 53%, 0.5) — the same color and opacity in HSL.
  • 8-digit HEX: #2563EB80 — the last pair, 80, equals about 50% opacity.

Modern CSS also allows a simpler space-separated syntax with a slash for alpha, such as rgb(37 99 235 / 50%) and hsl(221 83% 53% / 50%). The older comma syntax still works in every browser, so you can use whichever style your team prefers.

Common alpha values in HEX

  • 100% = FF
  • 90% = E6
  • 80% = CC
  • 75% = BF
  • 60% = 99
  • 50% = 80
  • 40% = 66
  • 25% = 40
  • 10% = 1A
  • 0% = 00

Transparency is useful for overlays on images, soft shadows, hover effects and glass-style interface panels.

Why HSL Is Easier for Humans

RGB and HEX describe colors the way screens produce them: by mixing amounts of red, green and blue light. That is precise, but it is not how people naturally think about color. If someone asks you to make a blue “a bit lighter”, it is hard to know which RGB numbers to change.

HSL describes color in human terms:

  • Hue answers “what color is it?” as an angle on the color wheel from 0 to 360.
  • Saturation answers “how vivid is it?” from 0% (gray) to 100% (full color).
  • Lightness answers “how light or dark is it?” from 0% (black) to 100% (white), with 50% being the pure color.

With HSL, making a color lighter means increasing one number. Creating a matching set of shades means keeping hue and saturation fixed and stepping through lightness values. Finding a complementary color means adding 180 to the hue. These tasks are difficult in RGB but simple in HSL.

Example: a shade scale with HSL

--blue-100: hsl(221, 83%, 93%);
--blue-300: hsl(221, 83%, 75%);
--blue-500: hsl(221, 83%, 53%);
--blue-700: hsl(221, 83%, 38%);
--blue-900: hsl(221, 83%, 22%);

Every shade clearly belongs to the same family because only lightness changes.

The Limits of HSL

HSL is convenient, but it has an important weakness: its lightness value does not match how bright colors actually look to our eyes. A yellow at hsl(60, 100%, 50%) and a blue at hsl(240, 100%, 50%) have the same HSL lightness, yet the yellow looks far brighter than the blue. This happens because human vision is much more sensitive to green and yellow light than to blue.

This matters when you create palettes with consistent brightness across different hues, or when you need predictable text contrast. Two colors with the same HSL lightness can have very different contrast ratios against white. Always check contrast with a dedicated tool rather than relying on HSL lightness alone.

Newer CSS Color Formats

CSS has introduced newer color spaces designed to fix the limitations of RGB and HSL. You do not need them for most websites today, but it is helpful to know they exist.

HWB

hwb(221 10% 8%) describes a hue plus amounts of whiteness and blackness. It is intuitive for mixing tints and shades, similar to mixing paint.

LAB and LCH

These formats are based on how humans perceive color. LCH uses lightness, chroma (colorfulness) and hue. Because its lightness is perceptual, two colors with the same L value look roughly equally bright.

OKLCH

oklch(62% 0.19 260) is an improved version of LCH that gives more even, predictable results. It is becoming popular for design systems because it makes it easy to create palettes with consistent brightness and to generate smooth gradients without muddy middles. OKLCH can also describe colors outside the standard sRGB range for wide-gamut displays.

Support for these formats is good in current browsers. If you use them, include a HEX or RGB fallback for older browsers.

Practical Use Cases for Each Format

When HEX is the best choice

  • Copying brand colors from a style guide or logo file.
  • Writing short, fixed color values in CSS.
  • Entering colors into WordPress, page builders, email tools and social media apps, which usually accept HEX.
  • Sharing colors with clients, because HEX codes are easy to send and compare.

When RGB is the best choice

  • Working with JavaScript, canvas drawing or image processing, where colors are handled as numbers.
  • Calculating color math, such as blending two colors or measuring luminance.
  • Using software or hardware that only accepts RGB, such as some video and lighting tools.

When HSL is the best choice

  • Creating hover and active states by adjusting lightness.
  • Generating shade and tint scales for a design system.
  • Building color harmonies by rotating the hue.
  • Theming, such as switching an entire interface to a new hue by changing one variable.

Theming With HSL Variables

A powerful technique is to store hue, saturation and lightness as separate CSS variables. This lets you change an entire color theme by editing a single number:

:root {
  --brand-h: 221;
  --brand-s: 83%;
}
.button {
  background: hsl(var(--brand-h), var(--brand-s), 53%);
}
.button:hover {
  background: hsl(var(--brand-h), var(--brand-s), 45%);
}
.badge {
  background: hsl(var(--brand-h), var(--brand-s), 94%);
  color: hsl(var(--brand-h), var(--brand-s), 30%);
}

Changing --brand-h from 221 to 160 instantly turns the whole interface from blue to green, while all the light and dark variations stay balanced. This is ideal for white-label products, multi-brand websites and user-selectable themes.

Precision and Rounding

HEX and RGB both store exactly 256 values per channel, so converting between them is always exact. HSL, however, uses degrees and percentages, and converting from HSL to RGB often produces decimal values that must be rounded to whole numbers. Converting back again may give a slightly different HSL value.

For example, a color picked as hsl(200, 70%, 45%) might become rgb(34, 139, 196), which converts back to roughly hsl(201, 70%, 45%). The difference is invisible to the eye, but it explains why tools sometimes show small changes after conversion. For brand colors, store the original HEX value as the official reference to avoid drift over time.

Color Formats Beyond the Screen

HEX, RGB and HSL are all designed for digital screens. Other industries use different systems:

  • CMYK describes ink percentages for printing.
  • Pantone is a matching system of numbered spot colors used for consistent printing of logos and packaging.
  • RAL is a standard used for paints, coatings and industrial products, especially in Europe.

When a brand will appear both online and in print, the style guide should list every color in HEX, RGB, CMYK and, if needed, Pantone. Converted values are close approximations, so print proofs are still important.

Quick Comparison Summary

  • HEX: short, popular, easy to copy; hard to adjust by eye.
  • RGB: numeric and precise; useful in code and calculations.
  • HSL: intuitive and great for variations; lightness is not perceptually accurate.
  • OKLCH: modern and perceptually even; best for advanced design systems.

All of these formats can describe the same on-screen colors. The right choice depends on the task in front of you. Many professionals use all of them: HEX for brand references, HSL or OKLCH for building scales, and RGB when writing scripts.

Common Mistakes When Working With Color Formats

  1. Mixing up HSL and HSV. Design apps often use HSV (also called HSB), while CSS uses HSL. The numbers look similar but mean different things. A color at 100% value in HSV is not the same as 100% lightness in HSL, which is always white. Convert carefully when copying values from a design tool.
  2. Forgetting units. In HSL, saturation and lightness need percent signs in the traditional syntax. Writing hsl(220, 80, 50) without percentages is invalid in many browsers.
  3. Using 0–100 for RGB. RGB channels run from 0 to 255 in standard notation. Using 100 as the maximum will produce a much darker color than intended. Percentages are allowed, but they must include the percent sign.
  4. Dropping the alpha by accident. Converting an 8-digit HEX code to a 6-digit code removes transparency, which can make overlays suddenly solid.
  5. Assuming equal lightness means equal contrast. As explained above, HSL lightness does not predict readability. Always test text contrast.
  6. Inconsistent formats in one project. Mixing HEX, RGB and HSL randomly makes code harder to read and maintain. Choose a primary format for each purpose and stick to it.

Practice: Convert One Color Into Every Format

Try this simple exercise to understand how the formats relate. Take the color #10B981, a fresh emerald green.

  • HEX: #10B981
  • RGB: rgb(16, 185, 129) — 10 hex is 16, B9 is 185 and 81 is 129.
  • HSL: approximately hsl(160, 84%, 39%).
  • With 50% opacity: #10B98180, rgba(16, 185, 129, 0.5) or hsla(160, 84%, 39%, 0.5).

Now increase the HSL lightness to 90% to create a light background tint, and reduce it to 25% to create a dark text color. You have just built a small, matching palette from one color in three formats, which is exactly the workflow designers use every day.

How Browsers Handle the Different Formats

When a browser reads your CSS, it converts every color into the same internal representation before drawing it on screen. That means #2563EB, rgb(37, 99, 235) and hsl(221, 83%, 53%) all end up as identical pixels. There is no performance difference between formats, and none of them loads faster than the others.

Because of this, the choice of format is purely about readability and convenience for the people writing and maintaining the code. If you open your browser’s developer tools and click a color swatch, you can usually cycle between HEX, RGB and HSL with a single click, which is a quick way to convert colors while you work. Some browsers also show newer formats such as OKLCH in the same picker.

Understanding that all formats describe the same colors removes much of the confusion beginners feel. Learn to read each one, use the format that makes your current task easiest, and convert freely whenever another tool or teammate needs a different notation.

Which Format Should Beginners Learn First?

If you are new to web design, start with HEX because you will see it everywhere: in WordPress, page builders, Canva, Figma and brand guides. Next, learn HSL, because it makes adjusting colors intuitive and helps you understand color theory. Finally, learn RGB when you start writing JavaScript or working with images. Once these three are comfortable, exploring OKLCH will feel like a natural next step.

Frequently Asked Questions

Are HEX and RGB the same color?

Yes. A HEX code is simply RGB written in base 16. #FF0000 and rgb(255, 0, 0) are identical.

Is HEX case-sensitive?

No. #6c5ce7 and #6C5CE7 are the same color.

Why does converting HSL to HEX sometimes change the value slightly?

HSL values are usually rounded to whole numbers, so converting back can shift a channel by one step. The visual difference is not noticeable.

Can I use HSL in CSS?

Yes. hsl() and hsla() are supported in all modern browsers.

Written by the Mage Color Picker Team

We build free online color tools and write practical guides on color theory, color codes and accessible design for designers and developers.

Scroll to Top