liveBook · Manning

Lang attribute

As explained in Architecting Accessibility

The lang attribute identifies the natural language of an HTML element's content.

If a screen reader reads English text using French pronunciation rules, the words may be difficult to understand. The HTML lang attribute identifies the language of an element’s content so assistive technology can use an appropriate speech synthesizer. It also supplies language information for braille translation and search indexing. section 4.2

Set the page language

Put the main language on the html element: <html lang="en">. Do this for each page of a multilingual site, using that page’s language. Without lang, a screen reader may fall back to the user’s default language rather than the language of the page. section 2.5.1 section 4.2

Mark a change within the page

For a French passage on an otherwise English page, mark the passage itself: <div lang="fr"><p>J’aimerais parler français couramment</p></div>. The language value is an IETF BCP 47 tag, such as en or fr. section 4.2

<nav aria-label="Language Selector">
   <ul class="lang-selector">
     <li>
       <a href="../en/index.html" 
         hreflang="en" 
         lang="en" 
         aria-current="page">English</a>
     </li>
     <li>
       <a href="../es/index.html"
         hreflang="es" 
         lang="es">Español</a>
     </li>
     <li>
       <a href="../fr/index.html" 
         hreflang="fr" 
          lang="fr">Français</a>
     </li>
   </ul>
</nav>

This language selector marks each link’s visible language name with its own lang value; the page still needs its main language on the html element. section 4.2

How Architecting Accessibility covers it

How deep it goes
Explains page-level and passage-level placement, screen-reader fallback, and BCP 47 tags without detailing speech-synthesizer internals.
Examples
Shows <html lang="en">, a French passage marked lang="fr", and a three-language navigation selector.
What it assumes
Assumes basic HTML element familiarity while explaining why screen readers need explicit language information.
What you can do after
Operate/configure it by setting each page’s main language and marking passages that switch languages.
How it connects
Connects semantic HTML and multilingual sites with screen readers, braille translation, and language selectors.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Architecting Accessibility. The section links point to the parts of the book it draws on.