HTML Charset | Character Encoding in HTML

HTML Charset (character set) defines the encoding used to represent text on a webpage. It ensures that browsers display characters and symbols correctly, especially when working with multiple languages or special characters. The most commonly used charset in HTML is **UTF-8**, which supports a wide range of characters and symbols from various languages.

Why Charset is Important:

Setting the correct charset ensures that your webpage displays all text content, symbols, and special characters as intended, regardless of the browser or operating system.

How to Set Charset in HTML

<!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title>HTML Charset Example</title>
        </head>
        <body>
            <p>This page uses UTF-8 encoding.</p>
            <p>Special characters: © ® € ☺</p>
        </body>
    </html>

Output

This page uses UTF-8 encoding.

Special characters: © ® € ☺

Commonly Used Charsets:

Example of UTF-8 Charset with Special Characters

<!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <title>Special Characters Example</title>
        </head>
        <body>
            <p>Currency symbols: € ¥ £ $</p>
            <p>Smiley face: ☺</p>
            <p>Greek letters: α β γ δ ε</p>
        </body>
    </html>

Output

Currency symbols: € ¥ £ $

Smiley face: ☺

Greek letters: α β γ δ ε

Best Practices for Using Charset:

Using the correct charset is essential for creating accessible and universally readable webpages. **UTF-8** is the standard choice for modern web development due to its wide compatibility and support for international characters.