Magento 2 Accessibility Deep Dive: Correcting Layered Navigation DOM Order for WCAG Compliance
Addressing a Critical Accessibility Gap in Magento 2 Layered Navigation
At Shopping Mover, we constantly monitor the Magento ecosystem for insights that can help merchants and developers optimize their e-commerce platforms. A recent GitHub issue (Issue #40670) has brought to light a significant accessibility concern within Magento 2's core layered navigation functionality, particularly affecting users relying on screen readers. This issue highlights how crucial seemingly minor structural details are for creating an inclusive online shopping experience.
The Problem: Disconnected Reading Order for Screen Readers
The core of the problem lies in the Document Object Model (DOM) structure of Magento 2's category and search results pages, especially when layered navigation is enabled using the default Luma theme or any theme inheriting from it. On these pages, the sidebar filters (.sidebar-main) are placed *after* the main product list (.column.main) in the HTML source code. While CSS might visually position the filters above the product list on mobile viewports, the underlying DOM order remains unchanged.
This discrepancy creates a significant disconnect for users navigating the page with assistive technologies like NVDA, TalkBack, or VoiceOver. When a screen reader navigates sequentially through the page elements, it reads all products in the main content area before reaching the filters. This violates WCAG 2.1 Success Criterion 1.3.2 (Meaningful Sequence), which states: "If the sequence in which content is presented affects its meaning, a correct reading sequence can be programmatically determined." For an e-commerce site, the ability to filter products is often a primary interaction, and having filters announced out of logical sequence hinders usability for a significant user base.
The Historical Context and Modern Solution
The original rationale behind placing the main content first in the DOM was to prioritize it for SEO crawlers. However, this reasoning is largely outdated. Modern search engines are sophisticated enough to understand visual layouts and do not require main content to appear first in the DOM to rank it appropriately. This historical decision now directly conflicts with modern accessibility standards.
The proposed fix, outlined in the GitHub issue, is elegant and effective: reorder the DOM so that the .sidebar-main element precedes .column.main. Visual presentation can then be managed using CSS Flexbox's order property, preserving the current desktop and mobile layouts while ensuring a correct and meaningful reading sequence for screen readers.
Proposed DOM Structure and CSS Adjustment:
Start with the tools
Explore migration tools
See options, compare methods, and pick the path that fits your store.