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.

Language, script and region are separate choices
TagMeaningChoose it when
enEnglishContent needs no regional distinction
en-USEnglish, United StatesUS regional formatting is intended
zh-HantChinese, Traditional scriptScript matters without a specific region
zh-HansChinese, Simplified scriptContent uses Simplified characters
zh-Hant-TWChinese, Traditional script, TaiwanBoth script and Taiwan context matter
sr-LatnSerbian, Latin scriptDistinguish 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

Sources