English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Complete List of CSS Attributes

CSS @charset Rule

@charset can use a single rule in external style sheets to specify the character encoding of style rules and values.

Never use @charset inEmbedded style sheetsUse this rule because there are other methods to define character encoding in HTML, such as<meta>tags.

Syntax of using @charset rule

The syntax of this rule is as follows:

@charset "charset-name";

The following example demonstrates how to use the @charset attribute.

@charset "UTF-8";
/* CSS Document */
body {
 background: yellow;
}
h1 {
 color: #ff0000;
 font-size: 24px;
}
p {
 color: rgb(0,255,0);
 font-size: 14px;
}
Test and see‹/›

Note:Only one rule can appear in the @charset external stylesheet, and this rule must be at the top of the document. There should be no characters before it, even comments.

Browser compatibility

Browser compatibility of @charset attribute, the numbers in the table below represent the minimum version number of browsers that support this attribute; all mainstream browsers support this rule.

  • Firefox 1.5+

  • Google Chrome 2+

  • Internet Explorer 5.5+

  • Apple Safari 4+

  • Opera 9+

Further reading

Please refer to the following tutorial:HTML Meta.