HTML Character Sets
The charset meta tag declares which character encoding a page uses, telling the browser how to interpret the bytes of the HTML file into readable text.
UTF-8 is the universal standard today, supporting virtually every character and symbol from every language, and should be declared as the very first line inside <head>.
<meta charset="UTF-8">Why encoding matters
Without a correct charset declaration, special characters, accented letters, or non-Latin scripts can display as garbled text (mojibake).
Declaring UTF-8
<meta charset="UTF-8"> should be the first tag in <head>, before any content-generating tags, to ensure correct interpretation from the very start.
<head>
<meta charset="UTF-8">
<title>My Page</title>
</head>(page renders all characters correctly)Declaring UTF-8 first ensures accurate text rendering throughout the page.
<p>Café, naïve, 你好, مرحبا</p>Café, naïve, 你好, مرحباUTF-8 correctly displays accented Latin letters as well as Chinese and Arabic scripts.
Key points
- The charset meta tag declares character encoding.
- UTF-8 is the modern universal standard.
- Missing/wrong charset causes garbled text (mojibake).
- Charset should be the very first tag inside <head>.
