Chapter 8: Content Languages

Syntax • Remarks The value of the lang attribute must be a valid BCP 47 language tag or the empty string (if the language is unknown). The BCP 47 language tags are listed in the IANA Language Subtag Registry. Accessibility The relevant WCAG 2.0 Success Criteria are: • 3.1.1 Language of Page • 3.1.2 Language of Parts The related WCAG 2.0 Techniques are: • H57: Using language attributes on the html element • H58: Using language attributes to identify changes in the human language Examples Element Language The lang attribute is used to specify the language of element content and attribute text values:

The content of this element is in English.

The content of this element is in English. The language declaration gets inherited:

This element contains English content.

Same with this element. Elements with Multiple Languages

You can “overwrite” a language declaration:

This English sentence contains the German word Hallo. Handling Attributes with Different Languages You can “overwrite” a parent element’s language declaration by introducing any element apart from applet, base, basefont, br, frame, frameset, hr, iframe, meta, param, script (of HTML 4.0) with an own lang attribute:

Hallo Welt! Base Document Language It’s a good practice to declare the primary language of the document in the html element: If no other lang attribute is specified in the document, it means that everything (i.e., element content and attribute text values) is in that language. If the document contains parts in other languages, these parts should get their own lang attributes to “overwrite” the language declaration. Regional URLs It is possible to add the attribute hreflang to the elements and that create hyperlinks. Such it specifies the language of the linked resource. The language defined must be a valid BCP 47[1] language tag.

example.org is one of IANA’s example domains. ↑ IETF Network Working Group: RFC 5646 Tags for Identifying Languages, IETF, September 2009

Leave a comment