
A headline can grow smoothly between phone and desktop sizes without a stack of media queries. clamp() gives it a minimum, a preferred calculation, and a maximum. This example lets you see those bounds by changing the preview width as well as the CSS.
Change the CSS below. The preview updates as you type. Your edits stay in this browser tab.
Resize the preview using the width control, then adjust the minimum, preferred, and maximum sizes.
HTML for this example
<section class="fluid-hero"><span class="eyebrow">A fictional studio</span><h1>Make room<br>for good ideas.</h1><p>A headline that grows with its viewport while staying inside a sensible range.</p></section>
Read the three values from left to right
In clamp(2rem, 1rem + 5vw, 4.5rem), the preferred value grows with the viewport but cannot fall below 2rem or rise above 4.5rem. Combining rem and viewport units keeps a font-relative contribution in that middle value. The preview is an iframe, so its own width controls vw in this demo.
Try the headline with real copy
Increase the middle value to make the size grow more quickly. Change the maximum to see where the headline stops growing. Test a longer heading as well as your shortest one; line-height, letter spacing, and available width affect the result just as much as font size. The example uses a deliberate line break for its particular wording, not a rule for every headline.
Do not let fluid sizing replace zoom testing
A fluid formula is not automatically accessible. Check browser zoom and larger default text settings, including at 200%, and make sure the heading can wrap without clipping. Avoid fixed-height containers around important text. On a real site, preserve the page’s heading hierarchy rather than copying this demo’s h1 into every section.
Reference: MDN on clamp().
Have a client website that needs this kind of attention? See our WordPress development for agencies and case studies.


Leave a Reply