htmlmultilingualsemantic-markuphreflang

Semantic use of hreflang and lang attribute


This is not a SEO question.

I am curious how to markup HTML in a semantic correct way concerning the used language. Please correct me if my markup is mistaken.

My questions is: do I need the lang attribute in the html tag when I already use the hreflang attribute in the link tag?

Are both directives semantically different? I mean: will the self-reference in the link tag in both examples semantically be understood as indicating the language of the document?

The code samples below might clarify my question a bit:

Example of an English webpage

http://example.com/en/

<!DOCTYPE html>
<html lang="en"> 
<head>
     <title>English webpage</title>
     <link rel="canonical" href="http://example.com/en">
     <link rel="alternate" href="http://example.com/en/" hreflang="en">
     <link rel="alternate" href="http://example.com/nl/" hreflang="nl">
     <link rel="alternate" href="http://example.com/en/" hreflang="x-default">
</head>
<body>
     <p>This is a webpage written in English. 
        This page is also available in Dutch. 
        The default language of this page is English. 
</body>
</html>

Example of a Dutch webpage

http://example.com/nl/

<!DOCTYPE html>
<html lang="nl"> 
<head>
     <title>Nederlandse webpagina</title> 
     <link rel="canonical" href="http://example.com/nl">
     <link rel="alternate" href="http://example.com/en/" hreflang="en">
     <link rel="alternate" href="http://example.com/nl/" hreflang="nl">
     <link rel="alternate" href="http://example.com/en/" hreflang="x-default">
</head>
<body>
     <p>Dit is een Nederlandstalige web pagina. 
        Deze pagina is beschikbaar in het Engels. 
        De standaardtaal van deze pagina is Engels.
</body>
</html>

Solution

  • You should always provide the lang attribute on the html element.

    Two reasons relevant to your case:


    Even if a user agent deduces the language of the document by taking self-referential¹ alternate+hreflang links into account, there are situations in which this could fail:

    (With a canonical link, both situations could be mitigated, but that’s one more thing a user agent would have to support. Not all do.)


    ¹ Strictly speaking, a self-referential alternate+hreflang hyperlink is not semantic, because alternate is defined to refer to "an alternate representation of the current document", but a document is of course not an alternate representation of itself. However, as Google Search documents its use, it’s now common to see this markup.