SmartToolsToday
๐Ÿ“–
ColorCSSDesign

Understanding Color Formats: HEX, RGB, and HSL Explained

HEX, RGB, and HSL all describe the same colors in different ways. Learn when to use each format and how to convert between them effortlessly.

ST
SmartToolsTodayยทJune 16, 2026ยท6 min read
Ad ยท 728ร—90 Leaderboard

Why Are There Multiple Color Formats?

Every color on a screen is produced by mixing red, green, and blue light at different intensities. The underlying data is always the same three numbers โ€” but the way those numbers are written varies depending on the context, the tool, and what you are trying to accomplish.

HEX is compact and widely used in CSS and design tools. RGB maps directly to how displays work. HSL is far more intuitive for humans when adjusting brightness or saturation. Understanding all three makes you faster whether you are writing CSS, working in Figma, or debugging a color mismatch between design and code.


HEX Colors

HEX (hexadecimal) represents each of the three color channels โ€” red, green, blue โ€” as a two-digit number in base 16:

#FF5733
  โ”‚โ”‚ โ”‚โ”‚ โ”‚โ”‚
  โ”‚โ”‚ โ”‚โ”‚ โ””โ”˜ Blue:  33 hex = 51 decimal
  โ”‚โ”‚ โ””โ”˜    Green: 57 hex = 87 decimal
  โ””โ”˜        Red:   FF hex = 255 decimal

Each channel ranges from 00 (0, off) to FF (255, full intensity). The # prefix is required in CSS.

Common HEX Examples

Color HEX
Red #FF0000
Green #00FF00
Blue #0000FF
White #FFFFFF
Black #000000
Mid-gray #808080

Shorthand HEX

When both digits of each channel are identical, you can abbreviate:

#FF5533  โ†’  #F53
#AABBCC  โ†’  #ABC
#FFFFFF  โ†’  #FFF

The browser expands each digit by doubling it: #F53 becomes #FF5533.

HEX with Alpha (Transparency)

CSS supports an 8-digit HEX for colors with transparency:

#FF573380   /* 50% transparent orange */

The last two digits are the alpha channel: 00 = fully transparent, FF = fully opaque.


RGB Colors

RGB spells out the three channels as decimal integers from 0 to 255:

rgb(255, 87, 51)       /* orange */
rgb(0, 0, 0)           /* black */
rgb(255, 255, 255)     /* white */

RGBA โ€” RGB with Alpha

rgba(255, 87, 51, 0.5)   /* 50% transparent orange */
rgba(0, 0, 0, 0.8)       /* 80% opaque black overlay */

The alpha value in RGBA is a decimal between 0 (invisible) and 1 (fully opaque), not a percentage.

In modern CSS, rgb() now accepts a fourth parameter directly without needing rgba():

rgb(255 87 51 / 50%)   /* space-separated, with / for alpha */

Converting HEX to RGB

Convert each two-digit HEX pair to decimal:

#FF5733
FF โ†’ 255 (red)
57 โ†’ 87  (green)
33 โ†’ 51  (blue)

Result: rgb(255, 87, 51)

To convert manually: for FF, compute (16 ร— 15) + 15 = 255. For 57, compute (16 ร— 5) + 7 = 87.

Converting RGB to HEX

Reverse the process โ€” convert each decimal to two-digit hex:

255 โ†’ FF
87  โ†’ 57
51  โ†’ 33

Result: #FF5733

Or use the Color Converter to do it in one click.


HSL Colors

HSL stands for Hue, Saturation, Lightness. Unlike HEX and RGB, which describe color in terms of hardware (light channels), HSL describes color in terms of human perception.

hsl(14, 100%, 60%)   /* orange */
hsl(0, 100%, 50%)    /* pure red */
hsl(240, 100%, 50%)  /* pure blue */
hsl(0, 0%, 50%)      /* mid-gray */

The Three Components

Hue (0โ€“360) is an angle on the color wheel:

  • 0ยฐ / 360ยฐ = Red
  • 60ยฐ = Yellow
  • 120ยฐ = Green
  • 180ยฐ = Cyan
  • 240ยฐ = Blue
  • 300ยฐ = Magenta

Saturation (0%โ€“100%) controls color intensity:

  • 0% = completely gray (no color)
  • 100% = fully vivid color

Lightness (0%โ€“100%) controls brightness:

  • 0% = black
  • 50% = the "true" color
  • 100% = white

HSLA โ€” HSL with Alpha

hsla(14, 100%, 60%, 0.5)   /* 50% transparent orange */

Modern CSS also accepts:

hsl(14 100% 60% / 50%)

Why HSL Is More Useful for Design

HSL lets you create color variations programmatically. Want a lighter version of your brand color? Just increase the lightness:

/* Brand blue */
hsl(220, 80%, 50%)

/* Lighter tint */
hsl(220, 80%, 70%)

/* Even lighter */
hsl(220, 80%, 85%)

/* Darker shade */
hsl(220, 80%, 30%)

All four share the same hue and saturation โ€” only lightness changes. In CSS custom properties, this technique creates entire palettes from a single hue value:

