If you want to ensure your font-size is fully responsive, consider using the
font-size: clamp(value1, value2, value3)
declaration.
The first value represents the minimum font size - ensuring it never goes below what you specify.
The second value is the preferred font size that the element will aim to use.
The last value signifies the maximum font size limit for the element.
When setting these values, utilizing em
, rem
, or vw
units can provide a completely responsive outcome. The em
unit in particular allows for relative sizing based on parent elements, automatically adjusting when the parent element changes.
For more information on using em
& rem
with the font-size
property, check out this link: https://www.geeksforgeeks.org/difference-between-em-and-rem-units-in-css/
Experiment with different values! Resize your browser window while viewing the example snippet in a new tab to see the impact and versatility of clamp()
.
body {
width: 800px;
font-size: 40px;
}
div {
width: 50%;
font-size: clamp(0.5em, 8vw, 8em);
}
<body>
<div>
Font size
</div>
</body>