Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
Give every colour a job and a number: the 60-30-10 split, semantic tokens like --danger, a small contrast.js that computes WCAG ratios, and a dark palette that keeps its meaning where filter: invert(1) does not.
What you will learn
- Split a screen's colour 60-30-10 with one loud accent
- Name colours by their job with semantic CSS variables
- Compute a WCAG contrast ratio and know the 4.5:1 and 3:1 limits
- Build a dark theme as its own palette instead of inverting colours
Before you start
- Basic HTML and CSS
- Visual Hierarchy, Spacing and the 8-Point Grid
Colour is where most screens go wrong without anyone noticing. Too many loud colours, text that is a little too light, a dark mode that looks fine until you notice the error badge turned cyan.
In this article you give every colour a job and a number. The example is a small task board, TaskBoard, with a sidebar and a list of tasks. All the colours live in one style.css, and a tiny contrast.js checks them.
Three colour jobs on one page: 60, 30, 10

How much of each colour should you use? A simple split works:
- 60% neutral. The page and the cards. Calm and easy on the eyes.
- 30% brand. Here, the dark sidebar. This is the personality of the app.
- 10% accent. The Add task button is the only strong colour in the content area, so your eye goes straight to it.
When everything shouts, nothing is heard. Keep the loud colour to about ten percent.
Name a colour by its job, not its look
Store colours as CSS variables, and name them by what they do, not by what they look like. Here are the light tokens and the dark tokens from style.css:
/* TaskBoard colours: semantic tokens. Light is the default, dark replaces only the values. */
:root {
--bg: #f8fafc; /* 60% neutral: page and cards */
--surface: #ffffff; /* cards sitting on the page */
--brand-dark: #1e1b4b; /* 30% header and sidebar */
--primary: #4f46e5; /* 10% the one main action */
--on-primary: #ffffff;
--success: #15803d;
--warning: #b45309;
--danger: #b91c1c;
--on-status: #ffffff;
--text: #0f172a;
--muted: #475569;
--line: #e2e8f0;
}
[data-theme="dark"] {
--bg: #0f172a;
--surface: #1e293b;
--brand-dark: #0b1020;
--primary: #818cf8;
--on-primary: #0f172a;
--success: #4ade80;
--warning: #fbbf24;
--danger: #f87171;
--on-status: #0f172a;
--text: #e2e8f0; /* off-white, not pure white */
--muted: #a8b3c7;
--line: #334155;
}
--primary is the main action (#4f46e5). --success means done or saved, --warning means careful or due soon, --danger means error or delete, and --bg and --surface are the page and the cards.
Why bother? Because later you change the values, and every component keeps working. Write --danger, not --red. Then dark mode only changes the values, and the names stay put.
Contrast is a number you can compute
Is the text easy to read on its background? You do not guess this. You calculate it. This is the core of the project's contrast.js, the WCAG 2 contrast ratio:
// contrast.js - WCAG 2 contrast ratio. Run: node contrast.js (or load it in a page)
function channel(v) {
const c = v / 255;
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
}
function luminance(hex) {
const n = parseInt(hex.slice(1), 16);
const r = channel((n >> 16) & 255), g = channel((n >> 8) & 255), b = channel(n & 255);
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
}
function ratio(fg, bg) {
const a = luminance(fg), b = luminance(bg);
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
}
function verdict(r) {
return r >= 7 ? 'AAA' : r >= 4.5 ? 'AA pass' : r >= 3 ? 'large text only' : 'FAIL';
}
ratio finds the lightness (relative luminance) of each colour, then divides the lighter one plus 0.05 by the darker one plus 0.05. You do not need to memorise the formula. You need to know what the number means. Run it with node contrast.js and it checks every pair in its list:
17.06 : 1 AAA Body text on page
7.24 : 1 AAA Muted text on page
6.29 : 1 AA pass White on primary
5.02 : 1 AA pass White on success
1.53 : 1 FAIL White on yellow warning
2.56 : 1 FAIL Light grey on white
5.02 : 1 AA pass White on dark-amber warning
14.48 : 1 AAA Light text on dark page
11.87 : 1 AAA Light text on dark card
5.98 : 1 AA pass Dark text on lighter primary
5.29 : 1 AA pass Danger on dark card
21.00 : 1 AAA Pure white on pure black
Body text on the page is 17.06:1. White on the primary is 6.29, white on success 5.02. All of these pass.
Now the interesting part. White text on a bright yellow is 1.53:1, and it fails badly. Light grey text on white is 2.56:1. It looks stylish, and many people simply cannot read it. The fix for the warning colour is a darker amber, #b45309, and white on it is 5.02:1. Now it passes.
The rule: body text needs 4.5:1 or more, large text needs 3:1.
Same tokens, new values
The dark theme uses the same page and the same markup. Only the values in the [data-theme="dark"] block change. The page is a deep blue grey, the cards are a little lighter, the text is off-white rather than pure white, and the primary becomes a lighter, softer indigo.
Light text on the dark page is 14.48:1, and every pair still passes. Pure white on pure black would be 21:1, but it glares, and people get tired quickly. That is why --text is #e2e8f0 and not #ffffff.
Break it: dark mode by inverting every colour
Here is the lazy way to make dark mode. The project's broken.html adds one line:
/* BREAK IT: "dark mode" made by inverting every colour */
html { filter: invert(1); }

At first glance the inverted page is dark, so it looks done. Look closer. That one line replaced your whole palette, and no colour has its job any more. The danger red became cyan. The success green became pink. The indigo primary became olive. An overdue task is now cyan, and nobody reads cyan as a problem.
An invert flips the meaning too. Build the dark palette on purpose.
Before you ship any colour scheme
- About 60-30-10, with one loud accent.
- Colours named by job.
- Body text at 4.5:1 or more.
- Never show status by colour alone. Add a word or an icon, because some people cannot tell red from green.
- The dark theme is its own palette, with off-white text.
- Check every pair with a contrast tool.
And a line you can paste into any UI request:
Use 60-30-10 and semantic tokens, keep every text pair at 4.5:1 or more, and make the dark theme its own palette.
Recap
| Step | What it means |
|---|---|
| Split it | 60 neutral, 30 brand, 10 accent |
| Name it | By job: --primary, --success, --danger |
| Measure it | 4.5:1 for body text, 3:1 for large text |
| Dark theme | Same names, new values, never an invert |
You do not need to memorise colour values. AI can generate a full palette for you. What you need is to know what to ask for and how to check it. For how these same names travel into Tailwind, read design tokens.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI Engineer (paid course, opens in a new tab)Related posts
One Request, Two Answers: the Same Post as an HTML Page and as JSON
Ask a Django blog for the same post twice: once as a 12,731-byte HTML page built by a template, once as 2,976 bytes of JSON built by a serializer. Compare the headers, see who builds the page, and why the server still owns every write.
A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
Make a blog design from a prompt in Figma Make, download src.zip, unzip it with Python's zipfile module, and read the two files that matter: App.tsx with its selectedPost state and BlogCard.tsx with its props.
How a Web Page Works: HTML Tags, Elements and Attributes
A web page is a text file full of labelled pieces. Learn tags, attributes and nesting with three tiny pages, and see what breaks when an attribute or a closing tag is wrong.
Semantic HTML: header, nav, main, aside and footer as Page Landmarks
The same page written as div soup and with semantic tags looks identical, but only one gives screen readers and search engines landmarks and an outline. Plus tables, div, span and the one-main rule.
