Language Codes

HTML language codes, specified by the lang attribute, indicate the language of the content, helping browsers and search engines display and interpret it correctly.

HTML Language Codes

Language codes are used in HTML to specify the language and regional variations of web content. This helps browsers, search engines, and assistive technologies interpret the content correctly.

Types of Language Codes

  • ISO 639 – Represents general language codes (e.g., en for English, fr for French).
  • ISO 3166 – Defines country-specific language variations (e.g., en-US for American English, fr-CA for Canadian French).

Specifying Language in HTML

The lang attribute tells browsers and screen readers the language of an element’s content. While it's often set in the <html> tag, it can also be used on paragraphs , divs , or spans for multilingual sections.

Declaring a Document's Language

Welcome!

This page is in English.

index.html
<h1>Welcome!</h1>
<p>This page is in English.</p>

Defining Multiple Languages in a Page

For multilingual pages, assign the lang attribute to different sections:

Hello World

Bonjour le monde

Hola Mundo

Hallo Welt

index.html
<h1>Hello World</h1>
<p lang="fr">Bonjour le monde</p> <!-- French -->
<p lang="es">Hola Mundo</p> <!-- Spanish -->
<p lang="de">Hallo Welt</p> <!-- German -->

Common Language Codes

Standard Language Codes (ISO 639)

  • en – English
  • fr – French
  • de – German

Regional Language Variants (ISO 3166)

  • en-US – English (United States)
  • fr-CA – French (Canada)
  • es-MX – Spanish (Mexico)

Benefits of Using the lang Attribute

  • Improves accessibility – Helps screen readers pronounce content correctly.
  • Enhances search optimization – Assists search engines in serving region-appropriate content.
  • Supports formatting adjustments – Some browsers apply language-specific text styling.

Conclusion

HTML language codes, defined by the lang attribute, specify the language and regional variations of content to ensure proper interpretation by browsers and assistive technologies. Using the lang attribute enhances accessibility, search optimization, and formatting adjustments.