ColorApril 2026 · 10 min read

HTML Color Codes Explained: HEX, RGB, HSL & Beyond

Every color you see on the web is defined by a code. Whether it's a six-character HEX value, an RGB triplet, or an HSL declaration, understanding how these formats work helps you write cleaner CSS, communicate with designers, and build more consistent color systems. This guide breaks down every format you'll encounter.

🔄
Try the Color Converter
Convert between HEX, RGB, HSL, HSB & CMYK instantly — free tool
DG
Derek Giordano
Designer & Developer
In this guide
01HEX Color Codes02RGB & RGBA03HSL & HSLA04CSS Named Colors05Modern Color Functions06Which Format to Use07Converting Between Formats08Transparency & Opacity09CSS Custom Properties for Colors10Color Tools & Resources
⚡ Key Takeaways
  • Learn every web color format: HEX, RGB, RGBA, HSL, HSLA, and named colors.
  • Covers hex color codes.
  • Covers rgb & rgba.
  • Covers hsl & hsla.
  • Covers css named colors.

HEX Color Codes

HEX (hexadecimal) is the most widely used color format on the web. A HEX code starts with a hash symbol (#) followed by six characters representing the red, green, and blue channels. Each channel uses two hexadecimal digits (00–FF), giving 256 levels per channel and over 16 million possible colors.

color: #FF6B6B; /* Coral red */ color: #0575E6; /* Bright blue */ color: #43E97B; /* Emerald green */ color: #000000; /* Black */ color: #FFFFFF; /* White */
#00FFD1
#0575E6
#00FFD1

Shorthand HEX

When each channel's two digits are identical, you can shorten the code to three characters. For example, #FF0000 becomes #F00, and #AABBCC becomes #ABC. This only works when each pair is a repeated digit.

#FF0000 → #F00 #AABBCC → #ABC #112233 → #123

8-digit HEX (with alpha)

Modern browsers support 8-digit HEX codes where the last two digits represent alpha (transparency). 00 is fully transparent, FF is fully opaque. A 4-digit shorthand version also exists.

color: #FF6B6B80; /* 50% transparent coral */ color: #0575E6CC; /* 80% opaque blue */

RGB & RGBA

RGB defines colors using decimal values for red, green, and blue — each ranging from 0 to 255. It's functionally equivalent to HEX but uses decimal numbers, which many developers find more intuitive when adjusting individual channels.

💡 Tip
Always include -webkit-backdrop-filter alongside backdrop-filter for Safari support. Without the prefix, the effect is invisible to roughly 25% of mobile users.
color: rgb(255, 107, 107); /* Coral */ color: rgb(5, 117, 230); /* Blue */ color: rgb(0, 0, 0); /* Black */

RGBA adds a fourth value for alpha transparency, ranging from 0 (fully transparent) to 1 (fully opaque). This is the most common way to specify semi-transparent colors in CSS.

/* 50% transparent black — perfect for overlays */ background: rgba(0, 0, 0, 0.5); /* 15% transparent coral — subtle tint */ background: rgba(255, 107, 107, 0.15);

In modern CSS, you can also use the space-separated syntax without the "a" suffix: rgb(255 107 107 / 0.5). This newer syntax works in all current browsers.

HSL & HSLA

HSL stands for Hue, Saturation, and Lightness. Unlike RGB and HEX, which describe colors in terms of hardware (how much red, green, and blue light to emit), HSL describes colors the way humans think about them — what shade, how vivid, and how bright.

⚠ Warning
On iOS Safari, backdrop-filter inside a position: fixed element can cause severe scroll performance issues. Test thoroughly on real iOS devices.
color: hsl(0, 100%, 50%); /* Pure red */ color: hsl(120, 100%, 50%); /* Pure green */ color: hsl(240, 100%, 50%); /* Pure blue */ color: hsl(0, 78%, 71%); /* Coral (#FF6B6B) */

Hue is an angle on the color wheel (0–360 degrees): 0° is red, 120° is green, 240° is blue. Saturation ranges from 0% (gray) to 100% (full color). Lightness ranges from 0% (black) through 50% (pure color) to 100% (white).

HSL's biggest advantage is predictability. Want a darker version of a color? Decrease lightness. Want a pastel? Reduce saturation. Want a complementary color? Add 180° to the hue. These operations are intuitive in HSL but require calculation in RGB or HEX.

Building color scales with HSL

HSL makes it straightforward to create consistent color scales for design systems. Keep the hue and saturation constant, then vary lightness to create shades and tints:

--blue-100: hsl(210, 85%, 95%); /* Lightest */ --blue-300: hsl(210, 85%, 75%); --blue-500: hsl(210, 85%, 50%); /* Base */ --blue-700: hsl(210, 85%, 30%); --blue-900: hsl(210, 85%, 15%); /* Darkest */

CSS Named Colors

CSS defines 148 named colors that you can use instead of numeric codes. These range from obvious ones like red, blue, and white to more specific names like cornflowerblue, papayawhip, and rebeccapurple.

Named colors are useful for prototyping and debugging but rarely appear in production code. They lack precision — you can't fine-tune them — and they don't cover enough of the color space for real design work. The exceptions are transparent (equivalent to rgba(0,0,0,0)) and currentColor (inherits the element's text color), which are both widely used in production.

Modern Color Functions

CSS Color Level 4 introduced new color functions that provide access to wider color gamuts and more perceptually uniform color spaces.

oklch() and oklab()

OKLCH is a perceptually uniform color space — meaning that equal numeric changes produce equal visual changes. In HSL, changing lightness by 10% can produce wildly different perceived brightness depending on the hue. OKLCH fixes this.

color: oklch(70% 0.15 150); /* Perceptually uniform green */ color: oklch(50% 0.2 30); /* Perceptually uniform red */

OKLCH is increasingly recommended for design systems because it produces more consistent color scales across different hues. Browser support is strong across all major engines.

Which Format to Use

For most projects, the best approach is to pick one primary format and use it consistently. HEX is the most compact and universally understood — it's the standard in design tools like Figma. HSL is the best choice when you need to programmatically generate color variations (scales, palettes). RGBA is essential anywhere you need transparency. OKLCH is the forward-looking choice for design systems that need perceptual uniformity.

In practice, most codebases use a mix: HEX for solid brand colors defined in variables, RGBA for overlays and shadows, and HSL when building dynamic color scales.

Converting Between Formats

Converting between color formats involves mathematical transformations. HEX to RGB is straightforward — each pair of hex digits converts to a decimal 0–255 value. RGB to HSL requires calculating the hue from the relative values of R, G, and B, which is more complex.

Rather than converting manually, use the Ultimate Design Tools Color Converter to instantly convert between HEX, RGB, HSL, HSB, and CMYK. Paste any color code and get all formats simultaneously.

Transparency & Opacity

There are two ways to make an element semi-transparent in CSS: the opacity property and alpha-channel color values. They behave differently. The opacity property affects the entire element and all its children — text, borders, backgrounds, everything becomes transparent together.

Alpha-channel color values (RGBA, HSLA, 8-digit HEX) only affect the specific property where they're used. A background set to rgba(0,0,0,0.5) will be semi-transparent while the text on top remains fully opaque. This is why RGBA is preferred over opacity for backgrounds and overlays.

CSS Custom Properties for Colors

CSS custom properties (variables) are the best way to manage colors in any project. Define your palette once in the root selector, then reference it throughout your stylesheet. This creates a single source of truth that's easy to update.

:root { --color-primary: #FF6B6B; --color-primary-light: #FF8E8E; --color-primary-dark: #E04A4A; --color-bg: #0A0A0F; --color-text: rgba(255, 255, 255, 0.85); --color-muted: rgba(255, 255, 255, 0.45); } .button { background: var(--color-primary); color: var(--color-bg); }

For theme switching (light/dark mode), redefine the same variable names under different selectors. The entire UI updates automatically because every element references the variable, not a hardcoded value.

Color Tools & Resources

Ultimate Design Tools offers several free color tools to help with every aspect of working with color codes. The Color Converter handles format conversions. The Contrast Checker tests WCAG accessibility. The Palette Generator creates harmonious color schemes. The Color Picker extracts colors from uploaded images. And the Color Blindness Simulator shows how your colors appear to people with color vision deficiency.

Convert any color code instantly

Paste a HEX, RGB, or HSL value and get every format at once. Free, no signup.

⚡ Open Color Converter
DG
Derek Giordano
Written by the creator of Ultimate Design Tools. BA in Business Marketing.
📚 References & Further Reading