navigator.language returns the user’s preferred BCP 47 language tag (usually the browser UI language). Learn the string format, Intl formatting, how it relates to navigator.languages, five examples, and try-it labs.
01
Kind
Read-only property
02
Returns
String (BCP 47)
03
Baseline
Widely available
04
Examples
en-US, fr-FR
05
Use with
Intl.*
06
Related
languages
Fundamentals
Introduction
Websites often want to greet users in their language, format dates the way they expect, and pick a sensible default locale. You do not need to guess — the browser already knows a preferred language.
navigator.language is read-only and returns that preference as a string, usually matching the browser UI language. Tags look like en, en-US, or fr-FR (BCP 47).
💡
Hint, not a hard requirement
Offer a language switcher. Some users keep the browser in English but prefer your site in another language. Use navigator.language as a smart default.
Concept
Understanding the language Property
Think of it as “which language does this browser say the user prefers first?”
BCP 47 tag — language, optional region (e.g. en-US).
Usually UI language — MDN: typically the language of the browser UI.
Single string — for the full preference list, see navigator.languages.
Intl-ready — pass the tag to Intl.DateTimeFormat, NumberFormat, etc.
Baseline — Widely available (MDN, since about July 2015).
Foundation
📝 Syntax
General form of the property:
JavaScript
navigator.language
Value
A string: BCP 47 language tag (e.g. en, en-US, fr-FR, es-ES).
Common patterns
JavaScript
// Read preferred language:
console.log(navigator.language);
// MDN-style Intl formatting:
const date = new Date("2012-05-24");
const formattedDate = new Intl.DateTimeFormat(navigator.language).format(date);
// Primary language subtag only:
const primary = navigator.language.split("-")[0]; // e.g. "en" from "en-US"
Cheat Sheet
⚡ Quick Reference
Goal
Code
Read preferred language
navigator.language
Type check
typeof navigator.language === "string"
Primary subtag
navigator.language.split("-")[0]
Format a date
new Intl.DateTimeFormat(navigator.language).format(date)
All preferences
navigator.languages
Status (MDN)
Baseline Widely available
Snapshot
🔍 At a Glance
Four facts to remember about navigator.language.
Returns
string
BCP 47 tag
Baseline
widely
Since ~Jul 2015
Means
preferred lang
Often UI lang
Pairs with
Intl
Format locale
Compare
📋 language vs languages
navigator.language
navigator.languages
Type
String
Array of strings
Meaning
Single preferred language
Ordered preference list
Typical link
languages[0] is usually the same as language
Use when
One default locale is enough
You offer fallbacks (en → en-US → …)
Hands-On
Examples Gallery
Examples follow MDN navigator.language patterns, including Intl formatting. Prefer Try It Yourself to see your browser’s preferred tag.
en
(or en-us / fr / es depending on your browser and supported list)
How It Works
Normalize case when comparing — older Safari used lowercase region codes like en-us.
Example 5 — Language Helper Object
Expose tag, primary subtag, and a short Intl sample for debug panels.
JavaScript
function languageInfo() {
const tag = navigator.language;
return {
language: tag,
primary: tag.split("-")[0],
sampleDate: new Intl.DateTimeFormat(tag).format(new Date("2012-05-24")),
advice: "Use as default locale; still offer a language switcher"
};
}
console.log(JSON.stringify(languageInfo()));
navigator.language is Baseline Widely available across modern browsers (MDN: since about July 2015). Use it as a default locale hint and pair it with Intl for formatting.
✓ Baseline · Widely available
Navigator.language
Read the preferred BCP 47 tag, format with Intl, and still offer a manual language switcher.
UniversalWidely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
languageExcellent
Bottom line: Use navigator.language for smart defaults. Prefer navigator.languages when you need a full preference list.
Wrap Up
Conclusion
navigator.language gives you the user’s preferred language as a BCP 47 tag. Use it to pick a default locale and drive Intl formatting — and keep a language switcher for users who want something different.
Baseline preferred-language string for locales and Intl.
5
Core concepts
🌐01
Returns
BCP 47 string
Type
💬02
Means
Preferred lang
UI
📅03
Use
Intl formatting
Locale
📚04
Related
languages[]
List
✅05
Status
Baseline
Wide
❓ Frequently Asked Questions
It is a read-only Navigator property that returns a string for the user’s preferred language — usually the language of the browser UI — in BCP 47 format such as en-US or fr-FR.
No. MDN marks it Baseline Widely available (since about July 2015). It is not Deprecated, Experimental, or Non-standard.
A BCP 47 language tag. Common examples: en, en-US, fr, fr-FR, es-ES. Older Safari on iOS (before 10.2) used lowercase region codes like en-us.
language is the single preferred language. languages is an array of preferred languages in preference order. The first item in languages is typically the same as language.
Pass navigator.language to Intl constructors, for example new Intl.DateTimeFormat(navigator.language).format(date), as shown on MDN.
No. It is read-only. Users change preferred language in browser or OS settings; your page only reads the tag.
Did you know?
MDN’s date example uses a fixed ISO string "2012-05-24" so you can clearly see how formatting changes with navigator.language — the date itself stays the same; only the display style changes.