Shades of Black in CSS: Hex Codes, Swatches and Contrast
"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
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.
| Swatch | Name | Hex | Source / note | White text | #9E9E9E text |
|---|---|---|---|---|---|
| Pure black | #000000 | CSS named colour black | 21:1 | 7.84:1 | |
| Slate 950 | #020617 | Tailwind CSS v3 palette (blue-tinted) | 20.17:1 | 7.53:1 | |
| Near black | #0A0A0A | Common off-black | 19.8:1 | 7.39:1 | |
| Slate 900 | #0F172A | Tailwind CSS v3 palette (blue-tinted "slate black") | 17.85:1 | 6.66:1 | |
| Smoky black | #100C08 | Traditional colour name (warm) | 19.48:1 | 7.27:1 | |
| Off-black #111 | #111111 | Common off-black | 18.88:1 | 7.05:1 | |
| Gray 900 | #111827 | Tailwind CSS v3 palette (cool) | 17.74:1 | 6.62:1 | |
| Material dark surface | #121212 | Baseline surface in Material Design's dark theme guidance | 18.73:1 | 6.99:1 | |
| Neutral 900 | #171717 | Tailwind CSS v3 palette (true neutral) | 17.93:1 | 6.69:1 | |
| Zinc 900 | #18181B | Tailwind CSS v3 palette | 17.72:1 | 6.61:1 | |
| Eerie black | #1B1B1B | Traditional colour name | 17.22:1 | 6.43:1 | |
| Stone 900 | #1C1917 | Tailwind CSS v3 palette (warm) | 17.49:1 | 6.53:1 | |
| Dark grey #222 | #222222 | Common card / panel shade | 15.91:1 | 5.94:1 | |
| Raisin black | #242124 | Traditional colour name (purple tint) | 15.93:1 | 5.95:1 | |
| darkslategray | #2F4F4F | CSS named colour | 8.93:1 | 3.33:1 below 4.5 | |
| Dark grey #333 | #333333 | Common border / elevated surface | 12.63:1 | 4.72:1 | |
| Jet | #343434 | Traditional colour name | 12.45:1 | 4.65:1 | |
| Onyx | #353839 | Traditional colour name | 11.82:1 | 4.41:1 below 4.5 | |
| Charcoal | #36454F | Traditional colour name (blue-grey) | 9.9:1 | 3.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
- OLED screens. On OLED displays, pixels showing pure black are switched off, which is why "true black" themes exist for phones.
- Maximum contrast for imagery, video players, photo galleries and cinematic hero sections.
- Seamless blending with black images, videos and device bezels.
Reasons to use an off-black like #121212
- Less harsh text. Pure white on pure black (21:1) can look like it glows or bleeds for some readers, particularly people with astigmatism. Dropping the background to
#121212and text to#E0E0E0still gives about 14:1. - Visible elevation. Shadows don't show on pure black. Material Design's dark theme guidance uses
#121212as the base surface and expresses elevation with progressively lighter surfaces instead of shadows. - Scrolling smear. Some OLED panels show a purple or dark trail when content scrolls across pure black, because fully-off pixels take slightly longer to switch on. A near-black such as
#0A0A0Aor#111avoids fully-off pixels.
"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); }
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.