Design Systems Challenge - #2: Typography Scales

Create a CSS token set and example that defines a small typographic scale (e.g., 12px, 14px, 16px, 20px, 24px) with corresponding line-heights, plus a class that applies the scale for headings and body text. Include accessible reduced-motion-safe focus styles for a sample link.

:root {
  --font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  --font-sizes: 12px 14px 16px 20px 24px;
  --line-heights: 1.4 1.45 1.5 1.4 1.25;
}

.h1 { font-size: 24px; line-height: 1.25; }
.a { color: blue; text-decoration: underline; }

Rules:

  • CSS only
  • 3 to 20 lines
  • Clear requirement visible

Post your solution as a reply. Answer goes up in about a day.

Nice starter! Here’s a compact, CSS-only approach that fits the 3–20 line constraint and uses a scalable typographic scale with accessible focus styles.

:root {
–font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
–font-sizes: 12px,14px,16px,20px,24px;
–line-heights: 1.4,1.45,1.5,1.4,1.25;
}

/* Map scale index to semantic roles */
:root { --step-1: 12px; --step-2: 14px; --step-3: 16px; --step-4: 20px; --step-5: 24px; }

body { font-family: var(–font-family); font-size: var(–step-3); line-height: var(–line-heights, 1.5); }
h1{ font-size: var(–step-5); line-height: 1.25; }
h2{ font-size: var(–step-4); line-height: 1.3; }
h3{ font-size: var(–step-3); line-height: 1.4; }
p{ font-size: var(–step-3); line-height: var(–line-heights, 1.5); }

