Color Values

Understanding RGB, HEX, HSL, and other color value formats

CSS Color Value Formats

CSS supports several color value formats. Each represents the same color in a different way, and each has different advantages depending on your use case.

1. Named Colors

The simplest format — use a predefined English name. CSS supports 148 named colors.

Named Color Example
h1 {
  color: tomato;
}
p {
  color: steelblue;
}

Hello World

This paragraph uses steelblue color.

2. HEX Values

A 6-digit hexadecimal code preceded by #. Each pair represents Red, Green, and Blue (00–FF). A 3-digit shorthand is also supported where each digit is doubled.

/* 6-digit HEX */
.box { color: #FF6347; }      /* Tomato */

/* 3-digit HEX shorthand */
.box { color: #F00; }         /* Same as #FF0000 (Red) */

/* 8-digit HEX with alpha */
.box { color: #FF634780; }    /* Tomato at 50% opacity */

3. RGB / RGBA Values

Specify Red, Green, and Blue channels as numbers from 0 to 255. RGBA adds an alpha channel (0.0 to 1.0) for transparency.

RGB Example
/* Opaque */
.solid { background: rgb(255, 99, 71); }

/* 50% transparent */
.transparent {
  background: rgba(255, 99, 71, 0.5);
}
rgb(255, 99, 71)
rgba(255, 99, 71, 0.5)

4. HSL / HSLA Values

HSL stands for Hue (0–360°), Saturation (0–100%), and Lightness (0–100%). This is often the most intuitive format for designers because adjusting lightness or saturation is straightforward.

/* Pure red at full saturation, 50% lightness */
.box { color: hsl(0, 100%, 50%); }

/* Desaturated red (grayish) */
.box { color: hsl(0, 30%, 50%); }

/* With alpha transparency */
.box { color: hsla(0, 100%, 50%, 0.5); }
0°
60°
120°
180°
240°
300°

5. HWB Values

HWB stands for Hue, Whiteness, and Blackness. It describes how much white and black are mixed into a pure hue color.

/* HWB syntax */
.box { color: hwb(0 0% 0%); }     /* Pure red */
.box { color: hwb(0 50% 0%); }    /* Red + 50% white = pink */
.box { color: hwb(0 0% 50%); }    /* Red + 50% black = dark red */

6. CMYK (for reference)

CMYK stands for Cyan, Magenta, Yellow, Key (Black). It is primarily used in print design. While not natively supported in CSS, understanding it helps when converting between digital and print colors.

🖨️
CMYK is a subtractive color model (used in printing), while RGB is an additive model (used on screens). The same color can look different between the two systems.

Interactive Color Format Converter

Use the RGB sliders or enter a HEX code to see a color in all formats simultaneously. Click any value to copy it.

#6495ED
Red100
Green149
Blue237
HEX#6495ED
RGBrgb(100, 149, 237)
RGBArgba(100, 149, 237, 1.0)
HSLhsl(219, 79%, 66%)
HSLAhsla(219, 79%, 66%, 1.0)
HWBhwb(219 39% 7%)
CMYKcmyk(58%, 37%, 0%, 7%)
NColC39, 39%, 7%

Choosing the Right Format

FormatBest ForPros
NamedQuick prototypingEasy to remember
HEXDesign tools, shorthandCompact, widely used
RGBProgrammatic manipulationEasy to compute
HSLColor adjustmentsIntuitive hue/saturation control
HWBTinting / shadingSimple whiteness/blackness mixing
🎨
Tip: HSL is great for creating color palettes because you can keep the hue constant and vary saturation and lightness to create harmonious shades and tints.