What the issue is
Web pages that dynamically update content without refreshing the entire page may fail to adjust the
lang attribute to match the new content's language. This scenario can occur in single-page applications, AJAX content updates, or any dynamic content change that involves a language switch not reflected in the document's language settings.
This is one of two takes on lang attributes with AJAX. One has to consider both the impact on the page of the new content, and the foreign words on the page added by AJAX. This issue related to the former take.
Why this is important
Properly setting the
lang attribute for dynamically changing content is crucial for accessibility. When the language of content changes without updating this attribute, it can lead to incorrect pronunciation by screen readers, potentially confusing users or obscuring the content's meaning. Correctly signaling language changes ensures that assistive technologies can provide a coherent and understandable experience.
Who it affects
This issue primarily affects:
- People relying on screen readers or other assistive technologies that interpret content based on the specified language.
- People with cognitive disabilities who may be confused by sudden changes in language without clear indication.
- Non-native speakers who might rely on the assistive technologies' language settings to understand content.
How to remediate the issue
- Implement a mechanism to update the
langattribute appropriately whenever content is dynamically changed to a different language.
- For content loaded via AJAX or through client-side scripting, ensure that the script updating the content also adjusts the
langattribute for the affected elements or their parent container.
- Test dynamic content updates with screen readers and other assistive technologies to verify that language changes are correctly announced and interpreted.