{"id":321421,"date":"2020-09-25T07:24:35","date_gmt":"2020-09-25T14:24:35","guid":{"rendered":"https:\/\/css-tricks.com\/?p=321421"},"modified":"2020-09-25T07:24:37","modified_gmt":"2020-09-25T14:24:37","slug":"linearly-scale-font-size-with-css-clamp-based-on-the-viewport","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/linearly-scale-font-size-with-css-clamp-based-on-the-viewport\/","title":{"rendered":"Linearly Scale font-size with CSS clamp() Based on the Viewport"},"content":{"rendered":"\n
Responsive typography has been tried in the past with a slew of methods such as media queries and CSS Here, we\u2019re going to explore a different way to linearly scale text between a set of minimum and maximum sizes as the viewport\u2019s width increases, with the intent of making its behavior at different screen sizes more predictable \u2014 All in a single line of CSS, thanks to The CSS function The value it returns will be the preferred value, until that preferred value is lower than the minimum value (at which point the minimum value will be returned) or higher than the maximum value (at which point the maximum will be returned).<\/p>\n\n\n\ncalc()<\/code>.<\/p>\n\n\n\n
clamp()<\/code>.<\/p>\n\n\n\n
clamp()<\/code> is a heavy hitter. It\u2019s useful for a variety of things, but it\u2019s especially nice for typography. Here\u2019s how it works. It takes three values: <\/p>\n\n\n\n\n\n\n\n
clamp(minimum, preferred, maximum);<\/code><\/pre>\n\n\n\n