:root {
  --brand-hue: 220;
  --brand-color: hsl(var(--brand-hue), 80%, 50%);
  --brand-light: hsl(var(--brand-hue), 80%, 85%);
  --brand-dark:  hsl(var(--brand-hue), 80%, 30%);
}

Converting Between Formats

RGB to HSL (the math)

Given rgb(255, 87, 51):

  1. Normalize: R = 255/255 = 1.0, G = 87/255 โ‰ˆ 0.341, B = 51/255 = 0.2
  2. Max = 1.0 (R), Min = 0.2 (B), Delta = 0.8
  3. Lightness = (Max + Min) / 2 = (1.0 + 0.2) / 2 = 0.6 โ†’ 60%
  4. Saturation = Delta / (1 - |2L - 1|) = 0.8 / (1 - |1.2 - 1|) = 0.8 / 0.8 = 1.0 โ†’ 100%
  5. Hue = 60 ร— ((G - B) / Delta) = 60 ร— ((0.341 - 0.2) / 0.8) = 60 ร— 0.176 โ‰ˆ 10.6ยฐ โ†’ rounded to 14ยฐ

Result: hsl(14, 100%, 60%)

You do not need to do this by hand โ€” use the Color Converter.

Quick Reference

Input Output Notes
#FF5733 rgb(255, 87, 51) Parse each pair as hex
#FF5733 hsl(14, 100%, 60%) Requires the full calculation
rgb(255, 87, 51) #FF5733 Convert each channel to 2-digit hex
rgb(255, 87, 51) hsl(14, 100%, 60%) Normalize then apply HSL formula

Which Format Should You Use?

Use HEX when:

  • Copy-pasting from design tools (Figma, Sketch, Adobe XD output HEX by default).
  • Writing static CSS where you do not need to manipulate the color.
  • Communicating a specific color value to a client or colleague.

Use RGB / RGBA when:

  • Working with canvas, WebGL, or image processing code that needs decimal channel values.
  • You need alpha transparency and prefer the explicit decimal syntax.
  • Passing color values to JavaScript for arithmetic.

Use HSL / HSLA when:

  • Building a design system or theme with multiple shades of the same color.
  • Programmatically lightening, darkening, or desaturating colors.
  • Writing readable CSS where the intent of a color adjustment should be obvious.
  • Implementing dark mode variants โ€” flip the lightness, keep the hue.

New CSS Color Formats (2024+)

Modern CSS introduces wider-gamut formats for displays that can show more colors than sRGB:

  • oklch() โ€” A perceptually uniform version of HSL (same Hue concept, better human-perception alignment). Increasingly recommended over HSL for design systems.
  • display-p3 โ€” Targets the wider P3 color gamut used by Apple displays and modern phones.
  • color-mix() โ€” Mixes two colors without JavaScript: color-mix(in hsl, red 40%, blue).

Browser support for these is solid in 2025+. For most web projects today, HEX, RGB, and HSL remain the practical defaults.


Frequently Asked Questions

Why does my HEX color look different in CSS vs. Figma? Both should render the same color in sRGB. Differences usually come from the monitor's color profile or display color space settings. Some Figma files use P3 colors that cannot be exactly represented in sRGB.

What is the difference between rgba(0,0,0,0.5) and rgb(0 0 0 / 50%)? They produce identical results. The newer space-separated syntax with / for alpha is the modern CSS standard and works in all current browsers.

Can I use HSL in older browsers? HSL has been supported since IE 9 (2011). HSLA since IE 9 as well. The space-separated slash syntax requires a modern browser (Chrome 91+, Firefox 89+, Safari 15+).

Is there a lossless round-trip between HEX and HSL? Not exactly. HEX and RGB store values in 8-bit integer space (0โ€“255 per channel). HSL involves floating-point math, so converting HEX โ†’ HSL โ†’ HEX may introduce tiny rounding errors in the LSB. In practice this is visually imperceptible.


Convert any color between HEX, RGB, and HSL instantly using the Color Converter โ€” paste in any format and get all three outputs at once.

Ad ยท 728ร—90 Leaderboard
Back to BlogBrowse Tools โ†’

Related Articles

๐Ÿ“–
Base64Encoding
5 min read

Base64 Encoding Explained: What It Is and When to Use It

Understand Base64 encoding from first principles: how it works, when to use it, when to avoid it, and practical examples in APIs, emails, and data URIs.

ST
Jun 20, 2026Read โ†’
๐Ÿ“–
Password SecurityCybersecurity
6 min read

Creating Strong Passwords: A Practical Security Guide

Learn what makes a password truly strong, how attackers crack weak ones, and how to build a password strategy that actually works for your daily life.

ST
Jun 20, 2026Read โ†’
๐Ÿ“–
JSONDeveloper Tools
5 min read

How to Format and Validate JSON: A Developer's Guide

Learn how to format, validate, and debug JSON data with practical examples. Master JSON syntax rules and avoid common pitfalls in APIs and config files.

ST
Jun 20, 2026Read โ†’