CSS’s clamp()
has been around for a few years now, but I finally got to use it in the rebuilding of this site. Let’s look at the hero text block on my new homepage!
:root {
--font-size--dynamic-headline-3: clamp(21px, 4vw, 36px);
--vertical-spacing-5: clamp(36px, 8vw, 72px);
}
.b--homepage-hero {
max-width: 60ch;
margin: 0 auto var(--vertical-spacing-5);
font-family: Parkly, sans-serif;
font-size: var(--font-size--dynamic-headline-3);
text-transform: uppercase;
& p {
color: rgb(0 0 0 / 60%);
text-align: center;
& strong {
font-family: "Parkly Wide", sans-serif;
color: rgb(0 0 0 / 75%);
text-transform: uppercase;
}
}
}
I’ve got the two variables included too. Okay, so the Dynamic Headline 3 variable is defined as clamp(21px, 4vw, 36px)
. Minimum, preferred, and maximum. The browser then makes the decision for us. Now one has to be mindful of that middle. It can be a somewhat arbitrary relative value if your clamp is tight, but if you have multiple headlines of varying sizes— like any typographer is going to— you need to make these numbers proportionate. Let’s look.
:root {
--font-size--dynamic-headline-1: clamp(43px, 8vw, 72px);
--font-size--dynamic-headline-2: clamp(32px, 6vw, 54px);
--font-size--dynamic-headline-3: clamp(21px, 4vw, 36px);
--font-size--dynamic-headline-4: clamp(21px, 3.1vw, 28px);
--font-size--dynamic-headline-5: clamp(21px, 2.65vw, 24px);
--font-size--dynamic-copy: clamp(16px, 2vw, 18px);
--font-size--dynamic-small: clamp(14px, 1.78vw, 16px);
}
Dynamic Headline 2 is 50% larger than Dynamic Headline 3. That applies to the min, pref, and max. But at the smallest sizes, Dynamic Headline 3, Dynamic Headline 4, and Dynamic Headline 5 are all the same. They got too small otherwise.
As we allow our pages to be more fluid with dynamic grids, flexbox, and clamps, we have to let go of some of our pixel precision in design. Almost all the fonts— and vertical spacing!— on this site are dynamic with clamp()
. The header, I think, is the only thing that isn’t.