How I Use CSS Custom Properties for Consistent Theming
My personal site is deliberately small: a landing page, a handful of notes, a few guides, and eventually a portfolio. Small sites fail in a specific way — not by being too plain, but by quietly drifting apart, where the same spacing turns up as 12px on one page and 20px on another, and the accent colour on the contact form no longer matches the one in the header. Custom properties are how I stop that drift. They are the mechanism underneath the restraint you see on screen.
Before I adopted them, every colour was a hex value typed into a rule, and every change meant opening four files and trusting my memory. That worked until the first palette change, which took an afternoon and left two pages behind. Defining the decisions once, at the top of the stylesheet, and letting the cascade carry them down the page is a small idea with a large effect on how calmly the site can be edited.
Theming, in the strict sense, means more than swapping a light palette for a dark one. It means one set of values — ink, paper, accent, spacing, type sizes — that every component borrows rather than invents. When a component needs to look different in a particular spot, that difference should come from the tokens it inherits, not from a fresh rule that overrides them. This is the discipline I want to describe here.
I am writing this partly as a record for myself, because the details get fuzzy after a few months, and partly because other people building small sites ask how I keep things coherent. The notes below cover naming, colour, structure, and the review habits that keep the whole thing from rotting. Nothing here is exotic — it is mostly CSS that has been around for years — but it is the CSS I actually reach for.
Why custom properties became my default
The turning point was moving from a stylesheet I compiled into one I read. Preprocessor variables served their purpose, but they resolve at build time and leave no trace in the browser; a token called --accent is useful to the compiler and invisible once the page loads. A custom property is different: it stays in the document as a live value, inheritable, overridable, and inspectable. I can open devtools on any heading and see the chain of variables that produced its size.
That live quality matters for theming. If I set values on the html element, every element below reads them, and a single attribute change re-skins the page without a reload. I can also flip one token inside a component and watch it apply, which makes experimentation cheap. Trying a warmer paper tone at half past nine on a Tuesday arvo in Melbourne is now a two-minute job, and the tram ride home leaves me with a working version rather than a stash of unmerged branches.
The other advantage is structural. Because custom properties are inherited by default, they can act as scope. A callout can raise its surface colour by redeclaring --surface on itself; a dense section can tighten its rhythm by redeclaring --space-2 inside a container. The cascade does the organising, so I write fewer selectors and fewer overrides. I keep the token sheet short enough to read in one sitting, and I let the page decide where each value lands.
Naming tokens for intent
Naming is where most token systems quietly fail. If tokens are named after appearances — --blue, --grey-200, --red-text — then every rebrand becomes a rename, and the names start lying the moment the palette changes. I name them after jobs instead: --paper, --paper-raised, --ink, --ink-muted, --line, --accent, --accent-ink. A component then asks for what it needs rather than what it happens to look like today, and swapping the accent for something else is a one-line change that leaves every call site untouched.
Spacing gets the same treatment, which took me longer to accept. The temptation is to name space by pixels — --space-12, --space-16 — but pixel names freeze the scale at the moment I wrote them and make it awkward to shift the whole rhythm later. I use a short scale instead: --space-1 through --space-7, each step a multiple of a base unit, with a couple of larger steps reserved for section breaks. Most of my learning about why that rhythm feels right came from studying Apple's whitespace, where the generous gaps in their pages made spacing read as structure rather than leftover.
Type runs on a parallel scale. I keep a fluid base with clamp() between a minimum and a maximum, expressed in rem so it responds to the reader's own settings, and let the tokens carry the step rather than the size. Line height follows the size it belongs to, because a measure of sixty-odd characters wants more leading than a heading with eight words. The payoff is that a change to the scale propagates through headings, captions, and body copy without touching a single component rule.
Colour that survives Australian daylight
Colour is where the local context pushes hardest. Australian light is bright and unforgiving: a phone held outdoors in Sydney at noon washes out, while the same screen in a dim room at night needs very little contrast to stay legible. Melbourne earns its reputation for changing its mind four times a day, so a design that only works at midday is a design that works half the time. I test every palette in the harshest light I can find and in a dim room, and I check that the ink sits on the paper rather than floating above it.
I build palettes in OKLCH where I can, because perceptual lightness is easier to hold steady than a hex value. Picking a hue and then adjusting only the lightness channel keeps a set of blues or greens looking like family members, and the numbers stay readable when someone else edits them. Contrast still gets checked with a proper tool, and colour never carries meaning alone — links are underlined, buttons have labels, states have shapes.
For the accessibility side of this work, I wrote a longer guide on designing for accessibility that covers contrast, focus order, and how to signal state without adding visual clutter. The short version fits here: a visible focus ring costs almost nothing visually and a great deal functionally, especially for people using the keyboard on a shared machine. I keep the ring thin but stubborn — it is not the first thing I would cut.
Theming the site without duplicating rules
The implementation is deliberately boring. One stylesheet holds the token definitions, and every component rule reads from it. Themes are expressed as redeclarations on the root element, keyed by an attribute I can set before paint or toggle later.
:root {
--paper: oklch(97% 0.005 90);
--ink: oklch(22% 0.02 260);
--accent: oklch(52% 0.12 165);
--space-1: 0.5rem;
--space-2: 1rem;
--step-0: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
}
[data-theme="dark"] {
--paper: oklch(18% 0.01 260);
--ink: oklch(93% 0.005 90);
--accent: oklch(72% 0.11 165);
}
body {
background: var(--paper);
color: var(--ink);
padding-block: var(--space-3);
}
Because the palette is just a set of redeclared values, adding a third theme costs a dozen lines. I also set the color-scheme property so form controls, scrollbars, and the browser's own interface match the theme instead of flashing white in a dark page. The same token file then feeds a print stylesheet, where I swap --paper for white and --ink for black and let everything else fall into place.
The site should behave the same on a phone in a taxi on the Parramatta Road as it does on a monitor in a studio. Australian buyers tend to expect prices in dollars with GST included when I sell a guide, and plenty of readers are on regional connections where the NBN might still be copper or a fixed-line backup, so I keep pages light and defer anything heavy until after the text has settled. A quiet page that loads quickly is a feature in itself.
Keeping the system honest
Systems rot quietly. A token gets added for one stubborn component, a one-off value creeps into a rule, and within a few months the stylesheet contains two competing ways of doing the same job. The fix is routine rather than heroic, and the habit that keeps it working for me is a weekly review ritual: I spend part of Friday walking the site as a reader, then twenty minutes with the code. Anything that appears three times becomes a token; anything used once stays local.
The review also catches drift in the other direction: tokens that are declared but no longer used, which I delete. Deleting is easy to skip and rewarding once you start. I re-check the light and dark pairings under changing conditions too, since my own habits shift with the seasons — long bright evenings in December make low contrast hard to spot, and a grey Melbourne winter makes everything look flatter than it is.
Nothing about this approach is permanent, and I don't want it to be. The site is meant to grow slowly, in the way a good printed page does, with occasional revisions and long stretches of calm. Custom properties give me a way to make those changes without rewriting the pages, which is exactly what I want from a personal corner of the web: something I can keep tending without it becoming a full-time job.