Lesson 3 of 9 · 20m
Inheritance, Custom Properties, and Why They Change Everything
What inherits, what doesn't, how `inherit`/`initial`/`unset`/`revert` actually differ, and why custom properties are the one true lever for theming and component APIs.
Half of CSS confusion comes from not knowing which properties inherit and what the global keywords actually do. The other half — once you work on anything with themes or a component library — comes from not understanding how custom properties interact with the cascade. Get both right and whole categories of styling problems disappear.
What inherits (and why you care)
Inherited properties are almost all typography and text behavior: color, font-family, font-size, line-height, text-align, cursor, visibility. Box properties — margin, padding, border, width, background — do not inherit. The practical upshot: set font-family and line-height once on body and stop repeating yourself, but never expect a border on a parent to do anything to a child.
body {
font-family: "Inter", system-ui, sans-serif;
line-height: 1.5;
color: #1f2937;
}That's it — that's the entire typography foundation of most apps. If you find font-family declared in fifteen components, the inheritance model wasn't internalized.
The four keywords nobody can tell apart
inherit— take the parent's computed value, even for non-inheriting properties.initial— the spec-defined default (display: inlinefor most elements, regardless of UA styles).unset— inherit if the property naturally inherits, initial otherwise. Usually what people mean.revert— roll back to the previous cascade origin (your author rule undone, UA stylesheet applies).revert-layerrolls back to the previous cascade layer — invaluable inside layered architectures.
/* a component that wants to be a blank slate inside any context */
.widget a {
color: revert; /* undo author link styles, fall back to UA — usually blue */
}Custom properties: inherit by default, compute late
:root {
--brand: #2563eb;
--surface: #ffffff;
}
[data-theme="dark"] {
--brand: #60a5fa;
--surface: #111827;
}
.button {
background: var(--brand); /* resolved at use time, per element */
}Custom properties inherit like color does — set them high, override them in subtrees. The killer detail: var() is resolved at computed-value time on the element using it, not where the variable was declared. So [data-theme="dark"] on any ancestor re-themes every descendant automatically, with zero additional CSS. This is why custom properties beat Sass variables for theming — Sass variables are compile-time constants; they can't respond to the DOM.
The component-API pattern
.card {
--card-padding: 1rem; /* default, overridable from outside */
padding: var(--card-padding);
}
.card--compact { --card-padding: 0.5rem; }Expose custom properties as the public API of a component. Consumers tune them without piercing the component's internal structure — this is the pattern every mature design system converges on.
Field notes
- Custom properties are case-sensitive:
--Brandand--brandare different. Yes, really. var(--missing, fallback)only uses the fallback if the property is unset or invalid-at-computed-value-time — the fallback does not rescue a value that parses but is wrong for the property.- Registering with
@propertygives custom properties types, defaults, and transitionability — worth it for tokens you animate.
Was this lesson helpful?