CSS @charset Tutorial

CSS @charset

The @charset CSS at-rule defines the character encoding for the style sheet. It must appear at the beginning of the style sheet and can only be used once.

Here's an example of how to use the @charset rule:

Result:

        @charset "UTF-8";
        
        body {
            font-family: Arial, sans-serif;
            color: #333;
            background-color: #fff;
        }
        

In this example, we have set the character encoding to UTF-8 using @charset "UTF-8";. This ensures that special characters and symbols are displayed correctly in the style sheet.

It's important to note that the @charset rule must be the first thing in the style sheet, before any other CSS rules or HTML code.

Here's an example of a table that showcases different character encodings:

Character Encoding Description
UTF-8 Unicode Transformation Format-8. Supports a wide range of characters.
ISO-8859-1 Western European character set encoding.
Shift_JIS Japanese character set encoding.