# Typography system

> How to define the typography foundation of a design system: font families and fallbacks, a type scale, role-based text styles, responsive and fluid type, tokens, multilingual support and documentation.

Web page: https://odeocreative.me/tutorials/design-systems/typography
Author: Hecham Gazhi (https://odeocreative.me)

Track: [Design System Tutorial](/md/tutorials/design-systems.md)

## What a typography system defines

A typography system turns type choices into a small, named set of styles that everyone uses. Without it, every designer picks sizes by eye and every developer adds a new font-size, and soon a product has 30 slightly different text styles.

- **Font families** and fallbacks for each language and use (UI, headings, code).
- **A type scale** — the allowed sizes.
- **Weights** — usually 3–4.
- **Line heights and letter spacing** for each size.
- **Text styles** — named combinations, by role.
- **Responsive rules** — how sizes change across breakpoints.

## Font families and fallbacks

| Token | Use | Example stack |
| --- | --- | --- |
| font-family-sans | UI and body text | "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif |
| font-family-display | Large headings (optional) | A characterful brand font |
| font-family-arabic | Arabic text | "IBM Plex Sans Arabic", "Noto Sans Arabic", Tahoma, sans-serif |
| font-family-mono | Code, IDs, tabular data | "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace |

> Tip: Always define fallbacks. Web fonts take time to load; a good fallback stack with similar proportions reduces layout shift. In CSS, `font-display: swap` shows fallback text immediately instead of invisible text.

## The type scale

Choose a base size (16px) and a ratio, then round to whole numbers and adjust by eye. Keep the number of sizes small — 8 to 10 is usually plenty.

| Token | Size | Line height | Typical use |
| --- | --- | --- | --- |
| font-size-100 | 12px | 16px | Captions, badges |
| font-size-200 | 14px | 20px | Secondary text, dense tables |
| font-size-300 | 16px | 24px | Body text |
| font-size-400 | 18px | 28px | Large body, lead text |
| font-size-500 | 20px | 28px | Small headings |
| font-size-600 | 24px | 32px | Section headings |
| font-size-700 | 30px | 38px | Page headings |
| font-size-800 | 36px | 44px | Large page headings |
| font-size-900 | 48px | 56px | Display, hero |

## Text styles by role

Designers and developers shouldn't combine size, weight and line height themselves. Instead, the system offers **composite text styles** named by role. Each style is a token that bundles family, size, weight, line height and letter spacing.

**Do**

- Name styles by role: heading, body, label, caption.
- Include a label style for buttons and form labels.
- Separate visual style from semantic HTML level (an h2 can use heading-sm).
- Use the same names in Figma text styles and code.

**Don't**

- Name styles by size: `text-24-bold`.
- Allow custom font sizes outside the scale.
- Tie styles to HTML tags so h1 must always be huge.
- Create separate styles for every colour of text — colour is a separate token.

```css
.text-display    { font: 600 3rem/1.15 var(--font-family-sans); letter-spacing: -0.02em; }
.text-heading-xl { font: 600 2.25rem/1.2 var(--font-family-sans); letter-spacing: -0.01em; }
.text-heading-lg { font: 600 1.875rem/1.25 var(--font-family-sans); }
.text-heading-md { font: 600 1.5rem/1.3 var(--font-family-sans); }
.text-heading-sm { font: 600 1.25rem/1.4 var(--font-family-sans); }
.text-body-lg    { font: 400 1.125rem/1.55 var(--font-family-sans); }
.text-body       { font: 400 1rem/1.5 var(--font-family-sans); }
.text-body-sm    { font: 400 0.875rem/1.45 var(--font-family-sans); }
.text-label      { font: 500 0.875rem/1.3 var(--font-family-sans); }
.text-caption    { font: 400 0.75rem/1.35 var(--font-family-sans); }
.text-code       { font: 400 0.875rem/1.5 var(--font-family-mono); }
```

## Responsive and fluid type

Large headings that work on desktop are often too big on phones. Two common approaches:

### Stepped

Each text style has different sizes at different breakpoints, e.g. display is 36px on mobile and 48px on desktop.

### Fluid

Sizes scale smoothly with viewport width using CSS `clamp()`, with a minimum and maximum.

```css
/* 36px on small screens → 56px on large screens */
.text-display { font-size: clamp(2.25rem, 1.5rem + 3vw, 3.5rem); }
```

> Tip: Body text usually stays the same size across breakpoints. It's headings and display text that benefit most from responsive sizing.

## Multilingual typography

- Define fonts per script and pair them for similar weight and x-height.
- Arabic text often needs a slightly larger size and taller line height to match the visual weight of Latin text — define language-specific overrides for text styles.
- Never apply letter spacing to Arabic.
- Uppercase styles don't exist in Arabic — avoid using `text-transform: uppercase` to communicate meaning.
- Test text styles with real translations, including long German words and mixed Arabic/Latin content.

```css
:root[lang="ar"] {
  --font-family-sans: "IBM Plex Sans Arabic", "Noto Sans Arabic", sans-serif;
}
:root[lang="ar"] .text-body { line-height: 1.75; letter-spacing: 0; }
```

## Accessibility in the type system

- Use **rem** units so text scales with the user's browser setting.
- Keep body text at 16px or larger; avoid 12px for anything important.
- Support zoom up to 200% without loss of content (WCAG 1.4.4) and text-spacing adjustments (WCAG 1.4.12).
- Make sure text colour tokens meet contrast with every surface they're used on.
- Respect platform text-size settings (Dynamic Type on iOS, font scale on Android) in native apps.

> Common mistake: Fixing heights on text containers (buttons, cards) so that larger text or longer translations get cut off. Let containers grow with their content.

## Key takeaways

- A typography system defines families, a scale, weights, line heights and named text styles.
- Keep 8–10 sizes and bundle them into role-based composite styles.
- Separate visual style from HTML heading level.
- Use stepped or fluid (clamp) sizing for headings across breakpoints.
- Plan for multiple scripts and accessibility: rem units, zoom, contrast, no fixed text heights.

## Exercise: Define a type system

1. Choose a Latin font, an Arabic companion and a monospace font with fallbacks.
2. Create a 9-step type scale with line heights on a 4px grid.
3. Define 10 role-based text styles as Figma text styles.
4. Write the same styles in CSS with a fluid display size using clamp().
5. Test them with an English and an Arabic version of the same screen.

## Quiz

1. Which is a better text style name in a design system?
   - text-24-bold
   - **heading-md** ✓
   - big-title-blue
   - font-3
   - Why: Role-based names survive changes to size and weight.

2. Why define fallback fonts?
   - To look different on each device
   - **So text shows and keeps similar proportions while web fonts load or if they fail** ✓
   - Browsers require exactly three
   - To save licence costs
   - Why: Fallbacks reduce invisible text and layout shift.

3. What does CSS clamp() enable for typography?
   - Bold text
   - **Fluid sizes between a minimum and maximum** ✓
   - Text truncation
   - Arabic support
   - Why: clamp(min, preferred, max) scales sizes smoothly with the viewport.

4. Should an h2 always use the same visual style?
   - Yes, always
   - **No — visual style and semantic level are separate** ✓
   - Only on mobile
   - Only in dark mode
   - Why: Semantics serve structure; visual styles serve hierarchy on each screen.

5. Why avoid fixed heights on text containers?
   - They're slow
   - **Larger text settings and longer translations get cut off** ✓
   - Figma doesn't support them
   - They break colours
   - Why: Containers must grow with content for accessibility and localisation.
