How to know the browser language and browser platform in JavaScript?

In this article we are going to discuss how to know the browser language and browser platform with the help of examples in JavaScript

To know the various properties of the browser, JavaScript provides the Navigator object. The Navigator object has several properties, which include - connection, credentials, cookies, geolocation, language, platform, etc. We are concerned with Navigator.language and Navigator.platform to know the language and platform of the browser. Let us discuss about them in detail.

Navigator.language

The read-only Navigator.language property returns a string that represents the browser UI language. It returns a string that contains the language version. For example, 'en', 'en-US', 'fr', 'fr-FR', etc.

Example 1: Getting Browser Language

The following is an example program to determine the browser language.

<!DOCTYPE HTML>
<html>
<head>
   <title>How to know the browser language and browser platform in JavaScript</title>
</head>
<body style="text-align:center;">
   <h3>To Know the Language of the browser.</h3>
   <p id="text1"></p>
   <script type="text/javascript">
      document.getElementById("text1").innerHTML = "The Language of the browser is : " + navigator.language;
   </script>
</body>
</html>
The Language of the browser is : en-US

Example 2: Getting All Preferred Languages

To know the list of preferred languages set by the user, the property navigator.languages is used. They are displayed in the format of most preferred language to least preferred language by the user. The first element of the returned array is navigator.language. The following example demonstrates the navigator.languages property.

<!DOCTYPE HTML>
<html>
<head>
   <title>How to know the browser languages and browser platform in JavaScript</title>
</head>
<body style="text-align:center;">
   <h3>To Know the Languages of the browser.</h3>
   <p id="text1"></p>
   <script type="text/javascript">
      document.getElementById("text1").innerHTML = "The Languages of the browser are: " + navigator.languages.join(", ");
   </script>
</body>
</html>
The Languages of the browser are: en-US, en, fr

Navigator.platform

The read-only Navigator.platform property returns a string that represents the browser platform. Some of the platforms include 'MacIntel', 'MacPPC', 'Win32', 'Win16', 'Linux x86_64', and 'Linux i686'.

Note: The Navigator.platform property is deprecated in modern browsers. Consider using navigator.userAgentData.platform for newer implementations where available.

Example: Getting Browser Platform

The following is an example program to determine the navigator platform.

<!DOCTYPE HTML>
<html>
<head>
   <title>How to know the browser platform in JavaScript</title>
</head>
<body style="text-align:center;">
   <h3>To Know the Platform of the browser.</h3>
   <p id="text1"></p>
   <script type="text/javascript">
      document.getElementById("text1").innerHTML = "The Platform of the browser is: " + navigator.platform;
   </script>
</body>
</html>
The Platform of the browser is: Win32

Combined Example

Here's a complete example that demonstrates both language and platform detection:

<!DOCTYPE HTML>
<html>
<head>
   <title>Browser Language and Platform Detection</title>
</head>
<body style="text-align:center;">
   <h3>Browser Information</h3>
   <div id="info"></div>
   <script type="text/javascript">
      const info = document.getElementById("info");
      info.innerHTML = `
         <p><strong>Primary Language:</strong> ${navigator.language}</p>
         <p><strong>All Languages:</strong> ${navigator.languages.join(", ")}</p>
         <p><strong>Platform:</strong> ${navigator.platform}</p>
      `;
   </script>
</body>
</html>
Primary Language: en-US
All Languages: en-US, en, fr
Platform: Win32

Conclusion

The Navigator object provides easy access to browser language and platform information through navigator.language and navigator.platform properties. Use navigator.languages to get all user-preferred languages in order of preference.

Updated on: 2026-03-15T23:18:59+05:30

763 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements