{"id":373905,"date":"2022-10-07T06:19:23","date_gmt":"2022-10-07T13:19:23","guid":{"rendered":"https:\/\/css-tricks.com\/?p=373905"},"modified":"2022-10-07T06:19:24","modified_gmt":"2022-10-07T13:19:24","slug":"fluid-typography-wordpress-block-themes","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/fluid-typography-wordpress-block-themes\/","title":{"rendered":"Adding Fluid Typography Support to WordPress Block Themes"},"content":{"rendered":"\n

Fluid typography is a fancy way<\/a> of \u201cdescribing font properties, such as size or line height, that scale fluidly according to the size of the viewport\u201d. It\u2019s also known by other names<\/a>, like responsive typography, flexible type, fluid type, viewport sized typography, fluid typography, and even responsive display text.<\/p>\n\n\n\n

Here is an example of fluid typography<\/a> that you can play live (courtesy of MDN documentation<\/a>). CSS-Tricks has covered fluid typography<\/a> extensively as well. But the point here is not to introduce you to fluid typography, but how to use it. More specifically, I want to show you how to implement fluid typography in WordPress 6.1 which recently introduced a fluid type feature directly in the WordPress Block Editor.<\/p>\n\n\n\n\n\n\n\n

Open up your style.css<\/code> file, slap in a style rule with fancy clamp()<\/code>-ing on the font-size<\/code> property, and good to go, right? Sure, that\u2019ll give you fluid text, but to get Block Editor controls that make it possible to apply fluid type anywhere on your WordPress site? That requires a different approach in these block-ified days.<\/p>\n\n\n

Fluid typography support in Gutenberg<\/h3>\n\n\n

Some WordPress theme developers have been using the clamp()<\/code> function to define a fluid font-size<\/code>, in their WordPress themes, even in newer \u201cblock\u201d themes such as Twenty Twenty-Two<\/a>, Twenty Twenty-Three<\/a>, and others.<\/p>\n\n\n\n

But the Gutenberg plugin \u2014 the one that contains experimental development for WordPress Block and Site Editor features \u2014 introduced support for fluid typography starting in version 13.8<\/a>. That opened the door for implementing at a theme level so that fluid type can be applied to specific elements and blocks directly in the Block Editor. CSS-Tricks was even given a shout-out in the Pull Request<\/a> that merged the feature.<\/p>\n\n\n\n

That work became part of WordPress Core in WordPress 6.1.<\/a> Rich Tabor, one of the earlier advocates of fluid typography in the Block Editor says:<\/p>\n\n\n\n

[Fluid typography] is also a part of making WordPress more powerful, while not more complicated (which we all know is quite the challenge). [\u2026] Fluid typography just works. Actually, I think it works great.<\/p><\/blockquote>\n\n\n\n

This Make WordPress post highlights<\/a> the approach taken to support the feature at the block level so that a fluid font size is applied to blocks dynamically by default. There are some benefits<\/a> to this, of course:<\/p>\n\n\n\n