Goal
- Cultivate content indexing by language.
- Facilitate machine translation.
- Enable correct reading of the content by a synthesized speech tool.
- Improve the accessibility of content for people with disabilities.
- Improve the way content is taken into account by search engines and indexing tools.
Implementation
Fill in the lang
attribute of the html
root element using the appropriate language code (as indicated in the registry maintained by IANA: http://www.iana.org/assignments/language-subtag-registry). In practice, for French this is: <html lang="fr"> (in HTML) et <html lang="fr" xml:lang="fr"> (in XHTML).
Otherwise, in more complex cases, the content language can be indicated by the different parent elements: head
, body
, title
, etc.
Find out more:
Control
Verification consists in checking that the lang attribute of the html
element is present and relevant (or failing that check its descendant elements) in the source code.
In the source code of each page:
- Check that the default language of the content is indicated by the
lang
attribute of thehtml
element, for example <html lang="fr"> (in HTML) - If not, check for each content element that is is at least inherited form a parent element (
head
,body
,title
, etc.) from itslang
attribute.
Check the validity and relevance of the language code used. For this, use for example the Language Subtag Lookup Tool by Richard Ishida, https://r12a.github.io/app-subtags/.
Common cases of incorrect language codes include jp
instead of ja
for Japanese, lu
instead of lb
for Luxembourgish, gr
instead of el
for Greek, lat
instead of la
for Latin, and oci
instead of oc
for Occitan. Additionally, the codes mul
for "multiple languages" and und
for "undetermined language" must not be used in web content. Finally, the xml:lang
can also be entered in addition to the lang
attribute, but it is not sufficient to comply with this best practice.
Discover Opquast training and certification
The objective of these rules and the Opquast community mission is ‘making the web better’ for your customers and for everyone! Opquast rules cover the key major areas of risk that can negatively affect website users such as privacy, ecodesign, accessibility and security.
Opquast training has already allowed over 19,000 web professionals to have their skills certified. Train your teams, contact us
We offer a 1 hour free discovery module.