You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/no-invalid-at-rules.md
+25-3Lines changed: 25 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,16 +13,15 @@ CSS contains a number of at-rules, each beginning with a `@`, that perform vario
13
13
-`@supports`
14
14
-`@namespace`
15
15
-`@page`
16
-
-`@charset`
17
16
18
17
It's important to use a known at-rule because unknown at-rules cause the browser to ignore the entire block, including any rules contained within. For example:
19
18
20
19
```css
21
20
/* typo */
22
-
@charse "UTF-8";
21
+
@impor "foo.css";
23
22
```
24
23
25
-
Here, the `@charset` at-rule is incorrectly spelled as `@charse`, which means that it will be ignored.
24
+
Here, the `@import` at-rule is incorrectly spelled as `@impor`, which means that it will be ignored.
26
25
27
26
Each at-rule also has a defined prelude (which may be empty) and potentially one or more descriptors. For example:
28
27
@@ -73,6 +72,29 @@ Examples of **incorrect** code:
73
72
}
74
73
```
75
74
75
+
Note on `@charset`: Although it begins with an `@` symbol, it is not an at-rule. It is a specific byte sequence of the following form:
76
+
77
+
```css
78
+
@charset "<charset>";
79
+
```
80
+
81
+
where `<charset>` is a [`<string>`](https://developer.mozilla.org/en-US/docs/Web/CSS/string) denoting the character encoding to be used. It must be the name of aweb-safe character encoding defined in the [IANA-registry](https://www.iana.org/assignments/character-sets/character-sets.xhtml), and must be double-quoted, following exactly one space character (U+0020) after `@charset`, and immediately terminated with a semicolon.
82
+
83
+
Examples of **incorrect**code:
84
+
85
+
<!-- prettier-ignore -->
86
+
```css
87
+
@charset 'iso-8859-15'; /* Wrong quotes used */
88
+
@charset "UTF-8"; /* More than one space */
89
+
@charset UTF-8; /* The charset is a CSS <string> and requires double-quotes */
90
+
```
91
+
92
+
Examples of **correct** code:
93
+
94
+
```css
95
+
@charset "UTF-8";
96
+
```
97
+
76
98
## When Not to Use It
77
99
78
100
If you are purposely using at-rules that aren't part of the CSS specification, then you can safely disable this rule.
0 commit comments