CSS Typography Scale Generator
Build a modular type scale from a base size and a ratio, previewed at every step and output as custom properties in rem with the pixel values commented.
Loading tool…
The CSS is generated by JavaScript in your browser and never leaves the page. There is nothing to upload and nothing is stored.
What the CSS Typography Scale Generator does
Use this CSS typography scale generator to build a modular type scale from a base size and a ratio, previewed at every step and output as custom properties in rem with the pixel values commented. Everything runs inside this page, so the work happens on your own device rather than on a server. It is most often used for defining the type scale for a design system as CSS custom properties. Companion tools to this one live on FreeToolStation.org.
How to use it
- Set the base size — this is your body text, usually 16px.
- Pick a ratio. 1.2 and 1.25 suit interfaces; the wider ones suit editorial layouts.
- Choose how many steps you need above and below the base.
- Copy the custom properties and reference them with var(--text-2) and so on.
How it works
A modular scale multiplies rather than adds. Each step is the one below it times a fixed ratio, so from a 16px base at a ratio of 1.25 you get 20, 25, 31.25, 39.06 and so on, with 12.8 and 10.24 going down. The reason to multiply is that the eye judges type size proportionally: adding 6px per step looks reasonable from 16 to 22 and cramped from 40 to 46, whereas a constant ratio looks even all the way up. That is the entire idea, and it is why the gaps between the large sizes look so much bigger than the gaps between the small ones.
The named ratios come from musical intervals, which is not a coincidence so much as a shared history — both are about perceived proportion. A major second (1.125) and a minor third (1.2) give tight scales that suit interfaces, where a heading needs to be distinguishable from body text without dominating it. A perfect fourth (1.333) or a perfect fifth (1.5) gives the dramatic jumps that suit editorial layouts and landing pages. The golden ratio (1.618) is the widest in common use and runs away fast: five steps up from 16px is already 110px.
Choosing a ratio is really choosing how many steps you can use. A wide ratio gives you two or three usable heading sizes before the numbers become impractical, which is fine for a page with one big headline. A narrow ratio gives you six or seven, which is what a design system with multiple heading levels, captions, labels and small print actually needs. If you find yourself wanting a size between two steps, the ratio is too wide for the design rather than the scale being wrong.
The output is custom properties in rem with the pixel value in a comment, which is the form worth copying into a real stylesheet. rem means the whole scale responds to a reader who has increased their browser font size — one of the few accessibility wins that costs nothing. The comment is there because designers and developers think in pixels and rem values like 1.9531rem are hard to recognise; having both in the file means nobody has to do the division mentally. Naming them by step rather than by role (--text-2 rather than --text-h2) keeps the scale reusable, since the same size is often a heading in one place and a large label in another.
Two caveats. Rounding to whole pixels makes a tidier set of numbers but breaks the exact ratio between adjacent steps, so the evenness that justified using a scale is slightly lost — it is usually worth leaving the fractions alone, since browsers render sub-pixel type perfectly well. And a single scale rarely works at every screen size: a 1.5 ratio that looks right on a desktop is far too dramatic on a phone, where the largest step may be wider than the screen. Either pick a gentler ratio, or pair the scale with fluid clamp values so each step scales with the viewport.
When to use it
- Defining the type scale for a design system as CSS custom properties.
- Choosing a ratio by seeing every step rendered rather than reading numbers.
- Converting an existing pixel scale into rem without doing the division by hand.
- Checking whether a ratio gives you enough usable steps for your heading levels.
- Generating the sizes to feed into a set of fluid clamp declarations.
Common mistakes to avoid
- Adding a fixed number of pixels per step instead of multiplying, which looks uneven.
- Picking a wide ratio and then needing a size between two steps.
- Using a desktop scale unchanged on a phone, where the top steps overflow the screen.
- Outputting px rather than rem, so the scale ignores the reader’s font size setting.
- Rounding every step to whole pixels, which breaks the ratio the scale exists to maintain.
- Naming the variables after roles rather than steps, which stops the same size being reused elsewhere.
Frequently asked questions
What is a modular type scale?
A set of sizes where each is the previous one multiplied by a fixed ratio. From a 16px base at 1.25 the steps are 20, 25, 31.25 and so on. Multiplying rather than adding is what makes the progression look even, because the eye judges type size proportionally.
Which ratio should I use?
1.125 or 1.2 for interfaces, where headings need to be distinct without dominating and you need many usable steps. 1.333 or 1.5 for editorial layouts and landing pages, where the drama is the point. 1.618 is the widest in common use and gives you only two or three practical steps.
Should the output be px or rem?
rem. It means the whole scale grows if the reader has increased their browser font size, which a px scale ignores completely. The pixel value is included as a comment so the numbers are still recognisable.
Should I round the sizes to whole pixels?
Usually not. Rounding gives tidier numbers but breaks the exact ratio between adjacent steps, which is the property that makes the scale look even. Browsers render fractional font sizes perfectly well.
Does one scale work on every screen size?
Rarely. A 1.5 ratio that reads well on a desktop is far too dramatic on a phone, where the largest step can be wider than the screen. Either choose a gentler ratio, or combine the scale with clamp() so each step scales with the viewport.
Why name the variables by step instead of by heading level?
Because the same size is often a heading in one context and a large label or a lead paragraph in another. Naming by step keeps the scale reusable; naming by role ties each size to one use and means you end up defining duplicates.