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 character set of the HTML page is relevant.

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

Syntax

@charset "charset";

Example

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

Here see an example which shows both the right and wrong ways of using the @charset rule:

Example

@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 "*/

Values

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

2.0+ x 1.5+ 4.0+ 9.0+




Related articles