Web Accessibility: The Importance of Declaring the Language in HTML

Who has never used Google Translate on a website and found out that the result was poor and not accurate at all? That’s why declaring the language in HTML on our websites helps more people than we can imagine and improves everyone’s experience.

What Does It Mean to Declare the Language?

It’s something as simple as including the lang attribute in our HTML tag. This attribute must have the correct language (we use ‘en’ for English and ‘es’ for Spanish). We can declare it like this:

<!DOCTYPE HTML>
  <html lang="es">
</html

Having this attribute on the HTML tag will allow all the other elements to inherit it, without the need to keep declaring it.

Its Impact on Web Accessibility

A correct use of the lang attribute will lead to:

  • screen readers using the correct pronunciation when reading the text, and
  • proper encoding on Braille keyboards.

Additional Benefits

Beyond accessibility benefits, declaring the language in HTML also helps to:

  • improve SEO,
  • optimizing the results we can get with automatic tools like translators or artificial intelligence.

That’s why it is so important that we do not assume the language of the content, and that we declare it always from the beginning.