TR

Home / Guides / How to Make Fluid Font Sizes with CSS clamp(): Formula, Ready Values and Glassmorphism

How to Make Fluid Font Sizes with CSS clamp(): Formula, Ready Values and Glassmorphism

Updated: November 6, 2026 · AracMerkezi

▶ Open CSS clamp() Calculator

For text that grows and shrinks with the screen width, people used to write many media queries. Today a single CSS function, clamp(), solves this in one line in most cases. The real difficulty is not the function itself but calculating the "preferred" value in the middle. This guide derives, step by step, a formula that lets you say "make it this size on a 400 px screen and that size on a 1200 px screen", gives three worked examples and checks the results at different widths. A short section on glassmorphism comes at the very end.

How does clamp() work?

clamp() takes three values: clamp(minimum, preferred, maximum). The browser calculates the preferred value but never lets the result go outside the minimum and maximum. Its logical equivalent is max(minimum, min(preferred, maximum)).

h1 { font-size: clamp(1.5rem, 1rem + 3vw, 3rem); }

In this example the heading is at least 1.5 rem (24 px) when the screen narrows and at most 3 rem (48 px) when it widens; in between it flows with the window width. A 16 px base is assumed.

Why isn't vw alone enough?

If you write only font-size: 4vw, text becomes unreadably small on a small screen and huge on a very wide one. Also, when the user enlarges the browser's font size, a value based only on vw does not respond to it. That is why a rem + vw combination is recommended for the preferred value: 1rem + 3vw. The rem part stays responsive to the user's setting, and the vw part provides the flow.

The formula: a line through two points

The goal is for the size to be S1 at screen width W1 and S2 at W2. The preferred value is the line through these two points:

  1. Slope = (S2 − S1) / (W2 − W1)
  2. vw coefficient = Slope × 100
  3. Constant (px) = S1 − Slope × W1; divide by 16 for rem.
  4. Result: clamp(S1, constant + vw coefficient·vw, S2); don't forget to convert S1 and S2 to rem.

Example 1: Body text, 400 px → 1200 px, 18 px → 32 px

Verification (calculated with Python): at 320 px the raw value is 16.6 px, so it is pinned to 18 px; 24.44 px at 768 px; 28.92 px at 1024 px; 32 px at 1200 px; at 1440 px the raw value is 36.2 px, so it stays at 32 px.

Example 2: Heading, 320 px → 1280 px, 24 px → 48 px

Screen widthCalculated size
320 px24 px
400 px26 px
768 px35.2 px
1024 px41.6 px
1200 px46 px
1440 px48 px

The size reaching the upper limit at 1280 px is the expected result: (48 − 16) / 0.025 = 1280.

Example 3: Spacing, 320 px → 1280 px, 16 px → 64 px

Slope = 48 / 960 = 0.05 → 5 vw; constant = 16 − 0.05 × 320 = 0. Since the constant is zero the formula simplifies: padding: clamp(1rem, 5vw, 4rem);. It is 38.4 px at 768 px and 51.2 px at 1024 px.

Where else is it used besides text?

Accessibility

Browser support

clamp() is supported by all modern browsers. If you target very old browsers, write a fixed font-size first and then add the clamp() line; a browser that does not support it uses the first line.

Common mistakes

Test suggestion

Try the design at 320 px, 768 px and 1440 px widths, and check readability by raising the browser's text size to 200%. If the result reads comfortably on both small and large screens, the formula is working.

Short section: the glassmorphism effect

The "frosted glass" look is achieved with a semi-transparent background and blurring of the content behind it: .card { background: rgba(255,255,255,.18); backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,.3); border-radius: 16px; }. backdrop-filter does not work in some older browsers, so the background should be left opaque enough. Heavy use of blur can affect performance on low-powered devices. Always check the contrast between the text color and the glass surface. For details see How to Make Glassmorphism with CSS.

Tools

If calculating the formula by hand is tedious, the CSS clamp() Calculator generates it for you. To convert between px and rem use the PX REM EM Converter, and to understand the difference use the guide PX, REM and EM Differences. For ready glass-effect code try the Glassmorphism CSS Generator.

Frequently asked questions

What is the clamp() function for?

It keeps a value between a minimum and a maximum limit so that you get a fluid size that follows the screen width.

Why isn't using only vw enough?

Text gets too small on small screens, too big on large ones, and it does not respond to the user's browser font-size setting; combining it with rem is better.

How do I calculate a clamp() value?

Slope = (S2 − S1) / (W2 − W1); the vw coefficient is 100 times the slope; constant = S1 − slope × W1. For 18 px at 400 px and 32 px at 1200 px the result is clamp(1.125rem, 0.6875rem + 1.75vw, 2rem).

Tools mentioned in this guide

More guides

This article is for general information only and is not legal, financial or medical advice. We are not an official institution.