<h1>I should scale up and down as viewport size changes, but probably not in Safari.</h1>
/* @link https://utopia.fyi/generator-mk-ii?c=320,14,1.113,1400,17,1.19,6,2, */
:root {
--fluid-min-width: 320;
--fluid-max-width: 1400;
--fluid-screen: 100vw;
--fluid-bp: calc((var(--fluid-screen) - var(--fluid-min-width) / 16 * 1rem) / (var(--fluid-max-width) - var(--fluid-min-width)));
}
@media screen and (min-width: 1400px) {
:root {
--fluid-screen: calc(var(--fluid-max-width) * 1px);
}
}
:root {
--f--2-min: 11.30;
--f--2-max: 12.00;
--step--2: calc(((var(--f--2-min) / 16) * 1rem) + (var(--f--2-max) - var(--f--2-min)) * var(--fluid-bp));
--f--1-min: 12.58;
--f--1-max: 14.29;
--step--1: calc(((var(--f--1-min) / 16) * 1rem) + (var(--f--1-max) - var(--f--1-min)) * var(--fluid-bp));
--f-0-min: 14.00;
--f-0-max: 17.00;
--step-0: calc(((var(--f-0-min) / 16) * 1rem) + (var(--f-0-max) - var(--f-0-min)) * var(--fluid-bp));
--f-1-min: 15.58;
--f-1-max: 20.23;
--step-1: calc(((var(--f-1-min) / 16) * 1rem) + (var(--f-1-max) - var(--f-1-min)) * var(--fluid-bp));
--f-2-min: 17.34;
--f-2-max: 24.07;
--step-2: calc(((var(--f-2-min) / 16) * 1rem) + (var(--f-2-max) - var(--f-2-min)) * var(--fluid-bp));
--f-3-min: 19.30;
--f-3-max: 28.65;
--step-3: calc(((var(--f-3-min) / 16) * 1rem) + (var(--f-3-max) - var(--f-3-min)) * var(--fluid-bp));
--f-4-min: 21.48;
--f-4-max: 34.09;
--step-4: calc(((var(--f-4-min) / 16) * 1rem) + (var(--f-4-max) - var(--f-4-min)) * var(--fluid-bp));
--f-5-min: 23.91;
--f-5-max: 40.57;
--step-5: calc(((var(--f-5-min) / 16) * 1rem) + (var(--f-5-max) - var(--f-5-min)) * var(--fluid-bp));
--f-6-min: 26.61;
--f-6-max: 48.28;
--step-6: calc(((var(--f-6-min) / 16) * 1rem) + (var(--f-6-max) - var(--f-6-min)) * var(--fluid-bp));
}
body {
font-family: system,
BlinkMacSystemFont,
"Segoe UI",
Roboto,
Helvetica,
Arial,
sans-serif,
"Apple Color Emoji",
"Segoe UI Emoji",
"Segoe UI Symbol";
// uncomment this to allow the type to scale on resize in Safari
// min-height: 1vw;
}
h1 {
font-size: var(--step-6);
font-weight: 500;
// min-height: 1vw;
}
View Compiled
/*
So there is this bug in Safari mentioned in Chris's article here: https://css-tricks.com/viewport-sized-typography/#bugs
The tl;dr is that when using viewport units to size text, and you resize the viewport, the text doesn't respond and scale like it's supposed to.
Chris' fix back then was: 'To fix this issue (allow resizing without page refresh) you need to cause a “repaint” on the element.'
Today, the bug report is marked as fixed: https://bugs.chromium.org/p/chromium/issues/detail?id=124331
However, I am now experiencing the same issue when creating fluid typography with viewport units *in CSS custom properties*
This is the most reduced test case. I have a fluid type system generated from utopia.fyi for quick reference. And the resulting font scale is directly applied to the h1. Resizing the viewport in Safari does not resize the h1 with it. Only when the page is refreshed at a specific viewport width does the corresponding width's font size apply.
I took hints from the comments here: https://css-tricks.com/snippets/css/fluid-typography/#comment-1607139
I tried all of the "fixes" mentioned in those comments. Setting font-size to 1vw on a container fixes the issue but of course has unwanted side effects.
So I ended up doing something similar (using a viewport-based unit on a container) that doesn't have a side effect: applying `min-height: 1vw` to the body element, which fixes the issue and makes the type scale fluidly on resize in Safari. If applying the min-height to the body doesn't make the type scale (I've gotten mixed results for no apparent reason!), try applying it to the h1 itself.
*/
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.