Skip to content

The lang Attribute

Global Attribute

The lang attribute specifies the language of an element’s content. It helps search engines, screen readers, translation tools, and browsers provide appropriate language-specific features like spell-checking and hyphenation.

<element lang="language-code">Content</element>
ValueDescription
language-codeA valid BCP 47 language tag (e.g., en, es, fr-CA, zh-Hans)
Result
Result
Result
Result
CodeLanguageExample
enEnglish<p lang="en">Hello</p>
esSpanish<p lang="es">Hola</p>
frFrench<p lang="fr">Bonjour</p>
deGerman<p lang="de">Hallo</p>
itItalian<p lang="it">Ciao</p>
ptPortuguese<p lang="pt">Olá</p>
ruRussian<p lang="ru">Привет</p>
jaJapanese<p lang="ja">こんにちは</p>
zhChinese<p lang="zh">你好</p>
arArabic<p lang="ar">مرحبا</p>
koKorean<p lang="ko">안녕하세요</p>
hiHindi<p lang="hi">नमस्ते</p>
CodeLanguage & Region
en-USEnglish (United States)
en-GBEnglish (United Kingdom)
en-AUEnglish (Australia)
es-ESSpanish (Spain)
es-MXSpanish (Mexico)
fr-FRFrench (France)
fr-CAFrench (Canada)
pt-BRPortuguese (Brazil)
pt-PTPortuguese (Portugal)
zh-HansChinese (Simplified)
zh-HantChinese (Traditional)
Result

Screen readers use the lang attribute to:

  • Select the appropriate voice or pronunciation rules
  • Apply correct intonation and stress patterns
  • Pronounce special characters properly
Result

Browsers use the lang attribute to:

  • Offer automatic translation when content language differs from browser language
  • Improve translation accuracy by knowing source language
  • Skip translation for specific elements
<!-- Tell translation tools not to translate this element -->
<p lang="en" translate="no">
Product code: SKU-12345
</p>

Browsers may select different fonts based on language:

<!-- Japanese text -->
<p lang="ja">日本語のテキスト</p>
<!-- Chinese text (may use different glyphs) -->
<p lang="zh">中文文本</p>
<!-- Korean text -->
<p lang="ko">한국어 텍스트</p>

Search engines use lang to:

  • Index content in the appropriate language database
  • Show content to users searching in that language
  • Understand regional targeting
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>US-focused content</title>
</head>
<body>
<!-- Content optimized for US English speakers -->
</body>
</html>

Combined with hreflang for multi-language sites:

<!-- English version -->
<html lang="en">
<head>
<link rel="alternate" hreflang="es" href="https://example.com/es/">
<link rel="alternate" hreflang="fr" href="https://example.com/fr/">
</head>
<!-- Spanish version -->
<html lang="es">
<head>
<link rel="alternate" hreflang="en" href="https://example.com/">
<link rel="alternate" hreflang="fr" href="https://example.com/fr/">
</head>
<!-- Good: Language set on root element -->
<!DOCTYPE html>
<html lang="en">
<!-- page content -->
</html>
<!-- Avoid: No language specified -->
<!DOCTYPE html>
<html>
<!-- page content -->
</html>
<!-- Generic when region doesn't matter -->
<html lang="es">
<!-- Specific when targeting a region -->
<html lang="es-MX"> <!-- Mexican Spanish -->
<html lang="es-ES"> <!-- Castilian Spanish -->
<article lang="en">
<p>In French, hello is <span lang="fr">bonjour</span>.</p>
<p>The German word is <span lang="de">hallo</span>.</p>
</article>
<!-- Avoid: Unnecessary language tags -->
<p lang="en">
<span lang="en">This</span> <span lang="en">is</span>
<span lang="en">excessive</span>.
</p>
<!-- Better: One tag on container -->
<p lang="en">
This is better.
</p>
<!-- Wrong: Not a valid BCP 47 code -->
<html lang="english">
<html lang="EN">
<html lang="en_US">
<!-- Correct -->
<html lang="en">
<html lang="en-US">
<!-- Problematic: Screen readers won't know the language -->
<!DOCTYPE html>
<html>
<body>
<p>Content without language specification</p>
</body>
</html>
<!-- Better -->
<!DOCTYPE html>
<html lang="en">
<body>
<p>Content with language specified</p>
</body>
</html>
<!-- Wrong: Using wrong code -->
<p lang="sp">Spanish text</p> <!-- 'sp' is not Spanish -->
<!-- Correct -->
<p lang="es">Spanish text</p> <!-- 'es' is Spanish -->
Result

The lang attribute is supported by all browsers.

BrowserSupport
ChromeAll versions
FirefoxAll versions
SafariAll versions
EdgeAll versions
  • dir - Text direction (ltr/rtl)
  • translate - Whether to translate content