Lang Codes in HTML
? Language Codes in HTML (lang attribute)
The lang attribute in HTML specifies the language of the content in an element, helping browsers, search engines, and assistive technologies understand the language context.
Why Use lang?
Improves accessibility (screen readers pronounce words correctly)
Helps search engines with indexing
Enables proper hyphenation and spell checking
Supports translation tools
How to Use the lang Attribute
Add lang to the <html> tag to specify the language for the whole document:
<html lang="en"> ...</html>You can also use lang on any other element to specify a different language for that section:
<p lang="fr">Bonjour tout le monde!</p>Common Language Codes (BCP 47 format)
| Language | Code | Example |
|---|---|---|
| English | en | <html lang="en"> |
| Spanish | es | <p lang="es">Hola</p> |
| French | fr | <p lang="fr">Bonjour</p> |
| German | de | <p lang="de">Guten Tag</p> |
| Chinese (Simplified) | zh-Hans | <p lang="zh-Hans">??</p> |
| Chinese (Traditional) | zh-Hant | <p lang="zh-Hant">??</p> |
| Arabic | ar | <p lang="ar">?????</p> |
| Japanese | ja | <p lang="ja">?????</p> |
| Russian | ru | <p lang="ru">??????</p> |
Regional Variations
You can specify country or region variants:
<html lang="en-US"> <!-- English (United States) --><html lang="en-GB"> <!-- English (United Kingdom) --><html lang="pt-BR"> <!-- Portuguese (Brazil) -->Summary
<!DOCTYPE html><html lang="en"><head> <title>Example Page</title></head><body> <p lang="es">Hola, ¿cómo estás?</p></body></html>Need a full list of language codes or how to use lang for multilingual sites?