Web development
Scale a heading with CSS clamp
Use clamp to give a heading a fluid preferred size bounded by readable minimum and maximum sizes. Combine relative units so the design can respond to both viewport width and user text settings.
Worked example
HTML example · save as example.html and open in a browser
<style>
h1{font-size:clamp(2rem,1.4rem + 3vw,4rem);line-height:1.15;max-width:18ch}
main{padding:1rem}
</style>
<main><h1>Practical guides for everyday development</h1></main>How it works
The first value establishes the lower bound and the third the upper bound. The middle calculation grows with viewport width while retaining a relative-text component. A constrained line length lets a large title break into intentional, readable lines.
Limits and mistakes
Fluid sizing is not a substitute for checking zoom and long translations. Pure viewport-only sizing can respond poorly to text enlargement. Avoid forcing a fixed height around a heading that may wrap to extra lines.
Check the result
Resize the page and confirm the font changes smoothly within the bounds. Test browser zoom and a longer title, ensuring neither clipping nor overlap appears.
Sources
Reference documentation for the behavior used in this guide: