This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The @charset CSS rule specifies the character encoding used in the style sheet. This syntax is useful when using non-ASCII characters in some CSS properties, like content. Although the first character in @charset is the @ symbol, it is not an at-rule. It is a specific byte sequence that can only be placed at the very beginning of a stylesheet. No other characters, except the Unicode byte-order mark, are allowed before it. It also does not follow normal CSS syntax rules such as use of quotes or whitespace.
If a @charset is not recognized as the charset declaration, it is parsed as a normal at-rule. The CSS syntax module deprecates this fallback behavior, defining it as an unrecognized legacy rule to be dropped when a stylesheet is grammar-checked.
As there are several ways to define the character encoding of a style sheet, the browser will try the following methods in the following order (and stop as soon as one yields a result):
charset attribute of the Content-Type: HTTP header or the equivalent in the protocol used to serve the style sheet.@charset CSS declaration.charset attribute of the <link> element. This method is obsolete and should not be used.@charset "UTF-8"; @charset "iso-8859-15";
A <string> denoting the character encoding to be used. It must be the name of a web-safe character encoding defined in the IANA-registry, and must be double-quoted, following exactly one space character (U+0020), and immediately terminated with a semicolon. If several names are associated with an encoding, only the one marked with preferred must be used.
Note that the @charset rule is not parsed via syntax, but via a specific byte sequence of the following form:
@charset "<charset>";
@charset "UTF-8"; /* Set the encoding of the style sheet to Unicode UTF-8 */
@charset 'iso-8859-15'; /* Invalid, wrong quotes used */ @charset "UTF-8"; /* Invalid, more than one space */ @charset "UTF-8"; /* Invalid, there is a character (a space) before the declarations */ @charset UTF-8; /* Invalid, the charset is a CSS <string> and requires double-quotes */
| Specification |
|---|
| CSS Syntax Module Level 3> # at-ruledef-charset> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
@charset |
2 | 12 | 1.5Firefox 1 supported an invalid syntax where the character encoding is not between single or double quotes. |
9 | 4 | 18 | 4 | 10.1 | 4 | 1.0 | 2 | 4 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/@charset