HTML Character Encoding and UTF-8
Declare the encoding
Encoding maps bytes to characters. Save HTML as UTF-8 and place the complete meta charset declaration within the first 1024 bytes. This declaration does not convert incorrectly saved bytes.
<!doctype html><html lang="en"> <head> <title>Metadata practice</title> <meta charset="utf-8"> </head> <body> <p>café — سلام</p> </body></html>The Unicode text is intact in this already-decoded local example.
Language is not encoding
lang identifies a human language; dir describes direction. Neither selects a byte encoding. UTF-8 can represent both Persian and English in one document.
<!doctype html><html lang="en"> <head> <title>Metadata practice</title> <meta charset="utf-8"> </head> <body> <p lang="fa" dir="rtl">سلام دنیا</p> <p lang="en">Hello world</p> </body></html>Two languages coexist without changing charset.
Character references after decoding
A numeric character reference is parsed from decoded markup. It is not an alternative to correctly encoding the entire file. A server Content-Type charset and any byte order mark can affect decoding; keep actual bytes and declarations consistent.
<!doctype html><html lang="en"> <head> <title>Metadata practice</title> <meta charset="utf-8"> </head> <body> <p>é = é</p> </body></html>Both sides show é. This tests parsing, not raw-byte encoding detection.
Common mistakes and practice
If text looks corrupted, inspect the actual file encoding and response headers rather than changing lang or escaping every character.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTML Character Encoding and UTF-8 — Knowledge Check
Apply the metadata concepts taught in this lesson.
Which encoding should new HTML use?
Where must the complete charset declaration fit?
Does lang="fa" choose encoding?
Will changing meta alone repair wrongly saved bytes?
What does é represent?