Color Codes Reference

Color codes reference: common CSS named colors mapped to HEX and RGB values, with swatch previews for quick selection in frontend styles.

How It Works

The same color can be written several ways. HEX (e.g. #ff8000) is just RGB in hexadecimal; RGB describes it with three 0–255 channels (red/green/blue); HSL uses hue (0–360°), saturation and lightness, which matches human intuition and makes tweaking easier.

They convert to one another; the choice is contextual — CSS leans on HEX and RGB, theming and gradients prefer HSL. Transparency is expressed with RGBA/HSLA or 8-digit HEX (#rrggbbaa) for the alpha channel.

In practice, converge colours into a set of design tokens instead of scattering hex values: name them semantically (surface / text-muted / border) so a dark-mode switch only swaps token values and components stop carrying literal colours. Define tokens in HSL where possible, since shifting one lightness channel makes hover/active steps easy to generate in bulk — but validate the contrast of every value with the WCAG relative-luminance formula, because an HSL L value is not a brightness measurement.

Also mind alpha notation: 8-digit hex (#rrggbbaa) and CSS rgba() mean the same thing, but 4-digit hex (#rgba) is unsupported in older browsers, so use rgba() when compatibility matters. Mixing colour spaces inside a gradient or shadow (sRGB alongside display-p3) forces the browser to convert into the narrower gamut, which shows up as desaturated colour — not a bug, but the inevitable result of gamut convergence.

When to Use This Table

This table is for translating a colour from a design file into a value in code: conversions between hex, RGB, HSL and CMYK, plus the mapping between CSS keywords and hex, are the most error-prone step between design and implementation.

When not to consult it: you are assessing contrast accessibility. WCAG luminance (relative luminance and the contrast formula) is a separate derivation, and the numeric conversions here do not constitute an accessibility conclusion.

Rule of thumb: this page is enough for converting representations (HEX↔RGB↔HSL). If the question is "is this palette acceptable", you need the WCAG formula and a real sampled colour, not two spellings of the same hex.

Mind that CMYK is device-dependent: identical CMYK values render differently across paper stocks and profiles. It exists for print file headers (an ICC profile reference in print) and must not be used directly for on-screen colour.

Boundaries and Common Pitfalls

  • HEX means sRGB, not the true colour on screen

    HEX numbers are coordinates in the sRGB gamut, and whether a display shows them accurately depends on calibration and ambient light. On a wide-gamut (P3) screen, no HEX value can exceed sRGB; conversely, P3 coordinates written as HEX look visibly washed out. To actually use a wide gamut, reach for color(display-p3 ...) or @media (color-gamut: p3) as progressive enhancement.

  • HSL percentages live in sRGB, and are not perceptually uniform

    HSL is good for exploration — picking a plausible colour by hue, building a 24-swatch palette or a theme colour — but bad when you need visually consistent steps: hues at the same L look very different in brightness (yellow at L=50% reads far brighter than blue at L=50%). For hover/active steps, either tune lightness against real perception or move to a perceptually uniform space such as LCH.

  • Alpha applied to text changes the real contrast ratio

    A translucent foreground such as rgba(0,0,0,0.5) blends with the background into a new colour that often fails contrast. WCAG ratios must be computed on the composited result, not on the values declared in CSS. Translucent text also introduces rounding differences across browsers and compositing layers, so identical code can be less readable in one environment than another.

  • CSS keyword colours are not always what you picture

    tomato is #FF6347 and orange is #FFA500, but gray in CSS is #808080 — not the "dark grey" most people picture — and darkgray is #A9A9A9, which is lighter than gray. These names come from an early X11 palette and often contradict everyday intuition. When precision matters, skip keywords and use hex or design tokens so the colour does not drift between browsers.

How This Relates to Neighbours

To extract a dominant colour, build a palette or preview combinations, use the in-site colour tools; this page only converts numbers and does no image analysis.

Judging readability (contrast, accessibility compliance) needs the WCAG relative-luminance formula, which this page does not conclude.

To emit a CSS variable or Tailwind snippet, generate it with the in-site converter and commit it yourself; this page does not generate code.

If the goal is consistency across dark and light modes, this table helps unify the notation, but the switching strategy and contrast validation still need their own design.

Practical Snippet

Key points: (1) HEX is an sRGB coordinate, not an appearance — wide-gamut work needs color(display-p3) as progressive enhancement; (2) HSL lightness is not perceptual brightness, so contrast must go through the WCAG relative-luminance formula — both functions are above, and only the latter is correct here; (3) when d === 0 the colour is grey and has no hue, so return h=0/s=0 rather than computing a meaningless hue.

// HEX ↔ RGB ↔ HSL 互转(不依赖任何库的最小实现)
function hexToRgb(hex: string) {
  const h = hex.replace('#', '')
  const full = h.length === 3 ? h.split('').map(c => c + c).join('') : h
  return {
    r: parseInt(full.slice(0, 2), 16),
    g: parseInt(full.slice(2, 4), 16),
    b: parseInt(full.slice(4, 6), 16),
  }
}

function rgbToHsl({ r, g, b }: { r: number; g: number; b: number }) {
  const [rn, gn, bn] = [r, g, b].map(v => v / 255)
  const max = Math.max(rn, gn, bn), min = Math.min(rn, gn, bn)
  const l = (max + min) / 2
  const d = max - min
  if (d === 0) return { h: 0, s: 0, l }            // 灰色:色相无意义
  const s = d / (1 - Math.abs(2 * l - 1))
  let h: number
  if (max === rn) h = 60 * (((gn - bn) / d) % 6)
  else if (max === gn) h = 60 * ((bn - rn) / d + 2)
  else h = 60 * ((rn - gn) / d + 4)
  return { h: (h + 360) % 360, s, l }
}

// 相对亮度(WCAG 2.x)—— 对比度必须用它,而不是拿 HSL 的 L 当亮度
function relativeLuminance(hex: string) {
  const { r, g, b } = hexToRgb(hex)
  const lin = (v: number) => {
    const c = v / 255
    return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4)
  }
  return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b)
}

const contrast = (a: string, b: string) => {
  const [x, y] = [relativeLuminance(a), relativeLuminance(b)].sort((p, q) => q - p)
  return (x + 0.05) / (y + 0.05)
}

console.log(contrast('#0d9488', '#ffffff'))  // 码屋 teal 对白字的实际对比度

Practical Notes

  • Only 148 named colors, and transparent / currentColor are not among themBoth are CSS-wide keywords rather than color values. They work in a background declaration, but getComputedStyle(el).backgroundColor resolves transparent to rgba(0, 0, 0, 0) and currentColor to the element color — handle these two cases separately when comparing colors programmatically.
  • Do not mix #RGB and #RRGGBB formsThe 3-digit form duplicates each nibble: #abc means #aabbcc. That makes #1234 invalid, and browsers drop the whole declaration silently instead of falling back, so the symptom is "style simply does not apply" with no console error.
  • Design-tool HEX is sRGB; wide-gamut displays will shift itModern screens support Display-P3. Reusing an sRGB HEX inside color(display-p3 …) visibly shifts the hue. To stay consistent across gamuts, adjust lightness and chroma in OKLCH or HSL first, then convert back to the target space.

Data Sources

  • W3C CSS Color Module Level 4
  • W3C CSS Color Module Level 5

Codes, names and definitions above come from public specifications; we claim no originality over the specification data itself. The arrangement, Chinese annotations and practical notes on this page are written by us.

SwatchNameHEXRGB
Black#000000rgb(0, 0, 0)
White#FFFFFFrgb(255, 255, 255)
Red#FF0000rgb(255, 0, 0)
Green#008000rgb(0, 128, 0)
Lime#00FF00rgb(0, 255, 0)
Blue#0000FFrgb(0, 0, 255)
Yellow#FFFF00rgb(255, 255, 0)
Cyan#00FFFFrgb(0, 255, 255)
Magenta#FF00FFrgb(255, 0, 255)
Gray#808080rgb(128, 128, 128)
Silver#C0C0C0rgb(192, 192, 192)
Maroon#800000rgb(128, 0, 0)
Olive#808000rgb(128, 128, 0)
Navy#000080rgb(0, 0, 128)
Teal#008080rgb(0, 128, 128)
Purple#800080rgb(128, 0, 128)
Orange#FFA500rgb(255, 165, 0)
Pink#FFC0CBrgb(255, 192, 203)
Brown#A52A2Argb(165, 42, 42)
Gold#FFD700rgb(255, 215, 0)
Tomato#FF6347rgb(255, 99, 71)
Crimson#DC143Crgb(220, 20, 60)
SteelBlue#4682B4rgb(70, 130, 180)
DodgerBlue#1E90FFrgb(30, 144, 255)
ForestGreen#228B22rgb(34, 139, 34)
HotPink#FF69B4rgb(255, 105, 180)
Indigo#4B0082rgb(75, 0, 130)
Violet#EE82EErgb(238, 130, 238)
Chocolate#D2691Ergb(210, 105, 30)
Salmon#FA8072rgb(250, 128, 114)
SkyBlue#87CEEBrgb(135, 206, 235)
SlateGray#708090rgb(112, 128, 144)
LightGray#D3D3D3rgb(211, 211, 211)
DarkSlateGray#2F4F4Frgb(47, 79, 79)
Coral#FF7F50rgb(255, 127, 80)
Turquoise#40E0D0rgb(64, 224, 208)
Khaki#F0E68Crgb(240, 230, 140)
Plum#DDA0DDrgb(221, 160, 221)

Frequently Asked Questions

What is the difference between HEX and RGB?

They represent the same color. HEX is hexadecimal (e.g. #FF0000); RGB is a decimal function (rgb(255,0,0)). Modern CSS also supports rgb(255 0 0 / 0.5) alpha and #RRGGBBAA.

What are web-safe colors?

Early displays could only reliably show a 216-color palette. It is no longer necessary, but classic named colors like red/blue/green remain the most used.

How do I ensure accessible color contrast?

Aim for text/background contrast ≥ 4.5:1 (WCAG AA). Do not judge by named color alone; use a contrast checker.

How many named CSS colors are there?

The CSS spec defines 148 named colors (including transparent and currentColor). This table lists the most common basic and extended colors.