lang
HTML lang Attribute
Some Common Examples are
en
for English,es
for Spanish,fr
for French ,ko
for Korean ,ja
for Japanese,ru
for Russian and so on.
Definition
The lang
attribute helps define the language of an element. The lang
attribute is a Global Attribute, and can be used on any HTML element.
Basic & Minimal HTML Structure
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=devicewidth, initial-scale=1.0"> </head> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html>
The lang
attribute has the value en
. These element attributes are very important because they specify the language of the document.
html lang
Example
<p lang="en">Hello World</p> <p lang="es">Hola Mundo</p> <p lang="de">Hallo Welt</p> <p lang="fr">Bonjour le monde</p> <p lang="pt">Olá Mundo</p> <p lang="ja">こんにちは世界</p> <p lang="ru">Привет, мир</p> <p lang="ko">안녕하세요 세계</p>
lang attributes
Note: It is always recommended to specify lang attribute with the appropriate value because the default value of lang is unknown.
[lang='fr']::before { content: '(Hello World in French) '; } [lang='ja']::before { content: '(Hello World in Japanese) '; }
Browser Support
Attributes | Chrome | Edge | Mozilla | Safari | Opera |
---|---|---|---|---|---|
lang | yes | yes | yes | yes | yes |