Skip to content

Sample post: placeholder content to show the layout. It will be replaced by real writing.

Fluid type with CSS clamp(), without media queries

Let headings grow with the screen between a set minimum and maximum, using a single line of CSS.

By 1 min readCSS

On this page

Media queries make text jump between sizes. clamp() lets it grow smoothly instead.

The syntax

h1 {
  font-size: clamp(34px, 5.2vw, 54px);
}

Read it as: never smaller than 34px, never larger than 54px, and 5.2% of the viewport width in between.

Pick the middle value

Choose the width where the size should reach its maximum. For 54px at 1040px wide:

54 / 1040 * 100 = 5.2vw

Keep it accessible

A pure vw value ignores the reader's zoom setting. Mixing in rem fixes that:

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

Now the heading still scales with the screen, and it also grows when someone zooms the page.

Sahadat Husain

Developer, Devsdemy

Builds WordPress plugins and web tools, and writes down what worked.

More to read