Locales
Language and locale codes by country
A language code answers a different question from a locale tag. A locale adds useful regional or script context when the product needs it.
Language, script and region are separate choices
BCP 47 tags start with a language such as en or zh. An optional script, such as Hant, comes before an optional region, such as TW: zh-Hant-TW. A region alone is not a language tag.
Use hyphens for HTML and JavaScript Intl locale tags. Language is conventionally lowercase, script title case, and region uppercase. Tags are case-insensitive; CLDR data may use underscore-separated identifiers, which are not the spelling to pass directly to Intl.
| Tag | Meaning | Choose it when |
|---|---|---|
| en | English | Content needs no regional distinction |
| en-US | English, United States | US regional formatting is intended |
| zh-Hant | Chinese, Traditional script | Script matters without a specific region |
| zh-Hans | Chinese, Simplified script | Content uses Simplified characters |
| zh-Hant-TW | Chinese, Traditional script, Taiwan | Both script and Taiwan context matter |
| sr-Latn | Serbian, Latin script | Distinguish Latin from Cyrillic content |
Choose the least-specific tag that is correct
Use a language-only tag when a region or script does not change product behavior. Add a region or script only when the content, formatting, or user expectation actually requires it.
Do not infer a user preference from a country alone
Country data is a useful default for a reference page, not a substitute for a user-selected language. Preserve a user choice whenever the product can do so.
Use the tag, then verify runtime support
HTML lang describes content language. Intl.NumberFormat selects number conventions; locale does not translate the page. Set timeZone and currency separately when needed, rather than assuming the tag selects them.
Test supportedLocalesOf() and resolvedOptions() in your target runtime. Available locale data can differ. The examples below compare number formatting and set a date formatter's time zone explicitly.
Look up country data after choosing your approach
The directory is a country lookup table with sourced language and locale data. Use this guide to decide which distinctions your product needs, then open a country page for its codes and sources.
<html lang="zh-Hant">
new Intl.NumberFormat("en-US").format(1234.5); // "1,234.5"
new Intl.NumberFormat("de-DE").format(1234.5); // "1.234,5"
new Intl.DateTimeFormat("zh-TW", { timeZone: "Asia/Taipei" });Data provenance