CSS @charsetRules
Example
Set the character encoding used in the style sheet to UTF-8:
@charset "UTF-8";
Browser Support
The numbers in the table indicate the first browser version number that supports the property.
| Property | |||||
|---|---|---|---|---|---|
| @charset | 2.0 | 12.0 | 1.5 | 4.0 | 9.0 |
Attribute definitions and usage instructions
The @charset rule specifies the character encoding used in the style file (.cssextension), and it can only be used in CSS files.
It must be the first element in the style sheet and must not be preceded by any characters.
If multiple @charset rules are declared, only the first one will be used, and it cannot be used in HTML elements or HTML pages, i.e., it cannot be used inside a <style> element.
Syntax
@charset "charset";
| Value | Description |
|---|---|
| charset | Specify the character set to use. |
More Examples
Example
@charset "UTF-8";
@charset "utf-8"; /*Case-insensitive*/
/*Set the CSS encoding format to Unicode UTF-8*/
@charset 'iso-8859-15'; /*Invalid, used wrong quotes*/
@charset 'UTF-8'; /*Invalid, used wrong quotes*/
@charset "UTF-8"; /*Invalid, more than one space*/
@charset "UTF-8"; /*Invalid, there is an extra space before @*/
@charset UTF-8; /*Invalid, UTF-8 without quotes*/