Dofactory.com
Dofactory.com
Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

HTML lang Attribute

The lang attribute specifies the language of an element‘s content.

Its value is used for site accessibility, translations, and SEO purposes.

Example

#

Three <p> tags with different lang attributes.
The languages are English, Spanish, and Korean.

This text is displayed in English.

Este texto se muestra en español.

이 텍스트는 한국어로 표시됩니다.

<p lang="en" style="background-color:#f6f8ff;padding:25px;">
   This text is displayed in English.
</p>
<p lang="es" style="background-color:#f6f8ff;padding:25px;">
   Este texto se muestra en español.
</p>
<p lang="ko" style="background-color:#f6f8ff;padding:25px;">
   이 텍스트는 한국어로 표시됩니다.
</p>

Using lang

The lang attribute specifies the language of an element's content.

This attribute is used for site accessibility, translations, and SEO purposes.

The lang value must be a 2-character value from the ISO Language Code list.

Example values: en for English, de for German, zh for Chinese, and zu for Zulu.

Values can also include region, such as en-GB, for English from Great Britain

Note:   lang is a global attribute that can be applied to any tag.

Note:   The lang attribute has no visual effect. It only adds semantics, i.e. additional meaning, to an element.


Syntax

<tag lang="lang" />

Values

#

Value Description
language-code-country-code The first 2 characters represent the language code of the page.
The last two characters represent the country code (optional).

Elements with a lang attribute

The lang attribute is a global attribute that can be applied to any element.

However, it is meaningful only on elements with text. Which are these?

Here are some elements:

  • lang on <html> defines the language for a page
  • lang on <p> defines the language for a paragraph
  • lang on <input> defines the language for an input control
  • lang on <textarea> defines the language for a textarea
  • And others...

Browser support

Here is when lang support started for each browser:

Chrome
4 Jan 2010
Firefox
2 Oct 2006
IE/Edge
1 Oct 2013
Opera
15 Jul 2013
Safari
6 Jul 2012

You may also like




Last updated on Sep 30, 2023

Earn income with your HTML skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides