Home  >  Article  >  Web Front-end  >  Should I Use Quotation Marks Around Font Family Names in CSS?

Should I Use Quotation Marks Around Font Family Names in CSS?

Barbara Streisand
Barbara StreisandOriginal
2024-11-19 10:19:02251browse

Should I Use Quotation Marks Around Font Family Names in CSS?

Do I Need Quotation Marks Around Font Family Names?

When working with CSS, you may have heard conflicting advice about wrapping quotes around font family names containing multiple words. Some claim it's necessary, while others dismiss it as a myth. Here's a technical explanation to clarify the matter:

The CSS 2.1 specification states that font family names can be specified either as quoted strings or unquoted sequences of identifiers. However, unquoted identifiers require escaping certain characters at the start of each token, such as punctuation and digits.

For example, to specify "Arial Narrow" without quotes:

font-family: Arial\ Narrow, Arial, Helvetica, sans-serif;

To avoid the need for escaping, the specification recommends quoting font family names with spaces, digits, or punctuation other than hyphens.

font-family: "Arial Narrow", Arial, Helvetica, sans-serif;

This ensures that the font name is interpreted correctly, even in cases where the whitespace or special characters might otherwise be misinterpreted.

In summary, while not always strictly necessary, quoting font family names with multiple words is a good practice to avoid potential confusion and ensure compatibility across browsers. Specifically, it is essential to quote font names that match reserved keywords or contain certain punctuation within identifiers.

The above is the detailed content of Should I Use Quotation Marks Around Font Family Names in CSS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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