Menu

Fluid type in Tailwind CSS with clamp(), plus 7 sizes you can copy
πŸ“°

Fluid type in Tailwind CSS with clamp(), plus 7 sizes you can copy

DEV Community: tailwindcssΒ·AppyGridΒ·3 days ago
#3jwGNFMJ
#devtotailwindcss#devto#dev#clamp#875rem
Long article (858 words) β€” no AI summary yet.
Reading 0:00
15s threshold

Most responsive headings I come across look like this:

<h1 class = "text-3xl md:text-4xl lg:text-5xl" >

Enter fullscreen mode

Exit fullscreen mode

It works. But resize the window slowly and you'll see the heading snap at 768px and again at 1024px. In between, it's always a little too big or a little too small for the space it's in.

clamp() fixes that with one class and no breakpoints:

<h1 class = "text-[clamp(1.875rem,1.4789rem+1.6901vw,3rem)]" >

Enter fullscreen mode

Exit fullscreen mode

That heading is 30px on a 375px phone, 48px on a 1440px laptop, and grows in a straight line in between.

What clamp() is doing

font-size : clamp ( MIN , PREFERRED , MAX ) ;

Enter fullscreen mode

Exit fullscreen mode

The browser uses the preferred value, but never goes below the minimum or above the maximum.…

Continue reading β€” create a free account

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