Is Quoting Font Family Names in CSS Necessary?
Traditionally, it was believed that wrapping font names containing multiple words in quotes within the CSS font-family property was considered good practice. However, recent tests suggest that browsers like Safari and Firefox have no issues rendering fonts without the quotes.
The CSS Specifications
According to the CSS 2.1 specification, font family names must be either quoted as strings or unquoted as a sequence of identifiers. If identifiers are used, punctuation and digits at the start of tokens require escaping.
Recommended Practice
While the CSS specification does not strictly require quotes, it recommends them for font family names with white space, digits, or punctuation other than hyphens to avoid confusion with keyword values or to prevent the need for escaping punctuation within the identifier.
When Quotes Are Necessary
Quotes are essential when font names match keyword values such as 'inherit', 'serif', or 'monospace'.
Conclusion
While there is a technical difference between quoted and unquoted font family names, it's unlikely to cause problems in modern browsers. However, quoting is recommended when the font name contains special characters or matches keyword values. By following this practice, you can ensure proper font rendering and avoid potential confusion in your CSS code.
The above is the detailed content of Do You Really Need Quotes for Font Family Names in CSS?. For more information, please follow other related articles on the PHP Chinese website!