CSS | @charset Rule


The @charset rule specifies the character encoding used in the style sheet. The @charset must be the first element in the style sheet and if several @charset rules are defined then the only first one is used. It can not be used in the <style> element where the character set of the HTML page is relevant.

The @charset rule specifies the character encoding used in the style sheet.

Property value: This parameter accept single value “charset”.
It is useful when some NON-ASCII characters are used in the content. There are so many ways to define the character encoding of a style sheet. All the browser follow the following methods in the given orders.

  • The value of Unicode byte-order character has to placed at the beginning of the file.
  • The value is given by the charset attribute of the Content-Type: HTTP header or the equivalent in the protocol used to serve the style sheet.
  • Use the character encoding defined by the referring document. This method does not used in HTML 5.
  • Assume that the document is UTF-8

Note: Below list describes the correct and incorrect charset encoding: