A modular scale calculator generates a mathematically harmonious sequence of sizes — most commonly used for typography — by starting from a single base value and multiplying it by a fixed ratio at each step. The resulting sizes feel visually related because they share the same mathematical relationship, the same principle that makes notes in a musical scale sound like they belong together.
How it works
The core formula is simple:
value(n) = base × ratio^n
- base is your starting size (typically 16 px, the browser default body text size).
- ratio is a multiplier greater than 1 — for example 1.5 for a Perfect Fifth.
- n is the signed step index: 0 equals the base, positive integers go up (larger sizes for headings), negative integers go down (smaller sizes for labels and captions).
Every named ratio in the selector corresponds to a classical musical interval. The Perfect Fifth (3:2 = 1.500) means the frequency of the higher note is exactly 1.5 times the lower one. Applied to type, it means each heading level is 1.5 times larger than the one below it.
Worked example
Suppose you set base = 16 px and ratio = Perfect Fifth (1.500):
| Step | Formula | Value |
|---|---|---|
| -2 | 16 × 1.5^-2 | 7.11 px |
| -1 | 16 × 1.5^-1 | 10.67 px |
| 0 (base) | 16 × 1.5^0 | 16.00 px |
| +1 | 16 × 1.5^1 | 24.00 px |
| +2 | 16 × 1.5^2 | 36.00 px |
| +3 | 16 × 1.5^3 | 54.00 px |
| +4 | 16 × 1.5^4 | 81.00 px |
These map naturally to: micro labels, small captions, body text, large body / lead, subheading, section heading, page title, hero heading.
If your root font-size is 16 px, step +2 (36 px) converts to 2.25 rem — convenient for a CSS custom property or Tailwind fontSize entry.
Formula note
Because ratio^n is an exponential function, steps increase faster at larger n. This is intentional: the perceptual difference between 16 px and 24 px feels similar to the difference between 54 px and 81 px because human perception of size is roughly logarithmic (Weber–Fechner law). A modular scale therefore produces steps that appear equally spaced to the eye even though the absolute pixel differences grow.
The calculator also shows the binary logarithm of the ratio (log₂(ratio)), which tells you how many semitones the ratio is equivalent to in an equal-tempered 12-tone scale. For the Perfect Fifth that is approximately 7 semitones; for the Golden Ratio it is about 0.694 octaves.
Choosing a ratio
- Minor Second (1.067): Very small steps — useful for dense spacing tokens or tight line-height ladders.
- Major Second (1.125): Still compact, popular for spacing systems.
- Minor Third (1.200): Moderate contrast, works well for both type and spacing.
- Major Third (1.250): A classic choice for sites needing a confident but not dramatic type ramp.
- Perfect Fourth (1.333): Strong contrast between heading levels; popular in editorial design.
- Perfect Fifth (1.500): The most widely recommended for web typography; easy to scan heading hierarchy.
- Golden Ratio (1.618): High drama; works best for landing pages with few heading levels.
- Octave (2.000): Each step doubles the previous — creates very bold hierarchies with only 3–4 usable steps.
Exporting the scale
The tool generates ready-to-paste code in three formats:
- CSS custom properties — paste into
:root {}and reference withvar(--text-+3)etc. - Tailwind config — paste into
theme.extend.fontSizeintailwind.config.js. - SCSS variables — use
$text-p3(positive step) or$text-n2(negative step) throughout your stylesheets.