There’s a moment when a page stops looking like a student project. It’s rarely one big thing. It’s consistency: the same spacing, two or three colors, a clear type hierarchy, and nothing randomly different.
The tool for consistency is design tokens — named values stored in CSS variables.
CSS custom properties
:root {
--color-ink: #221c46;
--color-brand: #4f46e5;
--color-paper: #faf7f2;
--space-4: 16px;
--radius: 18px;
}
body {
color: var(--color-ink);
background: var(--color-paper);
}
.card {
padding: var(--space-4);
border-radius: var(--radius);
}
--name defines a variable. var(--name) uses it. Change the value once in :root and every use updates. That’s the whole feature — and it’s enough to keep a design consistent.
Color
You don’t need 40 colors. Start with:
- Ink — the main text color (a dark purple-black, not pure black).
- Ink soft — secondary text.
- Brand — the main action color.
- Brand soft — a light tint for backgrounds.
- Accent — one color for highlights (use sparingly).
- Paper / card — the page and surface backgrounds.
- Line — borders and dividers.
- Mint — success or “done” states.
Contrast matters. Body text should have a contrast ratio of at least 4.5:1 against its background. Large text can get away with 3:1. If you’re unsure, run it through a contrast checker. Low-contrast gray-on-gray looks stylish in a mockup and unreadable on a laptop in sunlight.
Typography
Three decisions do most of the work:
- One font family (or a display font + a body font). Don’t use five.
- A type scale. Pick sizes and stick to them: 14, 16, 18, 24, 32, 48.
- Line height. Body text wants around 1.5–1.7. Headings want 1.1–1.3.
Also keep the line length readable: around 45–75 characters. In CSS, max-width: 65ch is a good default for paragraphs.
:root {
--font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}
body {
font-family: var(--font-sans);
font-size: 16px;
line-height: 1.6;
}
h1 {
font-size: clamp(2rem, 5vw, 3rem);
line-height: 1.1;
}
.lede {
font-size: 1.125rem;
max-width: 60ch;
}
Spacing
Pick a scale and use only those values:
:root {
--space-1: 4px;
--space-2: 8px;
--space-3: 12px;
--space-4: 16px;
--space-6: 24px;
--space-8: 32px;
--space-12: 48px;
}
Then spacing decisions become choices between a few values instead of “17px here, 19px there.” The page starts to feel intentional.
Try it
This card uses tokens for everything. Change --color-brand in :root and watch the whole card update.
Edit the code, then hit Run (or Ctrl + Enter) and watch the preview. This is a safe sandbox — you can't break the page.
Give the calculator a design system
the plan's verify stepAdd :root tokens to your style.css: three text colors, a brand color, a background, a line color, a spacing scale, one radius, and a font stack. Replace your hard-coded colors and spacing with var(). Then change the brand color once and confirm the whole page updates.
Check your body text contrast with a contrast checker. If it's under 4.5:1, darken the text or lighten the background.
The mistakes everyone makes
- Too many colors. Three or four is plenty. One accent.
- Low contrast. Light gray body text on white is the classic mistake.
- Every heading the same size. Hierarchy comes from contrast in size and weight.
- Random spacing. 13px, 17px, 21px. Pick a scale.
- A paragraph spanning the whole screen.
max-width: 65ch. - Pure black on pure white. It’s harsh. A dark ink color looks better.
- Color as the only signal. Add text or an icon.
Design tokens are named values in CSS variables.
A small palette + one accent beats a rainbow.
Body text needs 4.5:1 contrast; large text needs 3:1.
One font family, a type scale, and a comfortable line height.
Use a spacing scale: 4, 8, 12, 16, 24, 32, 48.
Next: states, transitions, and polish — hover, focus, disabled, and the small details that make the page feel alive.
Up next
States, transitions, and polish
A button isn't one thing — it's a normal state, a hover state, a focus state, a pressed state, and a disabled state. Learn those, add a little motion, and the page starts to feel alive.