Md Tarek — Portfolio© 2026

Full-stack Developer

System Design — built to hold up.

dhaka → remote, worldwide

Loading experience

Md TarekTarek
Design

Design Systems That Scale: Typography, Spacing & A11y

By: Md Tarek · 17 Oct 2026

Designer's workspace showing typography scale specimens, spacing grids, and UI component tokens
Designer's workspace showing typography scale specimens, spacing grids, and UI component tokens

Executive Summary & Key Takeaways

A design system is not a component library. It is a decision architecture: a set of constraints that removes thousands of micro-decisions from the product team and replaces them with a small number of documented, testable rules. Component libraries are an *output* of a design system, never the system itself.

  • Typography is math, not taste. Pick a modular ratio (1.125–1.333), derive the scale, then bind line-height *inversely* to font size. Large text needs tight leading; small text needs generous leading.
  • Space is your primary hierarchy signal. Before you add a border, shadow, or color, try adding whitespace. The 4/8pt grid is the cheapest consistency win in the entire stack.
  • Micro-interactions are feedback, not decoration. 100–200 ms for state confirmation, ease-out on entry, ease-in on exit, and animate transform/opacity only to hold 60 fps on mid-tier hardware.
  • Accessibility is a constraint, not a phase. WCAG 2.2 adds Focus Not Obscured (2.4.11) and Target Size Minimum (2.5.8, 24×24 CSS px). Bake these into tokens so compliance is automatic rather than heroic.
  • Token layering is the load-bearing wall. Primitive tokens (raw values) → semantic tokens (intent) → component tokens (scope). Theming, dark mode, and forced-colors support become one-line swaps instead of a refactor.
  • Ship a lint rule, not a guideline. Anything enforced only by documentation will drift within two sprints. Anything enforced by CI will survive.

---

1. The Mathematical Foundations of Type and Space

Modular scales beat vibes

A modular scale generates every type size from a base size and a constant ratio. The ratio *is* the personality of the product.

| Ratio | Name | Character | Best for | |---|---|---|---| | 1.125 | Major Second | Tight, utilitarian | Dense data tools, dashboards | | 1.200 | Minor Third | Balanced, neutral | Most SaaS products | | 1.250 | Major Third | Confident, editorial | Marketing sites, docs | | 1.333 | Perfect Fourth | Dramatic | Landing pages, hero type | | 1.618 | Golden Ratio | Extreme contrast | Display-only, rarely UI |

With a 16 px base and a 1.25 ratio: 16 → 20 → 25 → 31.25 → 39 → 48.8 → 61. Notice the problem: the steps get too large at the top and too coarse at the bottom. The production fix is a dual-scale system — a tighter ratio below the base size (1.125) and a wider ratio above it (1.25). This gives you fine-grained control for captions and labels while preserving dramatic display hierarchy.

Line-height is inversely proportional to size

Leading is not a fixed value; it is a function of line length, font size, and x-height. The practical heuristic:

  • Body (16 px): 1.5–1.6
  • Subheads (24 px): 1.3–1.4
  • Headlines (40 px+): 1.1–1.2
  • All-caps labels: add 0.05–0.1em of letter-spacing

Large text set at 1.5 line-height looks disconnected because the eye perceives the line box as a block, not a line. Tighten as you scale up; loosen as you scale down.

Measure, tracking, and optical alignment

Aim for 45–75 characters per line (roughly 65ch). Beyond 80 characters, return-sweep errors spike and comprehension drops measurably. Tracking should move *inversely* to size too: negative tracking (-0.02em) on display type, neutral on body, positive on small caps.

Fluid type without the chaos

Fluid clamp() sizing removes breakpoint jumps, but unconstrained it destroys the modular relationship. Always clamp the *base* token, then let the scale derive from it, and cap the viewport growth so the ratio holds.

/* ============================================================
   LAYER 1 — PRIMITIVES: raw, context-free values
   ============================================================ */
:root {
  /* Type scale: dual ratio — 1.125 below base, 1.25 above */
  --fs-100: 0.64rem;   /* 10.2px  — micro labels       */
  --fs-200: 0.8rem;    /* 12.8px  — captions           */
  --fs-300: 0.875rem;  /* 14px    — secondary UI       */
  --fs-400: 1rem;      /* 16px    — BODY BASE          */
  --fs-500: 1.25rem;   /* 20px    — lead paragraph     */
  --fs-600: 1.5625rem; /* 25px    — section heading    */
  --fs-700: 1.953rem;  /* 31.25px — page heading       */
  --fs-800: 2.441rem;  /* 39px    — display            */

  /* Space scale: 4px base, geometric — never invent an off-grid value */
  --space-3xs: 0.25rem;  /*  4px */
  --space-2xs: 0.5rem;   /*  8px */
  --space-xs:  0.75rem;  /* 12px */
  --space-sm:  1rem;     /* 16px */
  --space-md:  1.5rem;   /* 24px */
  --space-lg:  2rem;     /* 32px */
  --space-xl:  3rem;     /* 48px */
  --space-2xl: 4rem;     /* 64px */
  --space-3xl: 6rem;     /* 96px */

  /* Motion: duration + easing as tokens, not magic numbers */
  --dur-instant: 80ms;
  --dur-fast:    140ms;
  --dur-base:    220ms;
  --dur-slow:    360ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);    /* enter   */
  --ease-in:  cubic-bezier(0.7, 0, 0.84, 0);    /* exit    */
  --ease-std: cubic-bezier(0.2, 0, 0, 1);       /* move    */
}

