CSS syntax for design systems
The selectors, custom properties and shorthand that keep tokens and components honest in code.

Zander Whitehurst
9 min read
A design system in Figma can look finished and still fall apart the moment it meets a stylesheet. The gap is usually syntax. Designers who can read a rule, a custom property and a state selector can review the code their system lives in, and they can brief an engineer without handing over a screenshot and hoping.
You do not need the whole of CSS. You need the parts that decide whether a token, a component and a theme stay in agreement.
A rule is a decision
A CSS rule has a selector and a set of declarations. The selector says which elements the decision applies to. The declarations say what changes.
.button {
background: var(--action-primary);
color: var(--text-inverse);
padding: var(--space-2) var(--space-4);
border-radius: var(--radius-md);
}
Read it as a sentence. Anything with the class button gets this background, this text colour, this padding and this radius. If a value is a raw hex or a raw pixel, the component has stepped outside the system. If it is a custom property, the system still owns the decision. That is the same idea as semantic tokens: the component asks for a purpose, and the token supplies the value.
Custom properties are the system’s vocabulary
A custom property is a named value you define yourself, written --like-this and read back with var().
:root {
--space-2: 0.5rem;
--space-4: 1rem;
--action-primary: var(--blue-600);
}
[data-theme="dark"] {
--action-primary: var(--blue-400);
}
:root is the page. Defining tokens there means every component can see them. A theme selector further down the file overrides the same names. Components keep calling var(--action-primary). The colour underneath can change without anyone editing the button.
Two syntax details save people hours:
- The fallback.
var(--space-4, 1rem)uses1remonly when--space-4is missing. Useful while a token is being introduced. Dangerous if you leave it in forever, because the fallback hides a missing token. - They inherit. A custom property set on a parent is visible to children. Set a local override on a card and everything inside that card picks it up. That is how a nested surface can shift text colour without a new component.
Selectors that components actually use
Most component CSS stays inside a small set of selectors.
| Selector | What it matches |
|---|---|
| .button | The class on the component |
| .button--primary | A variant, written as a modifier class |
| button:hover | Pointer is over it |
| button:focus-visible | Keyboard focus, and only keyboard focus |
| button:disabled | The control cannot be used |
| button[aria-pressed=true] | A toggle that is on |
:focus-visible is the one I insist on. :focus also fires when someone clicks with a mouse, which is why so many products hide the outline and then fail a keyboard review. The visible-focus selector lets you draw a clear ring for keyboard users and leave mouse clicks quiet.
Attribute selectors are how state that lives in HTML shows up in CSS. aria-expanded, aria-invalid and data-state are all readable without a new class for every combination.
.field[aria-invalid="true"] {
border-color: var(--border-danger);
}
Shorthand, and the order it hides
Shorthand properties pack several values into one line. They are convenient and easy to misread.
.card {
margin: 0 auto;
padding: var(--space-4) var(--space-6);
border: 1px solid var(--border-subtle);
}
margin: 0 auto is top and bottom 0, left and right auto. Two values always mean vertical then horizontal. Four values run clockwise from the top: top, right, bottom, left.
border sets width, style and colour together. If you later write border-color on its own, you override only the colour. If you write border again, you replace all three. I have watched a “small tweak” wipe out a 1px border because someone restated the shorthand.
Cascade, specificity and layers
When two rules disagree, CSS picks a winner. Later rules beat earlier ones when they are equally specific. A class beats an element. An ID beats a class. Inline styles beat almost everything, which is why a design system should almost never ship them.
You can feel this going wrong when a utility class refuses to apply and someone adds !important. That is a symptom. The component stylesheet and the utility layer are fighting, and !important makes the next fight worse.
@layer gives each source a rank so you stop relying on file order:
@layer tokens, components, utilities;
@layer components {
.button { background: var(--action-primary); }
}
Tokens sit at the bottom, components in the middle, utilities on top. A one-off spacing class can still adjust a button, and the button’s own rule stays readable.
Units that survive a type change
Design systems leak when every measurement is a raw pixel.
remfor type and for spacing that should follow the user’s font size.1remis the root font size, usually 16px until someone changes it.pxfor hairline borders and for focus rings, where a fraction of a rem looks odd.%andfrfor layout. A grid column of1frtakes a share of the free space. Percentages are relative to the parent.
.layout {
display: grid;
grid-template-columns: 16rem 1fr;
gap: var(--space-6);
}
If your spacing tokens are already in rem, components should consume the token and stop doing maths in the rule. calc(var(--space-2) + 1px) is a smell. It means the scale does not have the value you need, so add the token.
What to check in review
When a component lands, I read the stylesheet for five things:
- Colours, space, radius and type come from custom properties.
- Hover, focus-visible, disabled and invalid each have a rule.
- Shorthand has not wiped a property someone set on purpose.
- Nothing uses
!importantto beat the system. - Layout uses
rem,%orfr, and borders stay inpx.
That list is short enough to do on every pull request. It is also short enough to hand to an agent. A component that passes it will still look like the system after the next theme, the next brand colour and the next person who has never opened the Figma file.
If you are about to define what those components accept from the outside, component props are the other half of the same contract. The CSS decides how a value looks. The props decide which values a team is allowed to ask for.
Memorisely