Another use case for CSS functions is allow a font size to grow while ensuring it is at least a minimum size, enabling responsive font sizes while ensuring legibility.
Let's look at some CSS:
h1 {
font-size: 2rem;
}
h1.responsive {
font-size: max(4vw, 2em, 2rem);
}
The font-size will at minimum be 2rems, or twice the default size of font for the page. This ensure it is legible and ensures accessibility
<h1>This text is always legible, but doesn't change size</h1>
<h1 class="responsive">
This text is always legible, and is responsive, to a point
</h1>
Think of the max()
function as finding the minimum value allowed for a property.