/* ============================================================
   LAYER 2 — SEMANTIC: intent, not value. This is what themes swap.
   ============================================================ */
:root {
  --text-body: var(--fs-400);
  --text-label: var(--fs-300);
  --text-heading-lg: var(--fs-700);

  --leading-body: 1.55;
  --leading-heading: 1.15;

  --measure: 68ch;

  --gap-inline: var(--space-2xs);   /* icon <-> label          */
  --gap-stack: var(--space-md);     /* vertical rhythm inside a card */
  --gap-section: var(--space-2xl);  /* between page sections   */
}

/* ============================================================
   FLUID TYPE — clamp the BASE, let the scale derive from it.
   Growth capped at 2.5vw so the ratio stays intact.
   ============================================================ */
html {
  /* 16px at 320px viewport -> 18px at 1280px+, then frozen */
  --fs-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
}

body {
  font-size: var(--text-body);
  line-height: var(--leading-body);
  max-inline-size: var(--measure);
  text-wrap: pretty;   /* avoids orphans; supported in modern engines */
}

h1, h2, h3 {
  line-height: var(--leading-heading);
  letter-spacing: -0.015em;
  text-wrap: balance;  /* evens out heading line lengths */
}

Real-world signal: when a design system lets --space-sm become 13px somewhere in the codebase, the grid has already failed. Enforce it — a Stylelint rule or a token-consumption check in CI turns an 8pt grid from an aspiration into a property.

---

2. Spatial Hierarchy, Density, and Perceptual Grouping

The human visual system groups elements by proximity before it groups them by color, shape, or border. That single fact should drive your entire layout philosophy: space is the primary communication channel, and every border you add is a confession that you under-used it.

The proximity contract

A durable rule for nesting: inner spacing must always be smaller than outer spacing. If a card has padding: 24px and the gap between two cards is 16px, the eye reads the two cards as one unit. This is the most common layout bug in production UIs, and it is invisible in code review because both values are individually reasonable.

Section gap      → 48px   (--space-xl)
  Card gap       → 24px   (--space-md)
    Card padding → 16px   (--space-sm)
      Label↔input gap → 8px   (--space-2xs)

Each level is strictly smaller than the one containing it. That monotonic decrease *is* the hierarchy; you can render it in pure grayscale and it still reads correctly. This is also why minimalist UIs work: strip the shadows and borders, and the spacing ratio still tells the user exactly what belongs to what.

Density modes as tokens, not forks

Enterprise tools need a compact mode and consumer surfaces need a comfortable one. Do not fork the components — swap the semantic space tokens at the root:

[data-density="compact"] {
  --space-2xs: 0.25rem;
  --space-xs:  0.5rem;
  --space-sm:  0.75rem;
  --space-md:  1rem;
  --space-lg:  1.5rem;
  --leading-body: 1.4;
}

Components reference var(--space-sm) and never learn that density exists. *Caveat:* density scaling must not breach WCAG 2.2 SC 2.5.8 — interactive targets stay at or above 24×24 CSS px in every mode.

Optical over mathematical alignment

Optical alignment is where systems earn their keep. Icon glyphs with different visual weights need different paddings to *look* centered even when they are mathematically identical. Crescents, triangles, and circular icons all need nudging. Build an optical-offset token per icon set rather than hand-fixing in each component — otherwise every new consumer reintroduces the bug.

---

3. Micro-Interactions, Motion, and Accessibility as Architecture

The four-part micro-interaction model

Every micro-interaction has: a trigger (user action or system event), rules (what is allowed to happen), feedback (what the user perceives), and loops/modes (what happens on repeat or in edge conditions). Most teams ship the trigger and feedback and forget the rules — which is how you get a submit button that animates twice when a user double-taps.

Duration guidance that holds up in usability testing:

  • 80–140 ms — hover, focus, checkbox, toggle. Above 200 ms these feel laggy.
  • 200–300 ms — enter/exit, dropdown, tooltip, toast.
  • 300–400 ms — modal, drawer, full-surface transition. Above 500 ms, perceived performance tanks even if nothing is slow.

Asymmetric easing is what separates polished from merely animated: `ease-out` on entry (fast start, gentle settle — feels responsive) and `ease-in` on exit (gentle start, fast departure — feels decisive).

Reduced motion means *different*, not *none*

