@charset - CSS | MDN

Syntax

css

@charset "UTF-8";
@charset "iso-8859-15";

Parameters

charset

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.

Formal syntax

Note that the @charset rule is not parsed via syntax, but via a specific byte sequence of the following form:

@charset "<charset>";

Examples

Valid and invalid charset declarations

css

@charset "UTF-8"; /* Set the encoding of the style sheet to Unicode UTF-8 */

css

@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 */

Specifications

Specification
CSS Syntax Module Level 3
# at-ruledef-charset

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.