iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

HTML Character Sets

A character set maps bytes to characters. UTF-8 is the modern default and the only one you should be picking today.

Why UTF-8 won

PropertyWhy it matters
Covers every Unicode characterEvery language, every symbol, every emoji works on one page.
Backwards compatible with ASCIIPlain English text is the same bytes either way.
Variable-widthASCII characters are 1 byte; rare characters take 2–4 bytes. Small files for English; full coverage for everything else.
UniversalThe web, JSON, modern programming languages, databases, and operating systems all default to UTF-8.

Common charsets and what they cover

CharsetCovers
UTF-8All Unicode (over 150,000 characters).
UTF-16Same coverage; uses 2 or 4 bytes per character.
ISO-8859-1 (Latin-1)Western European Latin alphabets.
ISO-8859-5Cyrillic.
Windows-1252Latin-1 with extra punctuation.
Shift_JISJapanese.
GB2312 / GBKSimplified Chinese.
Big5Traditional Chinese.
ASCIIBasic English only (128 characters).
Use UTF-8. Declare it with <meta charset="UTF-8"> as the first line of <head>, and make sure your editor saves the file with that encoding.

Example

Example
<!DOCTYPE html>
<html>
<head>
    <title>HTML Character Sets</title>
</head>
<body>

<h1>HTML Character Sets</h1>
<p>This is a demo page for the "HTML Character Sets" lesson.</p>

</body>
</html>
Try it Yourself »

Exercise

Which character set covers virtually every written language?

Test yourself

Q1. Recommended charset for the web is…
Q2. Declare it in <head> with…
Q3. Without declaration, browsers may…

Discussion

Loading…