CSS @charset Property

A @charset rule specifies the character encoding of the style rules and values. The @charset rule should never be used in an embedded style sheet, as there are other ways to define character encoding in HTML such as <meta> tag. If several @charset at-rules are defined, only the first one is used, and it cannot be used inside a style attribute on an HTML element or inside the <style> element where the HTML page's character set is relevant.

Initial Value none
Applies to Block-level elements.
Inherited No.
Animatable No.
Version CSS2
DOM Syntax object.style.clear = "UTF-8";


@charset "charset";

Here you can see how @charset can be used in a code:

@charset "iso-8859-15";       /* Set the encoding of the style sheet to iso-8859-15*/

The following piece of code shows both the right and wrong ways of using the @charset rule:

@charset "UTF-8";       /* Set the encoding of the style sheet to Unicode UTF-8 */
@charset 'iso-8859-15'; /* Invalid, wrong quoting style used */
@charset  "UTF-8";      /* Invalid, more than one space */
 @charset "UTF-8";      /* Invalid, there is a character (a space) before the at-rule */
@charset UTF-8;         /* Invalid, without ' or "*/


Value Description
charset Specifies the character encoding to use.
initial It makes the property use its default value.
inherit It inherits the property from its parents element.

Browser support

chrome edge firefox safari opera
2.0+ 1.5+ 4.0+ 9.0+

Practice Your Knowledge

What is the primary role of charset in CSS?

Quiz Time: Test Your Skills!

Ready to challenge what you've learned? Dive into our interactive quizzes for a deeper understanding and a fun way to reinforce your knowledge.

Do you find this helpful?