Internationalization
Fundamentals Chapter 1 introduced lang="en" on <html> as a quick rule. This chapter covers why it matters beyond a checkbox, how to mark mixed-language content correctly, and the encoding details that explain real, occasionally baffling text-rendering bugs.
lang — More Than One Attribute, More Than Once
- Screen readers switch pronunciation for the inner
lang-tagged span, reading the French phrase with French phonetics rather than mispronouncing it as English text. - Browser spell-check stops flagging the foreign phrase as a misspelling within an otherwise English document.
- CSS can target language via the
:lang()pseudo-class, for language-specific typography rules (quotation mark styles genuinely differ between languages).
Hreflang — Multiple Language Versions of the Same Content
For a site genuinely offering the same content in multiple languages at different URLs, hreflang link tags (in <head>) tell search engines which version to show users searching in each specific language — directly relevant should osztromok.com ever offer translated versions of its Hungarian-language-learning content, for instance.
Right-to-Left Text — the dir Attribute
Languages like Arabic and Hebrew read right-to-left — dir="rtl" doesn't just reverse the text itself (the browser already handles that based on the actual characters), it reverses the entire layout flow: where padding/margins effectively apply, which side elements align to, the direction lists indent.
dir="auto" inspects the first strongly-directional character actually typed and sets direction automatically — useful specifically for that unpredictable-content case, though an explicit dir value is preferable whenever the language is actually known ahead of time.
Character Encoding — Where Real Bugs Actually Come From
Fundamentals Chapter 1 established <meta charset="UTF-8"> as the modern standard. The edge cases worth understanding: what actually goes wrong, and why, when encoding is mismatched.
| Symptom | Likely cause |
|---|---|
| Garbled characters (mojibake), e.g. "’" instead of an apostrophe | A file saved/read in a different encoding than declared — classic mismatch between actual bytes and the declared charset |
| Question marks or boxes (□) replacing some characters | The character genuinely doesn't exist in the encoding/font being used to render it |
| Correct in the editor, garbled in the browser | charset meta tag missing or declared after too much content, or the actual file saved in a different encoding than the meta tag claims |
Chapter 11 Quick Reference
- lang — set on <html> for the document, and on individual elements for foreign-language phrases within otherwise different-language content
- lang affects: screen reader pronunciation, spell-check, CSS :lang() targeting, search engine regional serving
- hreflang link tags — declare alternate-language versions of the same content at different URLs
- dir="rtl" — reverses entire layout flow, not just text direction, for right-to-left languages
- dir="auto" — detects direction from actual content; useful for unpredictable user-generated text
- Mojibake/garbled text — almost always an encoding mismatch between actual bytes and declared/assumed charset
- charset meta tag must be among the very first bytes — browsers guess encoding from early content if it's declared too late
- Next chapter (final, capstone): building an accessible, performant, semantic multi-feature page