NavigatorLanguage.language

The NavigatorLanguage.language read-only property returns a string representing the preferred language of the user, usually the language of the browser UI.

Syntax

lang = navigator.language 

Values

A string representing the language version as defined in BCP 47. Examples of valid language codes include "en", "en-US", "fr", "fr-FR", "es-ES", etc.

Note that in Safari on macOS and iOS prior to 10.2, the country code returned is lowercase: "en-us", "fr-fr" etc.

Example

if (window.navigator.language != 'en') {       
  doLangSelect(window.navigator.language); 
}

Specifications

Specification Status Comment
HTML 5.1
The definition of 'NavigatorLanguage.language' in that specification.
Recommendation Initial definition

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes)[1] (Yes) 1.0 (1.7 or earlier)[2]
5.0 (5.0)[3]
11.0[4] (Yes) (Yes)
on WorkerNavigator ? ? 35 (35) ? ? ?
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) 1.0 (1.0) No support[4] (Yes) (Yes)
on WorkerNavigator ? ? 35 (35) No support ? ?

[1] Returns the browser UI language, not the value of the Accept-Language HTTP header.

[2] Prior to Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1), this property's value was also part of the user agent string, as reported by navigator.userAgent.

[3] Starting in Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2), this property's value is based on the value of the Accept-Language HTTP header.

[4] Closest available (non-standard) properties are userLanguage and browserLanguage.

See also

Document Tags and Contributors

 Last updated by: Kornel,