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.β¦