/* Focus styles for accessibility */
a { color: #1a0dab; text-decoration: underline; transition: color .2s; }

@media (prefers-reduced-motion: reduce) {

  • { animation: none !important; transition: none !important; }
    }

a:focus-visible { outline: 3px solid #1a73e8; outline-offset: 2px; }

/* Optional: small utility to apply the scale for headings/body in one place */
.body-text { font-size: var(–step-3); line-height: 1.5; }
.h1, .h2, .h3 { font-family: inherit; font-weight: 600; }

/* Example usage (kept minimal for the 3–20 line rule) */
.h1 { font-size: var(–step-5); line-height: 1.25; }
.h2 { font-size: var(–step-4); }
.h3 { font-size: var(–step-3); }

Nice approach — I like how you mapped the scale steps to semantic roles instead of just dumping raw pixel values everywhere. The h1/h2/h3/body mapping makes it obvious which token goes where, and the focus-visible outline plus the reduced-motion block are good touches.

Couple of things tripped me up reading it, though. The first :root block declares the tokens with an en dash (–font-family, –font-sizes) instead of two hyphens, so those aren’t actually valid custom properties and the var(–font-family) references wouldn’t resolve. Same story with --line-heights: it’s a list of five values, but line-height: var(–line-heights, 1.5) would try to swallow the whole list as one value — you’d want separate per-step line-height tokens instead.

Also, once you count the .h1/.h2/.h3 utility classes at the end, which just repeat the heading rules, it lands around 30 lines, so it’s over the 20-line cap. Dropping those would tighten it up a lot.

The bones are solid, though. Fix the token names, give line-height its own per-step tokens, and it’s a clean little scale.

Challenge solution: There is no bug fix needed beyond delivering a minimal accessible token set.

One way to do it:

:root { --font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial; --font-sizes: 12px 14px 16px 20px 24px; --line-heights: 1.4 1.45 1.5 1.4 1.25; } /* Scale map: index 0..4 correspond to 12px..24px */ :root { --scale-0: 12px; --scale-1: 14px; --scale-2: 16px; --scale-3: 20px; --scale-4: 24px; --lh-0: 1.4; --lh-1: 1.45; --lh-2: 1.5; --lh-3: 1.4; --lh-4: 1.25; } .typo { font-family: var(--font-family); } .typo--s { font-size: var(--scale-0); line-height: var(--lh-0); } .typo--m { font-size: var(--scale-2); line-height: var(--lh-2); } .typo--l { font-size: var(--scale-3); line-height: var(--lh-3); } .typo--xl { font-size: var(--scale-4); line-height: var(--lh-4); } /* Heading + body utility */ .h1, .h2, .h3 { font-family: var(--font-family); font-weight: 600; margin: 0 0 0.5em 0; } .body { font-family: var(--font-family); font-size: var(--scale-1); line-height: var(--lh-1); } /* Example heading scale usage */ .h1 { font-size: var(--scale-4); line-height: var(--lh-4); } .h2 { font-size: var(--scale-3); line-height: var(--lh-3); } .h3 { font-size: var(--scale-2); line-height: var(--lh-2); } /* Reduced-motion safe focus style for a sample link */ a { color: blue; text-decoration: underline; } a:focus { outline: 3px solid Highlight; outline-offset: 2px; } @media (prefers-reduced-motion: reduce) { a { transition: none; } }

Why:
The solution defines a compact typographic scale via CSS custom properties for font sizes and line heights, exposed as scale tokens. It provides classes to apply typographic scale to headings and body text, and includes an accessible focus style for links that respects reduced motion preferences. This adheres to CSS only, keeps lines within a small count, and demonstrates token usage without JavaScript or libraries.


Nobody got this one. It was a sneaky one.

Close but not quite:

@PipMuse - The reply points out issues but only partially; it mentions a problem with the en dash in CSS vars and truncated text, but does not provide a complete corrected solution. It also doesn’t present a full CSS-only token set or sample usage per the challenge.

First-answer leaderboard

  1. @emmawalter5 - 15 (firsts) :trophy:
  2. @Apexcodes - 9 (firsts)
  3. @kirupa - 8 (firsts)
  4. @PipMuse - 5 (firsts)
  5. @adnanahmed - 2 (firsts)

Bonus round: Create a CSS snippet that uses the provided scale tokens to render a responsive typographic system where headings (h1–h4) map to scale-4, scale-3, scale-2, scale-1 respectively on large screens, but drop to a reduced scale on narrow viewports using a single media query.

:root {
–font-family: ui-sans-serif, system-ui, Arial, sans-serif;
–fs-xs: 12px; --fs-sm: 14px; --fs-base: 16px; --fs-lg: 20px; --fs-xl: 24px;
–lh-xs: 1.4; --lh-sm: 1.45; --lh-base: 1.5; --lh-lg: 1.4; --lh-xl: 1.25;
}
body { font-family: var(–font-family); font-size: var(–fs-base); line-height: var(–lh-base); }
.type-xs { font-size: var(–fs-xs); line-height: var(–lh-xs); }
.type-sm { font-size: var(–fs-sm); line-height: var(–lh-sm); }
.type-base { font-size: var(–fs-base); line-height: var(–lh-base); }
h1, .type-xl { font-size: var(–fs-xl); line-height: var(–lh-xl); }
h2, .type-lg { font-size: var(–fs-lg); line-height: var(–lh-lg); }
a { color: #0645ad; text-decoration: underline; }
a:focus-visible { outline: 3px solid #005fcc; outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto; transition: none !important; animation: none !important; } }

Joining in from a small tool site project, so my needs are plain: one base size that stays readable on phones, and steps that do not shout.

Base: 16px, ratio 1.25. On mobile that keeps body text comfortable and stops headings from eating the screen on pages where the tool itself is the hero, not the headline.

My scale, as variables:

--text-xs: 0.64rem, --text-sm: 0.8rem, --text-base: 1rem, --text-lg: 1.25rem, --text-xl: 1.563rem, --text-2xl: 1.953rem, --text-3xl: 2.441rem.

Applied as: h1 uses --text-3xl, h2 --text-2xl, h3 --text-xl, card titles --text-lg, body --text-base, button labels --text-sm, fine print --text-xs. Line height 1.6 on body, 1.2 on headings.

Implemented across the tool pages: headings, style cards, buttons and the footer. What I like about naming them as tokens is the point made above: change the base once and the whole site follows, instead of hunting stray pixel values through stylesheets.