Modular Type Scales and Fluid Typography With clamp()
How to build a modular type scale, make headings fluid with CSS clamp(), convert px to rem, and create a spacing system for consistent web design.
&c=%237c3aed&k=developer)
Modular Type Scales and Fluid Typography With clamp()
Great-looking websites use a handful of related font sizes and consistent spacing. That consistency usually comes from simple maths: a modular scale for type and a base unit for spacing. The CSS type scale and unit converter generates both, along with fluid clamp() values.
What a modular scale is
A modular scale starts from a base size, usually 16 px for body text, and multiplies by a ratio for each step up and divides for each step down. With a ratio of 1.25, the steps are 20, 25, 31.25, 39.06 and 48.83 px. Ratios borrow names from musical intervals: 1.2 is a minor third, 1.25 a major third, 1.333 a perfect fourth, 1.5 a perfect fifth and 1.618 the golden ratio.
Choosing a ratio
Dashboards and apps with lots of text and small headings suit modest ratios like 1.125 to 1.2. Marketing pages and long articles can use 1.25 to 1.333 for more dramatic headings. Very large ratios produce huge headings quickly, so they work only with few steps.
Fluid typography
On a phone, a 49 px heading can overwhelm the screen. Fluid typography scales sizes smoothly between a narrow and a wide viewport. CSS clamp(minimum, preferred, maximum) does this without media queries. The preferred value combines rem and vw so the size grows linearly with the screen width. The calculator uses a smaller ratio for narrow screens and a larger one for wide screens, and writes the clamp() for each step.
Why rem matters
Users can change their browser's default font size, often for accessibility. Sizes in rem follow that preference; fixed px sizes do not. The clamp() values use rem for their limits so they respect the user's setting.
Unit conversions
rem = px / root font size. At a 16 px root, 24 px is 1.5 rem. In print-style points, 24 px is 18 pt. As a share of a 1,280 px viewport, 24 px is 1.875 vw. em is relative to the parent element, so it equals rem only when the parent uses the root size.
Spacing systems
Consistent spacing makes layouts feel calm. Choose a base unit, commonly 8 px or 4 px, and use multiples: 4, 8, 12, 16, 24, 32, 48, 64. Designers often match the spacing scale to the line height.
A worked example
With a 16 px base, ratio 1.25 on wide screens and 1.2 on narrow ones, between 375 and 1,440 px, step 4 becomes clamp(2.074rem, 1.944rem + 0.553vw, 2.441rem): 33 px on a phone and 39 px on a desktop.
Putting it in a design system
Copy the values into CSS custom properties such as --step-0 to --step-6, and spacing tokens such as --space-1 to --space-10. Use them everywhere instead of one-off values.
Questions designers ask
How many steps do I need? Most sites need five to seven: small text, body, and four or five heading sizes. Should line height be in units? Use unitless values such as 1.5 so they scale with the font size. Can I use clamp() everywhere? It is supported by all modern browsers. What about very small screens? The minimum value stops text shrinking too far.
Testing
Preview the scale with real content, at the smallest and largest widths, and with the browser zoomed to 200%, which accessibility guidelines require to remain usable.
Limits
Maths gives a starting point, but typefaces differ in apparent size. Check readability on real devices and adjust.


&c=%23c2410c&k=education)
