Language Codes

The lang attribute (and hreflang on links, srclang on <track>) takes a BCP 47 language tag: a primary language, usually a two-letter ISO 639-1 code, then optional hyphen-separated subtags for script (ISO 15924, Hant) and region (ISO 3166-1 or a UN number, TW, 419). Tags are case-insensitive but conventionally written zh-Hant-TW, and every valid subtag is listed in the IANA Language Subtag Registry. Use the shortest correct tag: fr unless the regional variant really differs.

Common language tags (iw and in were deprecated in 1989)
Language Tag Language Tag Language Tag
English (US, UK) en-US en-GB Arabic, Persian ar fa Chinese (Simplified) zh-Hans
Spanish (Latin Am.) es es-419 Hebrew he (not iw) Chinese (Traditional) zh-Hant
Portuguese (Brazil) pt pt-BR Hindi, Bengali hi bn Japanese, Korean ja ko
French (Canada) fr fr-CA Urdu, Turkish ur tr Vietnamese, Thai vi th
German, Italian de it Russian, Ukrainian ru uk Indonesian id (not in)
Dutch, Polish nl pl Swahili sw Malay, Filipino ms fil

Screen readers pick a voice from the tag and browsers use it for hyphenation, spell checking and :lang(). For Chinese, Japanese and Korean it also selects glyphs, because Unicode unifies Han characters each locale draws differently:

The same code points under three lang valuesHTMLLive
<div style="font: 32px sans-serif">
  <div lang="ja">骨 次 册 写 真 (ja)</div>
  <div lang="zh-Hans">骨 次 册 写 真 (zh-Hans)</div>
  <div lang="ko">骨 次 册 写 真 (ko)</div>
</div>
Browser output of Listing 2.55
Browser output of 55

On multilingual sites, add <link rel="alternate" hreflang="fr-CA" href="..."> for every translation. Google requires a language before any region (en-GB, never GB), reserves x-default for the fallback page, and detects a page's language from its text, not from lang.