Ensure that HTML elements with both valid lang and xml:lang attributes agree on the base language of the page
To maintain accessibility, the <html>
element should have matching lang
and xml:lang
attributes, both specifying the same primary language of the document.
About This Rule
This rule ensures that the <html>
element has consistent lang
and xml:lang
attributes, both containing valid and identical language codes. Adhering to this practice enhances accessibility for users of assistive technologies by providing clear language declarations.
Why It Matters
Screen readers and other assistive technologies rely on language attributes to determine the correct pronunciation and interpretation of content. Inconsistent or missing language declarations can lead to misinterpretation, making content difficult to understand for users who depend on these technologies.
How to Fix
To ensure consistency:
-
Add Matching Language Attributes: Assign both
lang
andxml:lang
attributes to the<html>
element, ensuring they have identical values. For example, for an English document: - Use Valid Language Codes: Utilize standard language codes, such as "en" for English, "fr" for French, or more specific codes like "en-US" for American English. A comprehensive list of language codes is available on the ISO Codes for the Representation of Names of Languages.
-
Specify Languages for Sections: For documents containing multiple languages, apply the
lang
attribute to relevant elements: -
Indicate Text Direction for Right-to-Left Languages: For languages like Arabic or Hebrew, include the
dir
attribute:
Other Rules
Interested in other web accessibility rules? Please see these other rules: