pwshub.com

CSS font-size-adjust is now in Baseline

Stay organized with collections Save and categorize content based on your preferences.

Rachel Andrew

The CSS font-size-adjust property lands in Chrome today, and becomes part of Baseline Newly Available. This property can help prevent shifting of your layout when fallback fonts are loaded, and ensure legibility of fallback fonts at smaller font sizes. The font-size-adjust property is part of Interop 2024, so this is another win for the effort to improve the interoperability of the web platform.

The problem

When you compare two fonts set to the same size, depending on the shape and size of the glyphs, the displayed text can take up a very different amount of space. As an example, the following demo shows text in Verdana and Arial, both set to 16 pixels.

Text displayed at 16px in Verdana and Arial.

The difference in size is accounted for by the fact that the aspect value, the height of lowercase letters when compared to uppercase letters in a font, varies between fonts.

This can cause two problems when a font with a different aspect value is used as a fallback. Firstly the amount of space taken up by the font will change. Secondly, your choice of fallback font may be less legible then the one first specified, particularly at small font sizes. This is because the relative height of lowercase letters to uppercase ones is a key factor in legibility.

How font-size-adjust helps

The font-size-adjust property lets you adjust your fallback font to better match the first font. The following example shows the two fonts shown previously, this time the second font has been adjusted to match the first.

Using font-size-adjust.

This example uses a single value, a number, which adjusts the fonts using the default font metric of ex-height. This is the ratio of the x-height, the height of a lowercase x in the font to font size. You can also specify the font metric used. In the next example, I have normalized the fonts using the ch-width keyword, in addition to the number.

Using font-size-adjust with the ch-width font metric.

To see all possible values see the MDN documentation for font-size-adjust.

It's worth looking at your site using your fallback font and seeing if a little tweak with font-size-adjust can help readers who are using the fallback font have a better experience, especially now it's available everywhere!

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-07-23 UTC.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"Missing the information I need" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"Too complicated / too many steps" },{ "type": "thumb-down", "id": "outOfDate", "label":"Out of date" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"Other" }] [{ "type": "thumb-up", "id": "easyToUnderstand", "label":"Easy to understand" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"Solved my problem" },{ "type": "thumb-up", "id": "otherUp", "label":"Other" }]

Source: web.dev

Related stories
1 month ago - Discover some of the interesting features that have landed in stable and beta web browsers during July 2024.
1 month ago - HELLO EVERYONE!!! It’s July 26th 2024 and you are reading the 21th edition of the Codeminer42’s tech news report. Let’s check out what the tech …
1 month ago - MUI is one of the largest and best-known UI component libraries. Learn what it is, its benefits and features, and why you should use it. The post MUI adoption guide: Overview, examples, and alternatives appeared first on LogRocket Blog.
2 weeks ago - When designers create layouts in their mockups, everything including the content typically looks perfectly aligned and consistent. But in the real world, user-generated content varies wildly. For example, one testimonial card might have a...
1 week ago - Interactivity is what makes a website come alive. Whether it's a button that reveals more content or a form that responds to your input, these little touches keep users engaged. Traditionally, we've relied heavily on JavaScript to make...
Other stories
8 hours ago - Looking for a powerful new Linux laptop? The new KDE Slimbook VI may very well appeal. Unveiled at Akademy 2024, KDE’s annual community get-together, the KDE Slimbook VI marks a major refresh from earlier models in the KDE Slimbook line....
12 hours ago - Fixes 130 bugs (addressing 250 👍). `bun pm pack`, faster `node:zlib`. Static routes in Bun.serve(). ReadableStream support in response.clone() & request.clone(). Per-request timeouts. Cancel method in ReadableStream is called. `bun run`...
1 day ago - Have you ever used an attribute in HTML without fully understanding its purpose? You're not alone! Over time, I've dug into the meaning behind many HTML attributes, especially those that are crucial for accessibility. In this in-depth...
1 day ago - Lifetimes are fundamental mechanisms in Rust. There's a very high chance you'll need to work with lifetimes in any Rust project that has any sort of complexity. Even though they are important to Rust projects, lifetimes can be quite...
1 day ago - The first interaction sets the tone for the entire experience — get it right, and you’ve hooked your users from the start. So as a UX designer, you need to know how to put the primacy effect of UX design to good use. The post Leveraging...