HTML Encoding (Character Sets)
HTML Encoding (Character Sets)
HTML encoding defines how characters are represented in a webpage. A character set ensures that text displays correctly in all browsers, including special characters, symbols, and non-English languages.
Why Encoding is Important
-
Prevents garbled text (mojibake) for special characters.
-
Supports multiple languages and scripts.
-
Ensures proper display of symbols, emojis, and HTML entities.
Common Character Sets
| Character Set | Description |
|---|---|
| UTF-8 | Most widely used, supports all languages and symbols |
| ISO-8859-1 | Western European languages |
| ASCII | English characters and basic symbols only |
Recommendation: Always use UTF-8 for modern web development.
Setting Character Encoding in HTML
The <meta> tag in the <head> section defines the character set:
Output:
-
Special characters display correctly: © ® € ™
-
Japanese text displays correctly: こんにちは
Key Points
-
Place the
<meta charset="UTF-8">as early as possible in<head>. -
Always save your HTML file in UTF-8 encoding.
-
UTF-8 supports all Unicode characters, including emojis.
