HTML · Chapter 33 of 45

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>.

Syntax
<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.

Example 1 (html)
<head>
  <meta charset="UTF-8">
  <title>My Page</title>
</head>
Output
(page renders all characters correctly)

Declaring UTF-8 first ensures accurate text rendering throughout the page.

Example 2 (html)
<p>Café, naïve, 你好, مرحبا</p>
Output
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>.
💡 Note: Always explicitly declare UTF-8, even though many servers default to it — never assume.

📝 Quick Quiz

1. What does the charset meta tag declare?

2. Which encoding is the modern universal standard?

3. What happens with an incorrect charset declaration?