Menu

1 / 5

Fluid sizes with CSS clamp(): practical examples you can copy

DEV Community: css·OSV Studio·15 days ago
#u2FW0B5K
#devtocss#devto#dev#clamp#calc
Reading 0:00
15s threshold

Media queries make values jump: 16px, then suddenly 20px, then 24px. Fluid values grow smoothly with the screen instead. In modern CSS, one line does it:

font-size : clamp ( 16 px , calc ( 10 . 66667 px + 1 . 48148 vw ), 32 px );

Enter fullscreen mode

Exit fullscreen mode

This post shows how to read declarations like this, gives you ready-made examples, and covers the mistakes that quietly break them.

How to read a clamp() declaration

clamp() takes three arguments:

clamp ( minimum , preferred , maximum )

Enter fullscreen mode

Exit fullscreen mode

minimum : the value never goes below this (16px above)

preferred : the part that changes with the viewport ( calc(… + …vw) )

maximum : the value never goes above this (32px above)

The example above means: 16px on a 360px screen, 32px on a 1440px screen, smooth growth in between , and it stays at 16px or 32px outside that range. No media queries needed.

The numbers in the middle look odd, but you don't need to touch them by hand.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.