The
`Intl` object
is the namespace for the
ECMAScript Internationalization API (ECMA-402). It's a powerful part of JavaScript for language-sensitive operations like string comparison, number formatting, and date/time formatting. This guide provides an interactive playground to explore its features.
How to use this guide:
Select an API from the navigation on the left. Each section provides a live playground. Change the inputs, locales, and options to see how the output changes in real time. This hands-on approach is the best way to learn!
Further Reading & Official Documentation
For a deeper dive and the official specification, refer to these essential resources:
Almost all `Intl` constructors share a common signature: `new Intl.Constructor(locales, options)`.
`locales`: A string or array of strings representing
BCP 47 language tags
(e.g., "en-US", "de-DE"). The environment picks the best-supported locale.
`options`: An object with configuration properties specific to the constructor.
What are BCP 47 Language Tags?
A
BCP 47 language tag
is a standardized code used to identify human languages. "BCP" stands for "Best Current Practice," and this standard ensures different systems can reliably understand which language and regional conventions to use.
The tags are built from smaller pieces called "subtags," separated by hyphens. The most common are:
Language:
A required two or three-letter code (e.g.,
en
for English,
es
for Spanish).
Script (Optional):
A four-letter code for the writing system (e.g.,
Hans
for Simplified Chinese script).
Region (Optional):
A two-letter country code (e.g.,
US
for the United States,
GB
for Great Britain).
Examples:
en-US: English (en) as used in the United States (US).
es-CL: Spanish (es) as used in Chile (CL).
zh-Hans-CN: Chinese (zh), written in the Simplified (Hans) script, as used in mainland China (CN).
These tags allow the
Intl
API to apply specific regional formats for dates, numbers, currencies, and sorting rules.
Finding Locales & Time Zones
To use the `Intl` API effectively, you need to provide valid BCP 47 language tags for locales and IANA identifiers for time zones. Here are some resources to find them.
Finding BCP 47 Language Tags
While you can often guess common tags (like `en-US` or `fr-FR`), the definitive list is maintained by the IANA (Internet Assigned Numbers Authority).
Official Registry:
The complete list of all valid language, region, and script subtags can be found at the
IANA Language Subtag Registry. This is the ultimate source of truth but can be dense to read.
User-Friendly Lists:
For a more accessible reference, you can find searchable lists on various websites. A common resource is the
Language Subtag Lookup tool.
Finding Time Zone Identifiers
Time zone names used by `Intl.DateTimeFormat` come from the
IANA Time Zone Database. These identifiers follow an `Area/Location` format.
Programmatic Access:
You can get an array of all time zones supported by the user's browser by running the following command in the browser's developer console:
console.log(Intl.supportedValuesOf('timeZone'));
Common examples include
America/New_York,
Europe/London,
Asia/Tokyo, and
Australia/Sydney.
Intl.DateTimeFormat
Formats dates and times in a locale-sensitive way. This is one of the most powerful and commonly used features of the Intl API.
Common Use Cases
Displaying an article's publication date in a user-friendly format.
Showing event start and end times in a calendar application.
Formatting timestamps for chat messages or activity logs.
Displaying dates on a booking website, respecting local conventions.
Experiment below with various locales and formatting options to see how the output changes.
Options
Live Example
Result
Intl.NumberFormat
Formats numbers, currencies, and units.
Common Use Cases
Formatting product prices on an e-commerce site (e.g., `$1,299.99` vs. `1.299,99 €`).
Displaying large numbers with compact notation (e.g., "1.2M followers").
Showing percentages in analytics dashboards.
Formatting scientific or technical data with units (e.g., "120 km/h").
Notice how decimal separators, grouping, and currency symbols change based on the selected locale and options.
Options
Live Example
Result
Intl.Collator
Provides language-sensitive string comparison for sorting. Default JavaScript `sort()` uses Unicode code points, which is often incorrect for alphabetical sorting in many languages.
Common Use Cases
Sorting a list of user names alphabetically in a contacts list.
Ordering product names in a dropdown filter on an e-commerce site.
Alphabetizing a list of countries or cities.
Correctly sorting file names that contain accented characters.
Select a locale to see how the list re-sorts correctly.
Options
Original List
émilie
Eva
emil
Äpple
apple
Zulu
Live Example
Sorted Result
Intl.PluralRules
Determines which plural category a number belongs to in a given language. English has "one" and "other", but other languages like Polish or Arabic have more complex rules.
Common Use Cases
Generating dynamic UI text like "You have 1 new message" vs. "You have 5 new messages".
Displaying search result counts: "Found 1 result" vs. "Found 10 results".
Handling complex pluralization for translation libraries (e.g., in Polish: "1 plik", "2 pliki", "5 plików").
This is essential for correct translations in applications that support multiple languages.
Options
Live Example
Resulting Plural Category
Intl.RelativeTimeFormat
Formats a time difference in a human-readable way, like "in 3 weeks" or "2 months ago".
Common Use Cases
Displaying timestamps on social media feeds ("posted 2 hours ago").
Showing upcoming deadlines ("due tomorrow").
Displaying countdowns ("event starts in 3 weeks").
Showing file modification times ("updated yesterday").
The `numeric: 'auto'` option allows for friendly terms like "yesterday" or "tomorrow".
Options
Live Example
Result
Intl.ListFormat
Formats a list of strings with locale-appropriate connectors.
Common Use Cases
Listing authors of an article: "John, Jane, and Sarah".
Showing a list of tags on a blog post: "Technology, JavaScript, and Web Dev".
Listing items in a shopping cart summary: "You have a shirt, pants, and shoes in your cart".
Displaying options in a confirmation dialog: "Do you want to save, discard, or cancel?".
This handles things like the Oxford comma in English correctly.
Options
Live Example
Result
Intl.DisplayNames
Provides translated names for languages, regions, scripts, or currencies.
Common Use Cases
Showing a readable language name in a language selector dropdown (e.g., "Español" instead of "es").
Displaying the full country name from a region code (`US` -> "United States").
Showing the name of a currency in a financial application (`JPY` -> "Japanese Yen").
Converting a script code to its name (`Latn` -> "Latin").
For example, it can tell you that "de" is "German" in English or "allemand" in French.
Options
Live Example
Result
Intl.Segmenter
Provides locale-sensitive text segmentation.
Common Use Cases
Accurately counting the number of "characters" in a string that includes multi-code-point emoji.
Implementing a word counter for a text editor that works for languages without spaces (e.g., Japanese, Thai).
Highlighting the current sentence a user is reading in a text-to-speech application.
Splitting text into words for search indexing or keyword analysis.
It can correctly split a string into graphemes (what users perceive as characters), words, or sentences, which is far more reliable than `string.split()`.
Options
Live Example
Resulting Segments
Intl.Locale
A constructor to parse and manipulate BCP 47 locale identifier strings.
Common Use Cases
Extracting the base language from a complex locale to fall back to a more general language if needed.
Reading user preferences from a locale string (e.g., `u-hc-h23` for 24-hour time) to customize the UI.
Validating that a user-provided string is a well-formed locale identifier.
Programmatically building or modifying locale strings.
It allows you to programmatically access parts of a locale string like the language, region, or script.
Input
Live Example
Parsed Properties
The Future: Interaction with Temporal API
The
Temporal API
is a new, modern date/time API for JavaScript, currently at Stage 3 in the TC39 process. It is designed to be a superior replacement for the old `Date` object.
Temporal objects can be passed directly to `Intl.DateTimeFormat` instances, creating a clean, robust way to work with dates and times.
A Note on Polyfills and Native Support
The conceptual examples below use a
polyfill
to make the `Temporal` API work in all browsers. However, there's a crucial distinction to understand:
The
polyfill
creates the `Temporal` objects (like
ZonedDateTime).
The browser's
native
Intl
engine
is what actually formats the date.
In browsers without native `Temporal` support (e.g., Chrome), the `Intl` engine has not been updated to understand these new objects. The polyfill cannot change this internal browser behavior. Therefore, to ensure compatibility, our examples perform a final conversion from a `Temporal` object to a legacy `Date` object (e.g.,
new Date(zdt.toInstant().epochMilliseconds)) just before formatting. This allows you to use the modern `Temporal` API for all your logic and only convert at the very last step for display.
Example: ZonedDateTime Formatting
Format a specific moment in time (a date, time, and timezone) for a user in a specific locale.
// This conceptual code requires the Temporal polyfill to run.
// 1. Create an immutable Temporal object.
const zonedDateTime = Temporal.ZonedDateTime.from({
year: 2025,
month: 8,
day: 29,
timeZone: 'America/Los_Angeles',
});
// 2. Format it using Intl.DateTimeFormat.
const formatter = new Intl.DateTimeFormat('de-DE', {
dateStyle: 'full',
timeStyle: 'long',
timeZone: 'America/Los_Angeles',
});
// Note: In browsers without native Temporal support, we must convert
// to a legacy Date object before formatting.
const legacyDate = new Date(zonedDateTime.toInstant().epochMilliseconds);
// The formatted output will be similar to:
// "Freitag, 29. August 2025 um 00:00:00 PDT"
console.log(formatter.format(legacyDate));
Example: PlainDate Formatting
Format a calendar date that has no time or timezone information, like a birthday.
// This conceptual code requires the Temporal polyfill to run.
// 1. Create a date object without time or timezone.
const plainDate = Temporal.PlainDate.from({
year: 1776,
month: 7,
day: 4,
});
// 2. Format it using Intl.DateTimeFormat.
const formatter = new Intl.DateTimeFormat('en-US', {
dateStyle: 'long',
timeZone: 'UTC', // Required for consistent output
});
// Note: In browsers without native Temporal support, we must convert
// to a legacy Date object before formatting.
const legacyDate = new Date(Date.UTC(plainDate.year, plainDate.month - 1, plainDate.day));
// The formatted output will be:
// "July 4, 1776"
console.log(formatter.format(legacyDate));