UNPKG

5 kBMarkdownView Raw
1# font-family-name-quotes
2
3Specify whether or not quotation marks should be used around font family names.
4
5<!-- prettier-ignore -->
6```css
7a { font-family: "Times New Roman", 'Ancient Runes', serif; }
8/** ↑ ↑ ↑ ↑
9 * These quotation marks and this one */
10```
11
12This rule checks the `font` and `font-family` properties.
13
14This 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
27For 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
33Expect quotes around every font family name that is not a keyword.
34
35The following patterns are considered violations:
36
37<!-- prettier-ignore -->
38```css
39a { font-family: Arial, sans-serif; }
40```
41
42<!-- prettier-ignore -->
43```css
44a { font-family: Times New Roman, Times, serif; }
45```
46
47<!-- prettier-ignore -->
48```css
49a { font: 1em Arial, sans-serif; }
50```
51
52The following patterns are _not_ considered violations:
53
54<!-- prettier-ignore -->
55```css
56a { font-family: 'Arial', sans-serif; }
57```
58
59<!-- prettier-ignore -->
60```css
61a { font-family: "Times New Roman", "Times", serif; }
62```
63
64<!-- prettier-ignore -->
65```css
66a { font: 1em 'Arial', sans-serif; }
67```
68
69### `"always-where-required"`
70
71Expect quotes only when quotes are _required_ according to the criteria above, and disallow quotes in all other cases.
72
73The following patterns are considered violations:
74
75<!-- prettier-ignore -->
76```css
77a { font-family: "Arial", sans-serif; }
78```
79
80<!-- prettier-ignore -->
81```css
82a { font-family: 'Times New Roman', Times, serif; }
83```
84
85<!-- prettier-ignore -->
86```css
87a { font: 1em "Arial", sans-serif; }
88```
89
90The following patterns are _not_ considered violations:
91
92<!-- prettier-ignore -->
93```css
94a { font-family: Arial, sans-serif; }
95```
96
97<!-- prettier-ignore -->
98```css
99a { font-family: Arial, sans-serif; }
100```
101
102<!-- prettier-ignore -->
103```css
104a { font-family: Times New Roman, Times, serif; }
105```
106
107<!-- prettier-ignore -->
108```css
109a { font-family: "Hawaii 5-0"; }
110```
111
112<!-- prettier-ignore -->
113```css
114a { font: 1em Arial, sans-serif; }
115```
116
117### `"always-where-recommended"`
118
119Expect 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
121The following patterns are considered violations:
122
123<!-- prettier-ignore -->
124```css
125a { font-family: Times New Roman, Times, serif; }
126```
127
128<!-- prettier-ignore -->
129```css
130a { font-family: MyFontVersion6, sake_case_font; }
131```
132
133<!-- prettier-ignore -->
134```css
135a { font-family: 'Arial', sans-serif; }
136```
137
138<!-- prettier-ignore -->
139```css
140a { font: 1em Times New Roman, Times, serif; }
141```
142
143The following patterns are _not_ considered violations:
144
145<!-- prettier-ignore -->
146```css
147a { font-family: 'Times New Roman', Times, serif; }
148```
149
150<!-- prettier-ignore -->
151```css
152a { font-family: "MyFontVersion6", "sake_case_font"; }
153```
154
155<!-- prettier-ignore -->
156```css
157a { font-family: Arial, sans-serif; }
158```
159
160<!-- prettier-ignore -->
161```css
162a { font: 1em 'Times New Roman', Times, serif; }
163```