What if I will tell you how we could solve fit-to-width text with pure #CSS without any hardcoded parameters? Curiously, scroll-driven animations will allow us to do just that!

Welcome my new article — “Fit-to-Width Text” — where I continue exploring the experimental implementations of the latest specs.

https://kizu.dev/fit-to-width-text/

Fit-to-Width Text

What if I will tell you how we could solve fit-to-width text with pure CSS without any hardcoded parameters? Curiously, scroll-driven animations will allow us to do just that! Join me as I continue exploring the experimental implementations of the latest specs.

As usual, thanks to @bramus for his view progress timeline ranges visualizer — https://scroll-driven-animations.style/tools/view-timeline/ranges/ :)
View Progress Timeline: Ranges and Animation Progress Visualizer

@kizu @bramus mind blowing! 🤯 🙌

you're mentioning the ability to strip units in calculations: I believe Safari 18.2 has just added it! (previously, a super clever trick by Jane Ori allowed to do it via tan(atan2())).

@pecus @bramus Yep, know about it! Can't wait for other browsers to pick this up as well :)

In the meantime — if you did not see it yet — I have a newer technique for the same result, but which is fully cross-browser (but requires text duplication): https://kizu.dev/fit-to-width/

Fit-to-Width Text: A New Technique

Registered custom properties are now available in all modern browsers. Using some pre-existing techniques based on them and complex container query length units, I solved a years-long problem of fitting text to the width of a container, hopefully paving the path towards a proper native implementation.