Shades of Black in CSS: Hex Codes, Swatches and Contrast

Last reviewed on 2026-10-03

"Black" on the web is rarely one colour. Designers use pure #000000 for maximum contrast, softer off-blacks like #121212 for dark themes, and tinted blacks (slate, charcoal, warm stone) to give a dark interface some character. This page lists the most useful shades of black for CSS backgrounds with their hex codes, live swatches, and the computed WCAG contrast ratio of white text and mid-grey text on each one.

All the ways to write pure black in CSS

These declarations all produce exactly the same colour:

background-color: black;
background-color: #000;
background-color: #000000;
background-color: #000000ff;          /* 8-digit hex with full alpha */
background-color: rgb(0 0 0);          /* modern space-separated syntax */
background-color: rgb(0, 0, 0);        /* legacy comma syntax */
background-color: hsl(0 0% 0%);
background-color: hwb(0 0% 100%);

To make a whole page black, set it on the root element and give text a light colour; the full walkthrough (where the code goes, inline vs. stylesheet, the JavaScript way) is in how to make a black background with CSS.

Shades of black: swatches

Pure black#000000
Slate 950#020617
Near black#0A0A0A
Slate 900#0F172A
Smoky black#100C08
Off-black #111#111111
Gray 900#111827
Material dark surface#121212
Neutral 900#171717
Zinc 900#18181B
Eerie black#1B1B1B
Stone 900#1C1917

Shades of black: hex codes and contrast

Contrast ratios were calculated with the WCAG 2 relative-luminance formula. WCAG AA requires 4.5:1 for normal text and 3:1 for large text (24px, or 18.66px bold) and UI components; AAA requires 7:1 for normal text. Mid-grey here is #9E9E9E, a typical "secondary text" colour.

SwatchNameHexSource / noteWhite text#9E9E9E text
Pure black#000000CSS named colour black21:17.84:1
Slate 950#020617Tailwind CSS v3 palette (blue-tinted)20.17:17.53:1
Near black#0A0A0ACommon off-black19.8:17.39:1
Slate 900#0F172ATailwind CSS v3 palette (blue-tinted "slate black")17.85:16.66:1
Smoky black#100C08Traditional colour name (warm)19.48:17.27:1
Off-black #111#111111Common off-black18.88:17.05:1
Gray 900#111827Tailwind CSS v3 palette (cool)17.74:16.62:1
Material dark surface#121212Baseline surface in Material Design's dark theme guidance18.73:16.99:1
Neutral 900#171717Tailwind CSS v3 palette (true neutral)17.93:16.69:1
Zinc 900#18181BTailwind CSS v3 palette17.72:16.61:1
Eerie black#1B1B1BTraditional colour name17.22:16.43:1
Stone 900#1C1917Tailwind CSS v3 palette (warm)17.49:16.53:1
Dark grey #222#222222Common card / panel shade15.91:15.94:1
Raisin black#242124Traditional colour name (purple tint)15.93:15.95:1
darkslategray#2F4F4FCSS named colour8.93:13.33:1 below 4.5
Dark grey #333#333333Common border / elevated surface12.63:14.72:1
Jet#343434Traditional colour name12.45:14.65:1
Onyx#353839Traditional colour name11.82:14.41:1 below 4.5
Charcoal#36454FTraditional colour name (blue-grey)9.9:13.7:1 below 4.5

Two things stand out. First, every one of these blacks passes AAA with white text, so the choice between them is about mood, not legibility. Second, secondary grey text gets marginal fast: #9E9E9E drops below 4.5:1 on the lighter, tinted blacks such as onyx #353839, charcoal #36454F and darkslategray. If you use lighter "blacks" for cards, lighten your secondary text too. Check your own pair with the dark background contrast checker.

Pure black or off-black?

Reasons to use pure #000

Reasons to use an off-black like #121212

"Slate black" and tinted blacks

A tinted black is a very dark colour with a hint of hue. Blue-tinted blacks (#0F172A, #020617) read as cool and technical; warm blacks (#1C1917, #100C08) feel softer and more editorial. Tints work best when the rest of the palette shares the hue: pair slate backgrounds with blue-grey borders and text.

/* A slate-tinted dark theme */
:root {
  --bg:        #0F172A;   /* slate black */
  --surface:   #1E293B;   /* raised cards */
  --border:    #334155;
  --text:      #E2E8F0;
  --text-soft: #94A3B8;
}
body {
  background-color: var(--bg);
  color: var(--text);
}

Building a black scale with custom properties

A dark interface usually needs four or five blacks: page, surface, raised surface, border and hover. Defining them once as custom properties keeps everything consistent:

:root {
  --black-0: #000000;   /* page or media background */
  --black-1: #0A0A0A;   /* page background (off-black) */
  --black-2: #121212;   /* cards */
  --black-3: #1E1E1E;   /* raised cards, menus */
  --black-4: #2A2A2A;   /* borders, dividers */
}
.card       { background: var(--black-2); border: 1px solid var(--black-4); }
.card:hover { background: var(--black-3); }
Card on #121212
Raised #1E1E1E
Inset #000

Black with a little depth

A flat black can feel empty on large screens. A subtle gradient between two blacks adds depth without changing the overall colour:

body {
  background-color: #000;
  background-image: radial-gradient(ellipse at top, #1a1a1a 0%, #000 70%);
  min-height: 100vh;
}

More ideas: black gradient backgrounds, black grid and dot backgrounds, black background examples and colours that work with black.

FAQ

What is the hex code for black?

#000000 (short form #000), which is the same as the CSS keyword black and rgb(0 0 0).

What is a good off-black for a website?

#121212 is a widely used baseline for dark themes; #0A0A0A and #111111 are closer to pure black. All three pass WCAG AAA with white text.

What colour is "slate black"?

There is no single standard value. In CSS work it usually means a very dark blue-grey such as Tailwind's slate-900 #0F172A or slate-950 #020617. The CSS named colour darkslategray (#2F4F4F) is much lighter and greener.