
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - DOM Element lang Property
The HTML DOM Element lang property is used to get (retrieve) and set (update) the language of the current HTML document or any specific element.
In HTML, lang is an attribute that specifies the language code, such as 'en' for English or 'fr' for French, indicating the language of the content within that element.
Syntax
Following is the syntax of the HTML DOM Element lang (to set the property) −
element.lang = lang_code;
Here, the lang_code is the language of content within the element.
Use the following syntax to get the property −
element.lang
Parameters
Since this is a property, it will not accept any parameter.
Return Value
This property returns a string containing the value of the element's lang attribute.
Example 1: Retrieving the lang Property Value
The following is the basic example of the HTML DOM Element lang property. It displays the value of the 'lang' (language) property applied to the<html> element −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element lang</title> </head> <body> <h3>HTML DOM Element lang Property</h3> <p id="ex">This paragraph is in English.</p> <button onclick="displayLangAttribute()">Display Lang Property</button> <div id="output"></div> <script> function displayLangAttribute() { const my_ele = document.querySelector("html"); const langAttribute = my_ele.lang; const res = `<p>Lang Attribute Value: ${langAttribute}</p>`; document.getElementById('output').innerHTML = res; } </script> </body> </html>
The above program displays the "lang" property value in the HTML element.
Example 2: Setting the 'lang' Property to DIV
Following is another example of the HTML DOM Element lang property. We use this property to set the lang property value to the <div> element −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element lang</title> </head> <body> <h3>HTML DOM Element lang Property Example</h3> <p>Click the button to set lang property to "div" below.</p> <div>Inside div</div><br> <button onclick="set_prop()">Set "lang" Property</button> <p id="res"></p> <script> function set_prop() { let my_ele = document.querySelector('div'); my_ele.lang = "fr"; document.getElementById('res').innerHTML="lang property has been set"; } </script> </body> </html>
After executing the above program, the "lang" property is set to the "div" element.
Example 3: Displaying 'lang' Property in Various Sections
In the example below, we use the lang property to display its value in various sections −
<!DOCTYPE html> <html lang="en"> <head> <title>HTML DOM Element lang</title> </head> <body> <h1>HTML DOM Element lang Property Example</h2> <p>It displays the 'lang' property for both English and France paragraphs.</p> <article id="article1" lang="en"> <h2 lang="en">Introduction</h2> <p lang="en">This is the introduction paragraph in English.</p> </article> <article id="article2" lang="fr"> <h2 lang="fr">Introduction</h2> <p lang="fr">Ceci est le paragraphe d'introduction en franais.</p> </article> <button onclick="displayLangAttributes()">Display Lang Property</button> <p id="ot"></p> <script> function displayLangAttributes() { const art=document.querySelectorAll('article'); let res="<p><b>Lang Attributes:</b></p>"; art.forEach(article => { const articleId = article.id; const articleLang = article.lang; res+=`<p>${articleId}-Lang:${articleLang}</p>`; }); document.getElementById('ot').innerHTML =res; } </script> </body> </html>
The above program displays the "lang" property value in various sections.
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
lang | Yes | Yes | Yes | Yes | Yes |