Addressing the Stylistic Dilemma: Should Font Family Names Be Enclosed in Quotes in CSS?
The debate surrounding the necessity of enclosing font family names in quotes has lingered in the CSS community. This question stemmed from a longstanding "best practice" that has been challenged by modern browsers. Let's delve into the technicalities and logic behind this convention.
Technical Basis
According to the CSS 2.1 specification, font family names can be specified with or without quotes. When unquoted, the name should be a sequence of identifiers. However, identifiers cannot contain spaces or certain punctuation characters. To include these characters, they must be escaped or the name should be quoted.
The rule of thumb recommends quoting font family names that contain whitespace, digits, or punctuation other than hyphens. This recommendation avoids potential errors in escaping.
Practical Implications
In practice, removing quotes from font family names containing spaces does not appear to cause issues in major browsers like Safari and Firefox. This suggests that the "best practice" of using quotes may not be essential for modern browsers. However, there are a few exceptions:
Recommendation
While modern browsers may not require quotes for font family names containing spaces, quoting names that contain other special characters or match CSS keywords is still a prudent practice. It ensures consistency, clarity, and avoids potential pitfalls.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3