Sub topic 9
Styles, Tokens, and Reusable Components
This chapter assumes you know basic typography vocabulary (typeface, size, weight, line spacing). It also assumes you have used a design or layout tool such as Figma, Canva, Illustrator, or InDesign, and that you can read short CSS snippets. You have already seen repetition as a principle: reuse the same fonts, colors, and spacing so a layout feels like one thing. This chapter covers the mechanisms that make repetition cheap and reliable, so you don't enforce it by hand.
Why repetition needs a system
Repetition fails quietly. You pick a blue for a button on Monday. On Thursday you pick a slightly different blue for a link, because you can't remember the first one. Neither choice is wrong on its own. Together they make the page look unplanned.
A design system fixes this by moving each decision out of individual elements and into one named place. You decide once, give the decision a name, and refer to the name everywhere. Three layers do this work:
- Styles are saved bundles of formatting that you apply to many elements.
- Tokens are named values, such as a color or a spacing step, that styles and components draw from.
- Components are reusable pieces of interface, such as a button or card, that carry their own styles and are placed many times.
Changes flow from left to right. If you edit a token, every style and component that uses it updates, and so does every layout that contains those components.
Styles: saved formatting
A style is a named set of formatting rules. Every layout tool has some version of it:
- InDesign has paragraph styles, character styles, and object styles.
- Figma has text styles, color styles, and effect styles.
- Canva has brand kits with saved fonts and colors.
- CSS has classes and selectors.
The benefit is the same in each tool. You apply the style called "Heading 2" instead of setting a typeface, size, weight, and spacing by hand. If you later decide headings should be slightly larger, you change the style once and every heading follows.
A useful rule is to make the number of text styles small and deliberate. A typical set looks like this:
| Style name | Typical use | Contrast it provides |
|---|---|---|
| Display | One large title per page | Largest size, heaviest weight |
| Heading | Section titles | Larger and bolder than body |
| Body | Paragraph text | Baseline size and weight |
| Caption | Notes, labels, credits | Smaller than body, often a muted color |
Notice that the styles also serve contrast. Each step differs clearly from its neighbors in size or weight, so the hierarchy is built into the set. Repetition and contrast cooperate here: the styles repeat across pages, and the differences between them create the hierarchy.
Tokens: named values
A style bundles several properties. A token is a single value with a name. Tokens come in a few common kinds:
- Color tokens, such as a text color or an accent color.
- Spacing tokens, such as small, medium, and large gaps.
- Type tokens, such as font families and size steps.
- Other tokens, such as corner radius, border width, or shadow.
The key habit is to name tokens by role, not by appearance. A token called --color-accent can change from blue to green without becoming a lie. A token called --blue cannot.
CSS custom properties are the most direct way to write tokens for the web. This is the code example from this tutorial's plan:
:root {
--color-text: #1a1a1a;
--color-accent: #0b5fff;
--space-sm: 8px;
--space-md: 16px;
--space-lg: 32px;
}
body {
color: var(--color-text);
font-family: system-ui, sans-serif;
}
.button {
background: var(--color-accent);
color: #ffffff;
padding: var(--space-sm) var(--space-md);
}
.link {
color: var(--color-accent);
}Read it in two parts. The :root block declares the tokens. Everything below it uses them through var(...). The button background and the link color both point to --color-accent, so they can never drift apart. If you change that one line, both elements change together.
Spacing tokens and proximity
Spacing tokens connect repetition to proximity. In the card example from the proximity chapter, items inside a card sit 8px apart and cards sit 32px apart. Those two numbers match --space-sm and --space-lg. When the same small number is always used for "related" and the same large number is always used for "separate," readers learn the pattern without noticing it. A small set of steps, such as 8, 16, and 32, is easier to keep consistent than free choice of any number.
Many teams build spacing steps from a base unit, such as multiples of 4 or 8. This is a convention, not a rule. What matters is that the steps are few and clearly different from each other. Steps of 15px, 16px, and 17px defeat the purpose, because the eye cannot tell them apart and the rules become noise.
Semantic tokens on top of raw values
Larger systems often use two tiers. Raw tokens hold the values, and semantic tokens say what the values are for.
:root {
/* Raw values */
--blue-600: #0b5fff;
--gray-900: #1a1a1a;
--gray-600: #595959;
/* Roles */
--color-text: var(--gray-900);
--color-text-muted: var(--gray-600);
--color-accent: var(--blue-600);
}Components use only the role names. To rebrand, you change which raw value each role points to. The components stay untouched. The cost is one more layer to maintain, so a small project may not need it.
Components: reusable pieces
A component is a pre-built element with its styles attached. In Figma it is a component with variants. In Canva it is a saved element or template. In code it is a function, class, or partial that renders the same markup each time.
Components apply repetition at a larger scale than styles. A card is more than a font and a color. It is a fixed arrangement of heading, text, spacing, and padding. Placing the same card twenty times guarantees twenty identical arrangements.
Here is a card from the plan, built from the same tokens:
:root {
--space-sm: 8px;
--space-md: 24px;
--space-lg: 32px;
}
.card {
display: grid;
gap: var(--space-sm);
padding: var(--space-md);
max-width: 40ch;
}
.card h2 {
margin: 0;
font-size: 1.5rem;
font-weight: 700;
}
.card p {
margin: 0;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
}
.card + .card {
margin-top: var(--space-lg);
}This card uses all four principles at once. The gap groups heading and text (proximity). The size and weight difference separates them (contrast). The shared .card rules keep every card the same (repetition). The grid places both children on one left edge (alignment).
Variants and overrides
Real interfaces need a primary button and a secondary button. A good component handles this with a defined set of variants, not with one-off edits. In Figma, you add a variant property such as type=primary|secondary. In CSS, you add a modifier class:
.button {
padding: var(--space-sm) var(--space-md);
border: 2px solid var(--color-accent);
background: var(--color-accent);
color: #ffffff;
}
.button--secondary {
background: transparent;
color: var(--color-accent);
}The two buttons share padding, border, and shape, so they read as the same family. They differ in fill, which creates contrast that signals importance. Variants let you vary on purpose while keeping everything else repeated.
Common errors
- Detached instances. In a design tool, you detach a component instance and edit it by hand "just this once." It no longer updates with the system. Do this rarely, and prefer adding a variant.
- Naming by appearance. Tokens named
--big-bluebreak when the design changes. Name by role. - Too many tokens. Fifteen shades of gray and twelve spacing steps give you choice but not consistency. Cut the set until each token has a clear job.
- Hard-coded values beside tokens. One
padding: 13pxin a component that otherwise uses tokens is a small crack that grows. Search for raw numbers and hex codes when you review. - Treating the system as a cage. A system supports repetition. It does not forbid deliberate breaks. A single element that departs from the pattern, such as a promotional banner, draws attention because everything around it repeats.
A short audit workflow
When you inherit a layout, you can measure how well it repeats:
- List every distinct font size, weight, and color you find. Count them.
- List every distinct spacing value between elements.
- Group values that are nearly identical, such as
#0b5fffand#0c60ff. - Decide which value in each group is the intended one.
- Replace the rest with a token or style.
The result is usually a shorter list and a layout that looks calmer, with no change to the content.
Exercise
A page uses #0b5fff for buttons and #0a5cf5 for links. A designer wants to change the brand color to green. Explain what is wrong with the current setup, and describe how tokens would change the work.
Show answer
The two blues are near-duplicates with no recorded reason for the difference, so repetition is broken and the colors only look inconsistent. Changing to green would mean finding and editing every hard-coded value, and it is easy to miss one. With a token such as --color-accent defined once and used by both buttons and links, the designer changes one line and every element follows. The token should be named by role, not by color, so the name stays accurate after the change.
Exercise
You have a .button component and need a less prominent "Cancel" button next to a "Save" button. Which approach keeps the system intact: (a) copy the button and manually change its colors, or (b) add a .button--secondary variant? Name which principle each choice affects.
Show answer
Choose (b). A variant keeps shared padding, border, and shape defined in one place, so repetition holds, and it changes only the fill, which adds contrast between the primary and secondary actions. Copying the button (a) creates a second set of rules that can drift from the original and weakens repetition.