DOM Order
DOM order refers to the sequence in which HTML elements appear in the Document Object Model, which directly affects how assistive technologies read and navigate content.
In simple terms: DOM order is like the order of pages in a book. Even if you rearrange pictures on a table, the page numbers stay the same. Screen readers read in page-number order, so that order needs to make sense.
What Is DOM Order?
DOM order is the sequence in which HTML elements appear in the Document Object Model, the tree-like structure that browsers construct from your HTML code. When a browser parses an HTML document, it creates a DOM tree where each element occupies a specific position relative to other elements. This position determines the default reading order for assistive technologies and the tab order for keyboard navigation. The DOM is the browser's internal representation of your page. Every element you write in HTML, from headings and paragraphs to buttons and links, gets placed into this tree in the exact order it appears in the source code. This sequential arrangement is foundational to how screen readers announce content and how keyboard users move through interactive elements. While CSS allows developers to visually reposition elements anywhere on the screen, the underlying DOM order remains unchanged. Properties like `flexbox order`, `grid-area`, `float`, and `position: absolute` affect only the visual presentation. Assistive technologies ignore these visual changes and follow the DOM tree instead.
Why It Matters
For sighted users, layout and design guide the eye through a page. But for screen reader users and keyboard-only users, the DOM order is the primary navigation path. When the DOM order diverges from the visual order, it creates a disorienting experience where content appears to jump around unpredictably. WCAG Success Criterion 1.3.2 (Meaningful Sequence) requires that when the order of content affects its meaning, a correct reading sequence can be programmatically determined. Success Criterion 2.4.3 (Focus Order) further requires that focusable components receive focus in an order that preserves meaning and operability. A mismatched DOM order can cause real problems. A user tabbing through a form might jump from the first field to the submit button, skipping fields in between. A screen reader might announce a modal's close button before its content. These experiences frustrate users and can make websites effectively unusable for people who rely on assistive technologies.
How It Works
When you write HTML, elements are placed into the DOM in source order. Consider this simplified example: ```html <header>Site Title</header> <nav>Navigation Links</nav> <main>Main Content</main> <aside>Sidebar</aside> <footer>Footer</footer> ``` A screen reader will announce these elements in exactly this order: header, nav, main, aside, footer. A keyboard user pressing Tab will move through focusable elements within these sections in the same sequence. Problems arise when developers use CSS to reorder visual presentation. For instance, using `flexbox order` to move the sidebar before the main content visually will not change the DOM order. Screen reader users will still encounter main content first, while sighted users see the sidebar first. Best practices for maintaining proper DOM order include: - **Write HTML in a logical reading order.** Structure your source code so it makes sense when read top to bottom, left to right. - **Avoid CSS reordering for meaningful content.** Use CSS `order`, `grid` placement, or absolute positioning sparingly, and only when the visual reorder doesn't affect comprehension. - **Use `tabindex` carefully.** Setting `tabindex` values greater than 0 creates a custom tab order that can conflict with DOM order. Stick to `tabindex="0"` or `tabindex="-1"` in most cases. - **Test without CSS.** Disable stylesheets and verify the content still reads in a meaningful sequence. - **Use browser developer tools.** The accessibility tree in Chrome DevTools or Firefox's Accessibility Inspector shows how assistive technologies interpret your DOM. Modern CSS layout methods like Flexbox and Grid are powerful, but they require developers to be mindful of the gap they can create between visual and DOM order. The CSS Working Group has acknowledged this issue, and newer specifications increasingly address source-order concerns.
Frequently Asked Questions
- Why does DOM order matter for accessibility?
- Screen readers and keyboard navigation follow the DOM order, not the visual layout. If the DOM order doesn't match the visual order, users who rely on assistive technologies may experience confusing or illogical navigation sequences.
- Can CSS change the DOM order?
- CSS properties like flexbox order, grid placement, and absolute positioning can visually rearrange elements without changing the underlying DOM order. This creates a disconnect between what sighted users see and what assistive technology users experience.
- How do I test DOM order on my website?
- Disable CSS in your browser and see if the content still makes logical sense. You can also tab through the page with your keyboard to check that the focus sequence is logical and predictable.
Need help making your website ADA compliant?
Our team specializes in ADA-compliant web design and remediation. Get a free accessibility audit today.
Last updated: 2026-03-15