Home > Web Front-end > CSS Tutorial > What Does the Slash Mean in CSS Font Shorthand?

What Does the Slash Mean in CSS Font Shorthand?

Barbara Streisand
Release: 2024-11-12 01:39:02
Original
366 people have browsed it

What Does the Slash Mean in CSS Font Shorthand?

Understanding the Slash in CSS Font Shorthand

In CSS, the font property provides a convenient way to set multiple font-related properties in a single declaration. However, using a slash in this property can be confusing.

What Does the Slash Signify?

The slash in the following CSS property:

font: 100%/120%;
Copy after login

actually sets two separate properties, equivalent to:

font-size: 100%;
line-height: 120%;
Copy after login

As per the official CSS documentation, this syntax mimics traditional typographical shorthand for specifying typeface sizes as "x pt on y pt," where "x" represents the glyph size and "y" the line height.

Typesetting Tradition

In the print typesetting world, it was common to specify typefaces using this "x on y" notation, and CSS inherits this concept. The slash character divides the font size and line height values, just as it does in the print version.

Syntax Requirements

However, it's important to note that this shorthand notation requires specifying both the font family and size. The example provided in your question, font: 100%/120%;, is invalid and will be ignored by browsers. To make it valid, you must add a font family, such as:

font: 100%/120% serif;
Copy after login

By understanding the meaning of the slash in the CSS font property, you can effectively control the size and line spacing of your text in web design.

The above is the detailed content of What Does the Slash Mean in CSS Font Shorthand?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template