@charset - CSS At-rule

@charset

Summary of characteristics of the @charset at-rule

Quick description
Indicates the character set used in the style sheet.
Status
Standard
W3C Module
Cascading Style Sheets Level 2 - Revision 1 Specification

Description of the @charset at-rule.

@charset defines the character set used in the style sheet. This directive is optional since CSS keywords don't contain diacritical characters (accents, cedillas...), unless the property content or the function symbols() are used.

The syntax of the @charset directive is picky:

  • @charset must be at the very beginning of the stylesheet, without any characters before it, not even a space or a line break.
  • There must be a space, and only one, between the word @charset and the character set name. No colon character, unlike the usual practice in CSS.
  • The character set must be enclosed in quotation marks. Apostrophes are not allowed, unlike the usual CSS syntax.

Syntax examples (right now, you're probably using "utf-8"):

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

How to write special characters?

If we need, for the purposes of the content property for example, to write special characters in CSS, we need to know their hexadecimal code (see our character search tool for that). Then enter the code in the CSS using the following syntax:

content: '\A9 '; pour © content: '\B1 '; pour ± content: '\C6 '; pour Æ content: '\260E '; pour ☎ Etc.

The HTML entities don't work in CSS.

Attention! If you write character codes in the HTML page, only the first 255 characters can be used (from 00 to FF). In the style sheet, all characters can be used, provided that the instruction @charset "utf-8"; is correctly included at the beginning of the sheet.

Browsers compatibility with the @charset at-rule.

No compatibility issues to report regarding the @charset directive.

Column 1
Correct handling by browsers of the @charset at-rule allowing for the definition of the character set of the style sheet.
1
@charset
at-rule
Estimated overall support.
96%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Samsung Internet

Chrome

Edge

Chrome pour Androïd

Androïd Brower

Firefox pour Androïd

Firefox

KaiOS Browser

Opéra

Safari

Safari sur IOS

Opéra mini

Evolution of the @charset at-rule.

  • Cascading Style Sheets Level 2 - Revision 1 Specification

    This level 2 of the specification describes the mechanism of cascading styles in CSS. This language is used to format HTML or XML documents. It supports media-specific style sheets so that authors can adapt the presentation of their documents for visual browsers, auditory devices, printers, braille devices, portable devices, etc.

    Regarding @charset Introduction of the @charset at-rule.
    WD
    November 04, 1997
    Working Draft.
    PR
    March 24, 1998
    Proposed for recommendation.
    REC
    May 11, 1998
    Recommendation .