1 | # font-family-name-quotes
|
2 |
|
3 | Specify whether or not quotation marks should be used around font family names.
|
4 |
|
5 |
|
6 | ```css
|
7 | a { font-family: "Times New Roman", 'Ancient Runes', serif; }
|
8 | /** ↑ ↑ ↑ ↑
|
9 | * These quotation marks and this one */
|
10 | ```
|
11 |
|
12 | This rule checks the `font` and `font-family` properties.
|
13 |
|
14 | This rule ignores `$sass`, `@less`, and `var(--custom-property)` variable syntaxes.
|
15 |
|
16 | ## Options
|
17 |
|
18 | `string`: `"always-where-required"|"always-where-recommended"|"always-unless-keyword"`
|
19 |
|
20 | _Please read the following to understand these options_:
|
21 |
|
22 | - The `font` and `font-family` properties accept a short list of special **keywords**: `inherit`, `serif`, `sans-serif`, `cursive`, `fantasy`, `system-ui`, and `monospace`. If you wrap these words in quotes, the browser will not interpret them as keywords, but will instead look for a font by that name (e.g. will look for a `"sans-serif"` font) -- which is almost _never_ what you want. Instead, you use these keywords to point to the built-in, generic fallbacks (right?). Therefore, _all of the options below enforce no quotes around these keywords_. (If you actually want to use a font named `"sans-serif"`, turn this rule off.)
|
23 | - Quotes are **recommended** [in the spec](https://www.w3.org/TR/CSS2/fonts.html#font-family-prop) with "font family names that contain white space, digits, or punctuation characters other than hyphens".
|
24 | - Quotes are **required** around font-family names when they are not [valid CSS identifiers](https://www.w3.org/TR/CSS2/syndata.html#value-def-identifier). For example, a font family name requires quotes around it if it contains `$`, `!` or `/`, but does not require quotes just because it contains spaces or a (non-initial) number or underscore. _You can probably bet that almost every font family name you use **will** be a valid CSS identifier_.
|
25 | - Quotes should **never** be used around vendor prefixed system fonts such as `-apple-system` and `BlinkMacSystemFont`.
|
26 |
|
27 | For more on these subtleties, read ["Unquoted font family names in CSS"](https://mathiasbynens.be/notes/unquoted-font-family), by Mathias Bynens.
|
28 |
|
29 | **Caveat:** This rule does not currently understand escape sequences such as those described by Mathias. If you want to use the font family name "Hawaii 5-0" you will need to wrap it in quotes, instead of escaping it as `Hawaii \35 -0` or `Hawaii\ 5-0`.
|
30 |
|
31 | ### `"always-unless-keyword"`
|
32 |
|
33 | Expect quotes around every font family name that is not a keyword.
|
34 |
|
35 | The following patterns are considered violations:
|
36 |
|
37 |
|
38 | ```css
|
39 | a { font-family: Arial, sans-serif; }
|
40 | ```
|
41 |
|
42 |
|
43 | ```css
|
44 | a { font-family: Times New Roman, Times, serif; }
|
45 | ```
|
46 |
|
47 |
|
48 | ```css
|
49 | a { font: 1em Arial, sans-serif; }
|
50 | ```
|
51 |
|
52 | The following patterns are _not_ considered violations:
|
53 |
|
54 |
|
55 | ```css
|
56 | a { font-family: 'Arial', sans-serif; }
|
57 | ```
|
58 |
|
59 |
|
60 | ```css
|
61 | a { font-family: "Times New Roman", "Times", serif; }
|
62 | ```
|
63 |
|
64 |
|
65 | ```css
|
66 | a { font: 1em 'Arial', sans-serif; }
|
67 | ```
|
68 |
|
69 | ### `"always-where-required"`
|
70 |
|
71 | Expect quotes only when quotes are _required_ according to the criteria above, and disallow quotes in all other cases.
|
72 |
|
73 | The following patterns are considered violations:
|
74 |
|
75 |
|
76 | ```css
|
77 | a { font-family: "Arial", sans-serif; }
|
78 | ```
|
79 |
|
80 |
|
81 | ```css
|
82 | a { font-family: 'Times New Roman', Times, serif; }
|
83 | ```
|
84 |
|
85 |
|
86 | ```css
|
87 | a { font: 1em "Arial", sans-serif; }
|
88 | ```
|
89 |
|
90 | The following patterns are _not_ considered violations:
|
91 |
|
92 |
|
93 | ```css
|
94 | a { font-family: Arial, sans-serif; }
|
95 | ```
|
96 |
|
97 |
|
98 | ```css
|
99 | a { font-family: Arial, sans-serif; }
|
100 | ```
|
101 |
|
102 |
|
103 | ```css
|
104 | a { font-family: Times New Roman, Times, serif; }
|
105 | ```
|
106 |
|
107 |
|
108 | ```css
|
109 | a { font-family: "Hawaii 5-0"; }
|
110 | ```
|
111 |
|
112 |
|
113 | ```css
|
114 | a { font: 1em Arial, sans-serif; }
|
115 | ```
|
116 |
|
117 | ### `"always-where-recommended"`
|
118 |
|
119 | Expect quotes only when quotes are _recommended_ according to the criteria above, and disallow quotes in all other cases. (This includes all cases where quotes are _required_, as well.)
|
120 |
|
121 | The following patterns are considered violations:
|
122 |
|
123 |
|
124 | ```css
|
125 | a { font-family: Times New Roman, Times, serif; }
|
126 | ```
|
127 |
|
128 |
|
129 | ```css
|
130 | a { font-family: MyFontVersion6, sake_case_font; }
|
131 | ```
|
132 |
|
133 |
|
134 | ```css
|
135 | a { font-family: 'Arial', sans-serif; }
|
136 | ```
|
137 |
|
138 |
|
139 | ```css
|
140 | a { font: 1em Times New Roman, Times, serif; }
|
141 | ```
|
142 |
|
143 | The following patterns are _not_ considered violations:
|
144 |
|
145 |
|
146 | ```css
|
147 | a { font-family: 'Times New Roman', Times, serif; }
|
148 | ```
|
149 |
|
150 |
|
151 | ```css
|
152 | a { font-family: "MyFontVersion6", "sake_case_font"; }
|
153 | ```
|
154 |
|
155 |
|
156 | ```css
|
157 | a { font-family: Arial, sans-serif; }
|
158 | ```
|
159 |
|
160 |
|
161 | ```css
|
162 | a { font: 1em 'Times New Roman', Times, serif; }
|
163 | ```
|