When should a CSS font value for CSS use quotation marks?

When does the font-family value for CSS have quotes around it?

I saw both font-family: arial and font-family: "arial" .

As a concrete example, I declare a font as follows:

 @font-face { font-family: 'entypo'; font-style: normal; font-weight: 400; src: url('/css/fonts/entypo.woff') format('woff'); } 

What will be the correct CSS for the element to use this font family?

+8
source share
3 answers

Quotation marks are needed only when there is a space in the font itself, for example, "Times New Roman" .

Arial does not need quotes, but some people use quotes such as "Arial" to be more consistent. This is just a personal preference.

The following is Justin's comment: font-family: times new roman; works without quotes ( JSFiddle ).

You can call your new @font-face using font-family: 'entypo'; as you usually expect. ( link )

+8
source

Just want to answer this question:

http://www.w3.org/TR/CSS2/fonts.html#font-family-prop

To avoid escaping errors, it is recommended that you specify font family names that contain spaces, numbers, or punctuation other than a hyphen:

body {font-family: "New Age Textbook, serif}

Font family names that match the keywords ("inherit", "serif", "sans-serif", "monospace", "fantasy" and "cursive") should be specified to prevent confusion with keywords with the same names .

+1
source

In CSS 2.1 spec, the font name must be in quotation marks if it contains characters other than identifier characters (which is a broader concept than just β€œAscii letters and numbers”) and spaces. So font-family: foo bar is correct, and that is, for example, font-family: entypo , of course.

Coding style is another problem. It is always correct to specify a specific font family name (as opposed to generic names like sans-serif ), therefore font-family: "entypo" also correct.

Very theoretically, the font name should also be indicated if the specific font family name matches the common name (I don’t think anyone has ever created such a font), or if its name contains leading or trailing spaces or consecutive spaces (but no one in in this sense I would not name my font in this way).

+1
source

All Articles