Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

React
  • One Request, Two Answers: the Same Post as an HTML Page and as JSON
  • A Blog Design from a Prompt: Downloading Figma Make Code and Reading App.tsx and BlogCard.tsx
  • How a Web Page Works: HTML Tags, Elements and Attributes
  • Semantic HTML: header, nav, main, aside and footer as Page Landmarks
  • HTML Forms: Labels, Names, Input Types and Where the Data Goes (GET vs POST)
  • CSS Basics: Selectors, Which Rule Wins, and the Box Model
  • CSS Flexbox vs Grid: A Nav Bar, a Card Row and a Dashboard
  • Responsive CSS: Viewport, Mobile-First Media Queries, clamp() and Dark Mode with Tokens
  • JavaScript for People Who Already Code: Syntax, Modules and Five Surprises
  • JavaScript Arrays the Functional Way: map, filter, reduce, find, sort and Object.entries
  • Async JavaScript: Promises, async/await, fetch and Promise.all
  • JavaScript in the Page: the DOM, querySelector and Events
  • npm, package.json and Vite: What npm install Fetches and How Vite Serves and Builds Your Page
  • TypeScript Essentials: Types Checked, Then Erased (Interfaces, Unions, Generics)
  • Why React, JSX and Components: The Page as a Function of Data
  • React Props and Composition: Data Down, Calls Up, Children in the Slot
  • Routing With React Router: One Page, Many Addresses
  • React Component Tests With Vitest and Testing Library: Test What the User Sees
  • End-to-End Tests for a React App With Playwright: A Full Dress Rehearsal
  • Why AI-Built Websites All Look the Same, and Four Levels That Fix It
  • Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
  • Colour, Contrast and Dark Palettes: 60-30-10, Semantic Tokens and Ratios You Can Compute
  • Typography That Sells: Type Scale, Line Length and Free Font Pairings
  • The UI Element Catalogue: Buttons to Toasts, Their Jobs, States and shadcn/ui Names
  • Design Tokens: Primitive and Semantic Tokens, from Figma to CSS to Tailwind
  • Tailwind CSS 4 in React: Utility Classes, Responsive Prefixes, Hover and Dark Mode
  • shadcn/ui in React: Components You Own, Edit and Commit
  • Design Tokens to a Tailwind Theme: Light and Dark Mode with @theme inline
  • Motion in React: Entrance, Hover, Exit and Layout Animations
  • A React Dashboard: Stat Cards, a Recharts Line Chart and a Sortable Table
  • Accessibility in Practice: Dialogs, Menus and the Keyboard in React
  • Reference-Driven Design: Extract a DESIGN.md From a Site You Admire and Build From It
  • Components, Variants and Variables: One Design System in Figma and in CSS
  • Figma MCP Server: Build a React Component From a Frame, Then Write It Back
  • Claude Design: From a Brief to a Clickable Prototype, Then Hand It Off to Claude Code
  • Critiquing AI-Generated UI: Six Checks for Every Screen
  • The AI Design Landscape: Prompt to UI, Prompt to App, and Design to Code
  • Your Brand Rules Folder: One Folder Every AI-Built Page Follows
  • The Best-Practice UI Prompt: Plain Sentences That Beat the Average AI Page
  • UI Ideas From Figma Make, Google Stitch and ChatGPT: One Prompt, Three Designs
  • Google Stitch From a Sketch or Screenshot: Show the Layout, Say What to Keep
  • Stitch to Figma to Code: Turn a Stitch Screen Into Code That Uses Your Tokens
  • Figma Make: Prompt to Prototype With a Four-Part Prompt
  • Upgrade a Dated UI From One Screenshot (or a Reference Image)
  • States and Feedback: Make Every Click Get an Answer
  • A Design-Loop Skill: Claude Screenshots, Scores and Fixes Its Own UI
  • Copy Without the AI Tells: A Copy Pass on a Landing Page
  • React State, Events, Lists and Conditional Rendering: Follow One Click
  • React useEffect: When It Runs, What Cleanup Is For, and When You Don't Need One
  • Lifting State Up, Refs and React DevTools: Put State Where It Is Needed
  • Forms and Actions in React 19: Controlled Inputs, Form Actions, useActionState and useFormStatus
  • React Context and Custom Hooks: Share One Value, Reuse the Logic
  • Server State With TanStack Query: One Key, One Request, One Cache
  • Mutations and Optimistic Updates in TanStack Query: Change Data, Then Tell the Cache
  • Generate TypeScript Types, Query Hooks and Zod From an OpenAPI Spec With Orval
  • A Mock Backend in the Browser With Mock Service Worker, Generated From the Spec
  • A React Client for a FastAPI API: The CORS Wall, CORSMiddleware and the Vite Proxy
  • Forms With React Hook Form and Zod: The API's Rules in the Browser, the Server's Errors Under the Field
  • JWT Auth in a React Client With a FastAPI Backend: Log In, Carry the Token, Let the Server Decide
  1. Blog
  2. /
  3. React
  4. /
  5. Fundamentals

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.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Fundamentals

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

TaskBoard in the light theme: a dark indigo sidebar with Tasks, Team and Reports on the left, and on the right a Today list with three white task cards marked Done in green, Due soon in amber and Overdue in red, and an indigo Add task button.
TaskBoard, rendered from the project's index.html and style.css.

How much of each colour should you use? A simple split works:

The 60-30-10 split 60% neutral 30% brand 10% page and cards sidebar and header accent Add task
Neutral does the quiet work, the brand colour gives personality, and one accent gets the eye.
  • 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); }
Left: TaskBoard with the dark palette, a deep navy page, slate task cards, a green Done badge, an amber Due soon badge, a red Overdue badge and a soft indigo Add task button. Right: the inverted page, with a pale yellow sidebar, a black page, a cyan Overdue badge and an olive Add task button.
Left: the dark palette built on purpose. Right: broken.html with filter: invert(1). That file ships with only the overdue task, so the inverted green and amber badges are not in the picture.

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

  1. About 60-30-10, with one loud accent.
  2. Colours named by job.
  3. Body text at 4.5:1 or more.
  4. Never show status by colour alone. Add a word or an icon, because some people cannot tell red from green.
  5. The dark theme is its own palette, with off-white text.
  6. 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

StepWhat it means
Split it60 neutral, 30 brand, 10 accent
Name itBy job: --primary, --success, --danger
Measure it4.5:1 for body text, 3:1 for large text
Dark themeSame 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.

Keep going in React · 22 of 59

Previous
Visual Hierarchy, Spacing and the 8-Point Grid: Tell the Eye What to Read First
Next post
Typography That Sells: Type Scale, Line Length and Free Font Pairings
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

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

Join free on Skool

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.

On this page

  • Three colour jobs on one page: 60, 30, 10
  • Name a colour by its job, not its look
  • Contrast is a number you can compute
  • Same tokens, new values
  • Break it: dark mode by inverting every colour
  • Before you ship any colour scheme
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

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

Join free on Skool

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)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.