Home Web Front-end CSS Tutorial Improve Web Typography with CSS Font Size Adjust

Improve Web Typography with CSS Font Size Adjust

Feb 16, 2025 am 11:51 AM

Improve Web Typography with CSS Font Size Adjust

CSS font-size-adjust Attributes: A powerful tool to improve the readability of web page typesetting

font-size-adjust CSS attribute allows developers to specify font sizes based on the height of lowercase letters rather than the height of uppercase letters, thereby significantly improving the readability of web text, especially when using alternate fonts.

This article will explore in-depth the importance of font-size-adjust attributes and their correct use in projects.

The importance of

font-size-adjust Most websites are mainly composed of text. Since text is crucial in a website, it is especially necessary to pay special attention to the fonts used. Choosing the right font can bring a pleasant reading experience, otherwise it may make the website difficult to read. After determining the font, you usually need to select the appropriate font size.

Properties set the font size of all font series on the website. However, it is often chosen for the preferred font family. The problem arises when the preferred font is unavailable for some reason, the browser uses one of the alternate fonts listed in the CSS document to render the text.

font-sizeFor example, given the following CSS rules:

If the browser cannot download "Lato" from Google Fonts, the next alternate font, Verdana, will be used instead. However, the
body {
  font-family: 'Lato', Verdana, sans-serif;
}
Copy after login
Copy after login
value is most likely chosen with the consideration of "Lato" rather than Verdana.

font-size

Aspect ratio of web fonts

For constant font size values, the visual size of the font and its readability may vary greatly. This is especially true for texts such as Latin that are case sensitive. In this case, the ratio of lowercase letter height to its uppercase letter height is an important factor in determining the readability of the font. This ratio is often called the aspect ratio of the font.

As mentioned earlier, once the

value is set, it will remain the same for all font families. However, if the aspect ratio of the alternate font is too different from the preferred font, it may affect the readability of the alternate font.

The font-size

property is very important in this case because it allows you to set the x height of all fonts to the same value, thereby improving its readability.

font-size-adjust

Select the appropriate

value font-size-adjust Now that you understand the importance of using the

attribute, learn how to use it on your website. This property has the following syntax:

font-size-adjust The initial value of

font-size-adjust: none | <number>
Copy after login
is

. The font-size-adjust value means that the none value of different font series will not be adjusted. none

You can also set the value of the font-size-adjust attribute to a number. This number is used to calculate the x height of all fonts on a web page to the same value. x height equals the given number multiplied by the font size. This can significantly improve the readability of small size fonts. Here is an example of how to use the font-size-adjust attribute:

body {
  font-family: 'Lato', Verdana, sans-serif;
}
Copy after login
Copy after login

The x height of all fonts will now be 20px * 0.6 = 12px. The actual size of a given font can now be changed to ensure that the x height remains at 12px at all times. The new adjusted font size for a given font can be calculated using the following formula:

c = (a / a') s.

Here, c is the adjusted font size to be used, s is the specified font size value, a is the aspect ratio specified by the font-size-adjust attribute, and a' is the aspect ratio of the font that needs to be adjusted.

You cannot set font-size-adjust to a negative value. A value of 0 will cause the text to have no height, in other words, the text will actually be hidden. In older browsers such as Firefox 40, a value of 0 is equivalent to setting font-size-adjust to none.

In most cases, developers usually try several font size values ​​to see which value is best for a given font. This means that ideally they want the x height of all font options to be equal to the x height of their preferred font. In other words, the most suitable value for the font-size-adjust attribute is the aspect ratio of the preferred font.

How to determine the aspect ratio of a font

To determine the correct aspect ratio of a font, you can rely on the fact that its resized font size should be the same as the original font size you specified. This means that in the preceding equation, a should equal a'.

The first step in calculating the aspect ratio is to create two elements. Both elements will contain a single letter and its surrounding border (the two letters must be the same because we need to compare between these two elements). Additionally, the font-size attribute values ​​for both elements are the same, but only one of them will also use the font-size-adjust attribute. When the value of font-size-adjust is equal to the aspect ratio of a given font, the size of the two letters in each element will be the same.

Use on the website font-size-adjust

Browser support: Currently, only Firefox supports font-size-adjust by default. Starting with versions 43 and 30, Chrome and Opera support this property after the Experimental Web Platform Features flag (enabled in chrome://flags). Edge and Safari do not support the font-size-adjust attribute at all.

If you decide to use this property, lower browser support should not be a problem at all. This property is designed with backward compatibility in mind. Browsers that do not support this property will display text normally, while browsers that support this property will adjust the font size according to the value of the font-size-adjust property.

Conclusion

After reading this tutorial, you now know the role of the font-size-adjust attributes, their importance, and how to calculate the aspect ratios of different fonts.

Because font-size-adjust can be downgraded gracefully in older browsers, you can start using it right away to improve the readability of text in your production website.

Improve Web Typography with CSS Font Size Adjust (The picture at the end of the article is the same as the beginning of the article)

The above is the detailed content of Improve Web Typography with CSS Font Size Adjust. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Vue 3 Vue 3 Apr 02, 2025 pm 06:32 PM

It&#039;s out! Congrats to the Vue team for getting it done, I know it was a massive effort and a long time coming. All new docs, as well.

Can you get valid CSS property values from the browser? Can you get valid CSS property values from the browser? Apr 02, 2025 pm 06:17 PM

I had someone write in with this very legit question. Lea just blogged about how you can get valid CSS properties themselves from the browser. That&#039;s like this.

Stacked Cards with Sticky Positioning and a Dash of Sass Stacked Cards with Sticky Positioning and a Dash of Sass Apr 03, 2025 am 10:30 AM

The other day, I spotted this particularly lovely bit from Corey Ginnivan’s website where a collection of cards stack on top of one another as you scroll.

A bit on ci/cd A bit on ci/cd Apr 02, 2025 pm 06:21 PM

I&#039;d say "website" fits better than "mobile app" but I like this framing from Max Lynch:

Using Markdown and Localization in the WordPress Block Editor Using Markdown and Localization in the WordPress Block Editor Apr 02, 2025 am 04:27 AM

If we need to show documentation to the user directly in the WordPress editor, what is the best way to do it?

Comparing Browsers for Responsive Design Comparing Browsers for Responsive Design Apr 02, 2025 pm 06:25 PM

There are a number of these desktop apps where the goal is showing your site at different dimensions all at the same time. So you can, for example, be writing

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

How to Use CSS Grid for Sticky Headers and Footers How to Use CSS Grid for Sticky Headers and Footers Apr 02, 2025 pm 06:29 PM

CSS Grid is a collection of properties designed to make layout easier than it’s ever been. Like anything, there&#039;s a bit of a learning curve, but Grid is

See all articles