The critical accessibility failure is treating prefers-reduced-motion as an off switch. Users who set it still need state confirmation. Remove the *movement*, keep the *feedback*: swap transforms for instant opacity or color changes.

/* --- Focus: token-driven, WCAG 2.4.11 compliant --- */
:root {
  --focus-ring-width: 2px;
  --focus-ring-offset: 2px;
  --focus-ring-color: var(--color-accent-strong); /* >= 3:1 vs adjacent bg */
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
  border-radius: inherit;
}

/* Never remove the ring. Replace it. */
:focus:not(:focus-visible) { outline: none; }

/* --- Micro-interaction defaults --- */
.btn {
  transition:
    background-color var(--dur-fast) var(--ease-std),
    transform var(--dur-instant) var(--ease-out);
}
.btn:active { transform: scale(0.97); }

/* --- Reduced motion: keep confirmation, drop the travel --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  /* Reintroduce non-motion feedback where it carries meaning */
  .btn:active { transform: none; opacity: 0.85; }
}

/* --- Forced colors (Windows High Contrast): never let theming hide state --- */
@media (forced-colors: active) {
  .btn, .card { border: 1px solid ButtonBorder; }
  .btn[aria-pressed="true"] { background: Highlight; color: HighlightText; }
}

/* --- Contrast preference: users who want more, not less --- */
@media (prefers-contrast: more) {
  :root {
    --color-border: CanvasText;
    --focus-ring-width: 3px;
  }
}

Contrast: WCAG 2 versus APCA

WCAG 2.x contrast ratio (4.5:1 body, 3:1 large text and UI components) is the legal baseline, but it is known to over-credit dark-on-light and under-credit light-on-dark. APCA (Accessible Perceptual Contrast Algorithm, the candidate for WCAG 3) models polarity and spatial frequency. Ship both: meet the 4.5:1 floor for compliance, then tune dark mode with APCA lightness contrast (Lc 75 for body, Lc 60 for large) so dark themes do not look washed out or hammered.

The permanent rule: never encode meaning in color alone. Pair every status color with an icon, label, or pattern. Roughly 8% of men have some form of color vision deficiency — that is not an edge case, it is your user base.

Accessibility as architecture, not audit

When accessibility lives in a spreadsheet, it is a quarterly cleanup. When it lives in tokens, it is a property of the system: --color-text-muted is *defined* to be 4.5:1 against --color-surface in every theme, so a new component cannot accidentally violate it. Then verify with real assistive tech — keyboard-only traversal, NVDA/JAWS on Windows, VoiceOver on macOS/iOS, 400% zoom for SC 1.4.10 reflow, and text-spacing overrides for SC 1.4.12.

---

Pro-Tips & Common Pitfalls

Do this

  • [ ] Define primitives → semantic → component token layers. Only the semantic layer is themed.
  • [ ] Enforce the space scale in CI (Stylelint declaration-property-value-allowed-list or a token-consumption check).
  • [ ] Bind line-height inversely to font size; test at 200% zoom, not just default.
  • [ ] Keep inner spacing strictly smaller than outer spacing at every nesting level.
  • [ ] Use :focus-visible, never :focus alone, and never outline: none without a replacement.
  • [ ] Keep interactive targets ≥ 24×24 CSS px (WCAG 2.2 SC 2.5.8) in *every* density mode.
  • [ ] Animate only transform and opacity; verify on a throttled mid-tier device, not your workstation.
  • [ ] Test the forced-colors and prefers-contrast: more paths — they are where themed UIs break silently.
  • [ ] Run an automated a11y check *and* a manual keyboard sweep. Automation catches roughly a third of real issues.
  • [ ] Version tokens and publish changelogs. A silent token change is a breaking change to every consumer.

Pitfalls to avoid

  • Pitfall: Treating the component library as the design system. Components rot; principles and tokens survive. Document intent, not just usage.
  • Pitfall: Pure black on pure white. #000 on #fff causes halation and eye strain. Use near-black (#111–#1a1a1a) on off-white — it also makes dark mode feel intentional rather than inverted.
  • Pitfall: Copy-pasting a scale you did not derive. A 1.618 golden ratio looks gorgeous in a specimen sheet and collapses the moment you need a 14 px label. Match the ratio to the density of the product.
  • Pitfall: Over-animating to signal craft. Motion that exceeds ~300 ms on a frequent interaction reads as latency. Delight is not the same as delay.
  • Pitfall: Killing all motion under `prefers-reduced-motion`. Feedback disappears along with the animation, and users lose confirmation that their action registered.
  • Pitfall: Dark mode as a CSS inversion. Contrast must be re-verified per theme; inverted borders and shadows almost always fail and look muddy. Re-derive, do not invert.
  • Pitfall: Placeholder-only labels. Placeholders vanish on input, :autofill, and at high zoom — they fail SC 3.3.2 and consistently hurt form completion rates.
  • Pitfall: Guideline-only governance. If a rule is not a lint error, a visual regression test, or a generated type, it will be violated within two sprints. Make it mechanical.