GMT+1
Berlin

HTML element has a valid value for its lang attribute

Published on ·
By

When building a website, it's easy to overlook some of the seemingly minor details that can have a big impact on accessibility and search engine optimization (SEO). One such detail, often flagged in the Accessibility section of a PageSpeed report, is the lang attribute on the html element. This attribute specifies the language of the document's content, and ensuring it has a valid value is a simple yet crucial step.

different names of langugages
<html lang="en-US">

Setting a correct lang attribute helps screen readers and other assistive technologies to pronounce the text correctly. It also gives search engines a better understanding of your content, which can improve your site's ranking for users searching in that specific language.

Here is a list of possible values for the lang attribute, based on the IANA Language Subtag Registry. This list is by no means exhaustive, as the registry contains codes for thousands of languages. However, these are some of the most common two-letter codes. You can also add a region subtag for more specific cases, separated by a hyphen - (e.g., en-US for American English, en-GB for British English).

The most popular language codes

For a full and up-to-date list of all language subtags, you can refer to the IANA Language Subtag Registry.

screenshot of the ebay.de homepage html code
Ebay.com HTML code

To quote or not to quote

You might occasionally see the lang attribute, or other HTML attributes, written without quotation marks, like <html lang=de>, for example https://www.ebay.de/. While this syntax is technically valid in certain situations within the HTML standard, it is not considered best practice.

It is highly recommended to always wrap attribute values in either single or double quotes (<html lang="de">). Here's why:

  • Readability and Consistency: Quotes make your code cleaner and easier for other developers to read and understand.
  • Preventing Errors: If an attribute value contains a space or a special character, quotes are mandatory. Failing to use them consistently can lead to syntax errors. For example,
    would be interpreted incorrectly by browsers.
  • XML Compatibility: In stricter standards like XHTML and XML, quotes are always required. Adopting the habit of always using quotes ensures your code is compatible with a wider range of standards and tools.

Is your website struggling with PageSpeed scores? I can help you with a complete website optimization and performance improvement.

Which communication tool
is best for you?