JavaScript Navigator language Property

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline

What You’ll Learn

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

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.

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).

📝 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"

⚡ Quick Reference

GoalCode
Read preferred languagenavigator.language
Type checktypeof navigator.language === "string"
Primary subtagnavigator.language.split("-")[0]
Format a datenew Intl.DateTimeFormat(navigator.language).format(date)
All preferencesnavigator.languages
Status (MDN)Baseline Widely available

🔍 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

📋 language vs languages

navigator.languagenavigator.languages
TypeStringArray of strings
MeaningSingle preferred languageOrdered preference list
Typical linklanguages[0] is usually the same as language
Use whenOne default locale is enoughYou offer fallbacks (en → en-US → …)

Examples Gallery

Examples follow MDN navigator.language patterns, including Intl formatting. Prefer Try It Yourself to see your browser’s preferred tag.

📚 Getting Started

Read the tag and extract the primary language.

Example 1 — Read Preferred Language

Log the BCP 47 string your browser reports.

JavaScript
console.log(navigator.language);
console.log("type: " + typeof navigator.language);
Try It Yourself

How It Works

The value is always a string on modern browsers — not an array (that is languages).

Example 2 — Primary Language Subtag

Take the part before the hyphen for coarse matching (en from en-US).

JavaScript
const tag = navigator.language;
const primary = tag.split("-")[0].toLowerCase();
console.log("tag: " + tag);
console.log("primary: " + primary);
Try It Yourself

How It Works

Useful when you ship en.json / fr.json files but users report en-GB or fr-CA.

📈 Practical Patterns

Intl formatting, locale picking, and a small helper.

Example 3 — Format a Date with Intl

MDN’s pattern: pass navigator.language to Intl.DateTimeFormat.

JavaScript
const date = new Date("2012-05-24");
const formattedDate = new Intl.DateTimeFormat(navigator.language).format(date);
console.log(formattedDate);
Try It Yourself

How It Works

Same idea works with Intl.NumberFormat and Intl.RelativeTimeFormat.

Example 4 — Pick a Supported Site Locale

Choose the best match from the languages you actually ship.

JavaScript
function pickLocale(supported, fallback) {
  const tag = (navigator.language || fallback).toLowerCase();
  const primary = tag.split("-")[0];
  if (supported.includes(tag)) return tag;
  if (supported.includes(primary)) return primary;
  return fallback;
}

console.log(pickLocale(["en", "en-us", "fr", "es"], "en"));
Try It Yourself

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()));
Try It Yourself

How It Works

Combine with navigator.languages when you need fallback chains beyond the first preference.

🚀 Common Use Cases

  • Default UI locale — load the closest translation pack on first visit.
  • Date / number formatting — feed Intl constructors the user’s tag.
  • Content negotiation — hint which localized blog or help docs to show.
  • Analytics — understand preferred languages (without over-fingerprinting).
  • Forms — pre-select a language dropdown value.

🧠 How navigator.language Works

1

User / OS sets a language

Browser UI language reflects that preference.

Settings
2

Browser exposes a BCP 47 tag

navigator.language returns that string.

Read
3

Your app picks a locale

Match translations or pass the tag to Intl.

Apply
4

Still allow overrides

Remember the choice in settings / cookies when the user switches language.

📝 Notes

  • Baseline Widely available (MDN, since about July 2015).
  • Not Deprecated, Experimental, or Non-standard — no status banner required.
  • Value is a BCP 47 language tag string.
  • Old Safari on iOS (before 10.2) used lowercase region codes (en-us).
  • Related: languages, keyboard, JavaScript hub.

Universal Browser Support

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.

Universal Widely available
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
language Excellent

Bottom line: Use navigator.language for smart defaults. Prefer navigator.languages when you need a full preference list.

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.

Continue with languages, keyboard, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use it as a default locale hint
  • Pass it to Intl formatters
  • Compare tags case-insensitively
  • Fall back from en-GB to en when needed
  • Let users override with a switcher

❌ Don’t

  • Force a language with no override
  • Assume the tag always includes a region
  • Confuse it with navigator.languages (array)
  • Use it alone for legal geo-blocking
  • Ignore saved user language preferences

Key Takeaways

Knowledge Unlocked

Five things to remember about language

Baseline preferred-language string for locales and Intl.

5
Core concepts
💬 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.

Explore languages Next

Learn the ordered preference list for Intl and i18n fallbacks.

languages →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful