HTML Charset

The charset attribute in HTML specifies the character encoding for the HTML document. Character encoding is essential for ensuring that the text is displayed correctly in different browsers and devices.

Why Charset is Important

Charset helps browsers understand how to interpret the bytes in your HTML document into readable characters. Using the correct character encoding ensures that text, including special characters, symbols, and non-Latin scripts, is displayed properly.

Specifying Charset in HTML

The most common way to specify the character encoding for an HTML document is by using the <meta> tag within the <head> section of the HTML document.

Example: Specifying UTF-8 Charset
Try yourself
        
            <meta charset="UTF-8">
        
    

This example shows how to specify the UTF-8 character encoding for an HTML document using the <meta charset="UTF-8"> tag.


Common Charsets

Charset Description Meta Tag Example
UTF-8 Unicode character encoding for almost all characters, widely used for its compatibility and comprehensiveness.
Try yourself
        
            <meta charset="UTF-8">
        
    
ISO-8859-1 Western European character encoding, commonly used before UTF-8 became standard.
Try yourself
        
            <meta charset="ISO-8859-1">
        
    
UTF-16 Unicode character encoding that uses 2 bytes per character, suitable for encoding a large set of characters.
Try yourself
        
            <meta charset="UTF-16">
        
    

Best Practices


Verifying Charset

You can verify the character encoding of your HTML document by inspecting the page in your browser's developer tools. Check the Network tab to see the charset specified in the HTTP headers.