We use the
@charset at-rule to specify the character encoding
of an external style sheet. The at-rule must be followed by a quoted
string value and a semicolon; the string must contain a valid encoding
name from the IANA registry.
For obvious reasons, if it’s
@charset rule must be the very first
thing in the CSS file. The only item that can precede it is a Unicode byte order mark (BOM).
need to use an
@charset rule in your style sheets. A
user agent can deduce the character encoding of a CSS style sheet in four
different ways, and if all of those fail, it uses a default.
For an external style sheet, a user agent will look for the following items:
charsetattribute in a Content-Type HTTP header (or similar) sent by the web server
- a Unicode byte order mark, or an
charsetattribute specified in the
<link>tag from which the HTML document links to the style sheet
- the encoding of the referring document or style sheet
This list defines the items in order of descending priority, and the first one that’s found will determine the style sheet’s encoding. If none are found, the user agent will assume the character encoding is UTF-8.
You can refer to characters that can’t be represented by the style sheet’s encoding using CSS escape notation.
This example indicates that the style sheet will use the ISO-8859-15 character encoding:
In Internet Explorer
versions up to and including 7, an
will not fail if the encoding is specified without quotes, even
though it should.
In Firefox 1.0, an
rule will work only if it’s specified without quotes, on which it should
- Wed, 24 Mar 2010 14:19:11 GMT
Safari loses the first rule is you add a space or comment before the charset: