Don’t forget the lang attribute

Category: Web Dev Zoo

Tagged: zoo, html

Published at:

Poorly drawn hellbender with a text in a speech bubble: “HTML hellbender says: Don’t forget the lang attribute to define the default language.”

HTML hellbender says:

Don’t forget the lang attribute to define the default language.

And here’s why:

  • Screen readers use the lang attribute to pronounce words correctly and adjust voice settings, making content easier to understand.
  • Search engines like Google use the lang attribute to serve the right content to the right audience.
  • Browsers and translation tools rely on the lang attribute to identify the language and improve translations.
  • Some languages have specific hyphenation and formatting rules that work better when the correct language is set.
  • Standards like WCAG recommend defining the default language for better accessibility.

Here are some tips on defining the lang attribute.

  • Use simple codes like en for English, de for German, or fr for French to define the main language.
  • Use specific codes like en-GB for British English or en-US for American English to define regional differences.
  • If part of your content is in another language, wrap it in a tag with a different lang attribute:
  • <p lang="fr">Ce texte est en français.</p>