Sub topic 11
Encoding brand rules in templates and design tokens
This chapter assumes you can read the rules in a guideline document, apply logo, color, and type rules by hand, and check contrast against WCAG thresholds. It covers how to move those rules out of the PDF and into files that enforce them.
Why encode rules at all
A rule that lives only in a PDF depends on every designer reading it and remembering it. A rule built into a template or token file is applied by default. The designer has to take a deliberate step to break it.
Encoding helps with three common failures:
- Copied values drift. Someone pastes
#0b3d91into ten files, and later someone types#0b3e91. Nobody notices until the pages sit side by side. - Outdated guidelines persist. When the brand updates its blue, every copied value needs a manual hunt.
- Unwritten rules get lost. "Never use the accent for body text" is easy to forget unless it sits next to the value it constrains.
Encoding does not replace judgment or review. It handles the rules that can be stated exactly, so reviewers spend time on the rest.
Three layers: assets, templates, tokens
These three things solve different problems.
| Layer | What it holds | Example | Typical home |
|---|---|---|---|
| Assets | Approved files that must not be redrawn | Logo SVGs, icon set, approved photos | Shared library or DAM |
| Templates | Pre-built layouts with rules already applied | Slide master, social post frame, letterhead | Figma, InDesign, PowerPoint |
| Tokens | Named values for color, type, spacing | `--brand-color-primary` | CSS, JSON, design tool variables |
Assets and templates are for designers working in tools. Tokens are for both designers and code, because the same name can map to a Figma variable and a CSS custom property.
The loop at the bottom matters. When review finds a gap, the fix goes back into the source and then flows out again. Patching one deliverable leaves the next designer with the same problem.
Writing tokens
A token is a named value with a purpose. Two habits make tokens useful.
Name by role, not by appearance. --brand-color-primary survives a rebrand. --blue-dark becomes a lie the day the brand moves to green.
Store the usage note with the value. A bare hex code tells a teammate what the color is. It does not tell them where it may be used. The JSON below keeps both together:
{
"color": {
"primary": { "value": "#0b3d91", "description": "Main brand blue. Use for headings and primary buttons." },
"accent": { "value": "#f2a900", "description": "Highlights only. Do not use for body text." }
},
"logo": {
"minWidthPx": { "value": 96, "description": "Smallest digital logo width." },
"clearSpace": { "value": "1x logo mark height", "description": "Minimum empty space on all sides." }
}
}Note that the logo rules are in the file too. Not every token becomes a CSS variable. A value like 1x logo mark height is a rule for people and for template construction, and the token file is still the right place to record it.
Consuming tokens in CSS
On the web, tokens become custom properties declared once on :root. Every page then references the names:
:root {
--brand-color-primary: #0b3d91;
--brand-color-accent: #f2a900;
--brand-color-text: #1a1a1a;
--brand-color-background: #ffffff;
--brand-font-heading: "Example Sans", Arial, sans-serif;
--brand-font-body: "Example Serif", Georgia, serif;
--brand-space-unit: 8px;
}
h1 {
font-family: var(--brand-font-heading);
color: var(--brand-color-primary);
}
body {
font-family: var(--brand-font-body);
color: var(--brand-color-text);
background: var(--brand-color-background);
}Changing the primary blue now means editing one line. The fallback fonts (Arial, Georgia) are part of the rule as well. Check whether your guidelines name approved fallbacks, because the font will fail to load for some users.
Generating the CSS from the token file
Maintaining the JSON and the CSS by hand recreates the drift problem. Generate one from the other. This Node script flattens a nested token object into custom properties:
const tokens = {
color: {
primary: { value: "#0b3d91" },
accent: { value: "#f2a900" },
text: { value: "#1a1a1a" },
background: { value: "#ffffff" },
},
space: {
unit: { value: "8px" },
},
};
function flatten(node, path = []) {
if (typeof node.value === "string") {
return [[`--brand-${path.join("-")}`, node.value]];
}
return Object.entries(node).flatMap(([key, child]) =>
flatten(child, [...path, key])
);
}
const lines = flatten(tokens).map(([name, value]) => ` ${name}: ${value};`);
console.log(`:root {\n${lines.join("\n")}\n}`);Running it prints --brand-color-primary: #0b3d91; and the other variables. A node counts as a token when its value is a string, so the script skips numeric values such as minWidthPx. A real pipeline needs to handle those. Tools such as Style Dictionary do this, along with output for iOS, Android, and Figma. The principle is the same: one source, many outputs.
Building templates that carry the rules
A good template makes the correct choice the easy one. Build these in:
- Locked or protected elements. Place the logo in its own layer at the approved size with clear space already built in. In InDesign, put it on a master page. In Figma, use a component with the clear-space margin as an internal frame.
- Styles instead of formatting. Define paragraph styles for H1, H2, body, and caption with the correct typeface, size, and leading. Designers apply styles. They do not set fonts by hand.
- Color swatches only. Replace the default swatch palette with the brand palette. Remove the rest, so a stray color takes effort.
- Grid and margins. Set columns and margins in the file, using the spacing unit from your tokens.
- Placeholder content with real constraints. A headline placeholder that is the longest allowed headline reveals overflow before the client does.
Binding templates to tokens
In Figma, create variables named after your tokens (color/primary) and bind fills and text styles to them. A rebrand then changes the variable, and every bound layer updates. In code, the equivalent is using var(--brand-color-primary) everywhere. A raw hex value in a stylesheet is a defect, because it will not follow the token.
Encoding accessibility
Tokens can hold accessibility rules as well as brand rules. The accent in the example has a stated limit: highlights only, not body text. There is a numeric reason. Dark blue #0b3d91 on white has a contrast ratio of about 10:1, well above the WCAG AA minimum of 4.5:1 for normal text. The accent #f2a900 on white comes to roughly 2:1, which fails even the 3:1 large-text threshold.
Two practical steps follow from this:
- Define paired tokens, such as
color-text-on-primary, so a designer picks a combination that was already checked. Do not leave them to combine any two colors. - Run the contrast function from the accessibility chapter as an automated check on every text and background pair in your token file. Fail the build when a pair below 4.5 is marked for body text.
Common errors
- Too many tokens. Fifty near-identical grays invite misuse. Define the steps the guidelines name and no others.
- Tokens that skip the guidelines. If a token exists that the guideline document does not mention, one of them is wrong. Settle which one before you ship.
- No owner or version. Record who maintains the token file and give it a version number. Designers need to know whether their template is current.
- Templates copied, not linked. A duplicated Figma file stops receiving updates. Use shared libraries or components so changes propagate.
- Treating the template as permission. A template follows the rules for the case it was built for. A new format still needs the guidelines, so use the process from the gaps and conflicts chapter.
Exercise
A teammate's stylesheet contains color: #0b3d91; in thirty places. The brand then changes its primary blue. Name two problems this causes, and describe the fix.
Show answer
The first problem is that all thirty places must be found and edited by hand, and any that are missed leave the old blue on some pages. The second is that the code does not record why the color is used, so a teammate cannot tell whether a given #0b3d91 is the primary color or a coincidence. The fix is to define --brand-color-primary once on :root, replace each raw value with var(--brand-color-primary), and ideally generate the :root block from the token file so there is one source.
Exercise
Your token file defines accent as #f2a900 with the note "Highlights only." A designer proposes using it as body text on a white background. How do you decide, and what do you record?
Show answer
Compute the contrast ratio of #f2a900 against #ffffff. It is roughly 2:1, below the 4.5:1 AA minimum for normal text and below 3:1 for large text, so the proposal fails regardless of the "highlights only" note. Reject it. Record the measured ratio in the token's description so the next designer sees the reason. If a lighter accent use case recurs, add a documented darker accent variant instead of making exceptions.