HTML Character Sets
In this page:
Evolution of Character Encodings
In the early days of computing, different systems used different character encoding keys.
ASCII supported only basic English characters, while ISO-8859-1 added support for Western European accents, creating layout conflicts as the web expanded globally.
Example: Evolution of Character Encodings
<!-- ASCII: basic English only. ISO-8859-1: adds Western European accents -->
<meta charset="ISO-8859-1">
The Universal UTF-8 Standard
UTF-8 is a highly efficient, variable-width character encoding standard that can represent over a million unique characters, including mathematical symbols, global alphabets, and emojis.
Example: The Universal UTF-8 Standard
<meta charset="UTF-8">
Declaring Charsets in the head Section
To make sure your webpage renders correctly, you must place the character set meta tag inside the head section of your document. It must be placed within the first 1024 bytes of the file so the browser reads it before loading your text.
Example: Declaring Charsets in the head Section
<head>
<meta charset="UTF-8">
<title>My Page</title>
</head>
Troubleshooting Mojibake Errors
If a webpage has a missing or incorrect character set declaration, special characters like curly quotes, dashes, and accented letters will render as broken, garbled symbols (like é). This issue is called mojibake.
Example: Troubleshooting Mojibake Errors
<!-- Missing charset can cause: café to render as café -->
<meta charset="UTF-8">
Server Headers vs. HTML Meta Tags
When a visitor loads your webpage, your web server sends an HTTP header that specifies the content type and character set.
While the server's HTTP header has a higher priority than your HTML meta tag, including the meta charset tag in your HTML is still essential to ensure the page renders correctly when loaded locally.
Example: Server Headers vs. HTML Meta Tags
<!-- HTTP header: Content-Type: text/html; charset=UTF-8 -->
<meta charset="UTF-8">
- Forgetting to include the meta charset tag inside the head section of your HTML document.
- Placing the charset meta tag below heavy script or stylesheet links inside your head section.
- Saving your HTML files in a legacy format in your code editor while declaring UTF-8 in your code.
- A character set is a standardized key that tells the browser how to translate binary numbers into readable text characters.
- UTF-8 is the modern, universal web standard that supports almost all global languages, symbols, and emojis natively.
- Always place the meta charset="UTF-8" tag on the very first line inside your head section.
Standard HTML5 character declarations are natively supported by all modern and legacy web browsers.
Chapter Quiz — Complete all 20 topics to unlock
0/20 topics done
Complete these topics first:
- HTML Keyboard Shortcuts
- HTML Browser Support
- HTML Character Sets
- HTML Doctypes
- HTML Audio/Video Reference
- HTML Meta Tags
- HTML ARIA Roles
- HTML Input Validation
- HTML Iframe Security
- HTML Responsive Images
- HTML Web Fonts
- HTML Icon Fonts
- HTML Progress & Meter
- HTML Output Element
- HTML Datalist
- HTML Image Maps
- HTML Browser DevTools
- HTML Validation
- HTML Quiz
- HTML Interview Prep