Skip to main content
← 🎨 CSS as a design systemΒ·Module B4 Β· Lesson 7
TaskBuild a modular type scale with --scale: 1.25 on :root. Define --text-sm, --text-base, --text-lg, --text-xl, --text-2xl, --text-3xl as multiplications. Apply --text-3xl to h1, --text-2xl to h2, --text-xl to h3, --text-base to body.

Modular scale: typography that feels designed

100 XP7 min
Theory

Pick a ratio, multiply your way up

body  = 1rem
h6    = 1rem Γ— 1.25^1 = 1.25rem
h5    = 1rem Γ— 1.25^2 = 1.563rem
h4    = 1rem Γ— 1.25^3 = 1.953rem
h3    = 1rem Γ— 1.25^4 = 2.441rem
h2    = 1rem Γ— 1.25^5 = 3.052rem
h1    = 1rem Γ— 1.25^6 = 3.815rem

Each step is 1.25Γ— the previous β€” the "Major Third" scale. Headings feel related instead of arbitrary.

Common scales

RatioNameFeel
1.125Major SecondSubtle, dense (good for editorial)
1.25Major ThirdVersatile default
1.333Perfect FourthBold, dramatic
1.5Perfect FifthBig jumps, headlines pop
1.618GoldenClassical

Pick ONE for your project. Stick with it. Suddenly your headings look "designed."

With custom properties

:root {
  --scale: 1.25;
  --text-base: 1rem;
  --text-sm: calc(1rem / var(--scale));         /* 0.8rem */
  --text-lg: calc(1rem * var(--scale));         /* 1.25rem */
  --text-xl: calc(var(--text-lg) * var(--scale));   /* 1.563rem */
  --text-2xl: calc(var(--text-xl) * var(--scale));  /* 1.953rem */
}

h6 { font-size: var(--text-lg); }
h5 { font-size: var(--text-xl); }
h4 { font-size: var(--text-2xl); }

Tailwind's text-sm/-base/-lg/-xl/-2xl is exactly this β€” a 1.25 modular scale baked in.

Sizes that aren't on the scale

If you need a size between two scale steps for one specific component (a hero subtitle), pick the closer one rather than introducing a new value. Discipline matters more than perfection.

πŸ”’

Sign up to start coding

Theory is open to everyone. The interactive editor, live preview, and check are unlocked with a 7-day free trial β€” card required, cancel anytime.

Sign up β€” free trial β†’

First 10 lessons in each track are free. No card needed for those.

← PreviousNext lesson β†’

Get one Python or web tip a day β€” by email

Short, hand-written, no spam. Unsubscribe in one click.