CSS Color Basics

CSS has four ways to write the same color. Pick a color below and watch all four update at once.

The quick brown fox jumps over the lazy dog

CSS color basics: how named, hex, RGB, and HSL values work, with a live switcher that shows one color in all four formats at once, plus a copyable CSS snippet.

CSS has four ways to write the same color: a name (steelblue), a hex code (#3B82F6), RGB (rgb(59, 130, 246)), or HSL (hsl(217, 91%, 60%)). They all describe the same color — pick the format that is easiest to read and adjust.

The four ways to write a color in CSS

FormatExample (same blue)When to use it
NamedsteelblueQuick prototypes and readable code. Only 148 names exist, so most colors have no name.
Hex#3B82F6The default. Compact, copy-pasteable, and what design tools give you.
RGBrgb(59, 130, 246)When you think in red/green/blue channels, or need transparency: rgba(59, 130, 246, 0.5).
HSLhsl(217, 91%, 60%)When you want shades and tints: keep the hue, raise lightness for a tint, lower it for a shade.

All four describe the same color — the browser converts them to the same red, green, and blue light. The demo above proves it: change the color once and every format updates to match. Pick the format that is easiest to read and adjust for the job at hand; hex for most work, HSL when you are building a scale of shades, named colors only when the exact name exists.

How hex works

A hex code is three pairs of hexadecimal digits: red, green, blue, each from 00 (none) to FF (full). #FF0000 is pure red, #00FF00 pure green, #0000FF pure blue, #000000 black, #FFFFFF white. A 3-digit code like #F53 is shorthand — each digit doubles, so it means #FF5533. There are 16,777,216 possible hex colors. The hex code guide explains this in full.

How HSL works

HSL splits a color into three ideas that match how people think: hue (the angle around the color wheel, 0–360° — 0 is red, 120 is green, 240 is blue), saturation (0% is gray, 100% is fully vivid), and lightness (0% is black, 50% is the pure color, 100% is white). To make a tint, raise lightness; to make a shade, lower it; to mute a color, lower saturation. That is why HSL is the best format for building a palette from one brand color.

Transparency

RGB and hex both have transparent forms. rgba(59, 130, 246, 0.5) is the same blue at 50% opacity, and modern browsers accept 8-digit hex too: #3B82F680 (the last two digits are the opacity, 80 in hex is 128 out of 255). Transparency is useful for overlays and hover states, but remember that a semi-transparent color over an unknown background can fail contrast — check it in the contrast checker.

Frequently asked questions

Which CSS color format should I use?

Hex (#3B82F6) for most work — it is compact and every tool produces it. Use HSL when you need to make tints and shades from one color, and named colors only for the 148 CSS names like steelblue or rebeccapurple.

What is the difference between hex and RGB in CSS?

They describe the same color in different notation. Hex writes each channel as two hexadecimal digits (#FF5733); RGB writes them as decimals from 0 to 255 (rgb(255, 87, 51)). Convert between them on the hex-to-RGB page.

Can I use a color name instead of a hex code?

Yes, but only the 148 CSS named colors work — red, steelblue, rebeccapurple, and so on. Most colors have no name, so hex is the safer default. The demo above tells you when your color has a CSS name.

What does hsl(217, 91%, 60%) mean?

Hue 217 degrees (a blue), saturation 91% (very vivid), lightness 60% (a little lighter than the pure color). The same color as hex #3B82F6 and rgb(59, 130, 246).

Related tools

What Is a Hex Code? · Color Converter · Hex to RGB · CSS Text Color · CSS Background Color