A webpage can appear to follow a clear sequence while its underlying document follows a different one. CSS makes this possible by moving content into columns, reversing flex items, positioning grid elements, or changing a layout at different screen sizes.

A difference between document order and visual order is not automatically a problem. It becomes important when the difference changes meaning, separates related information, or causes reading and keyboard navigation to follow an unexpected path.

Source order, document order, and visual order

Visual order is the arrangement a person sees on the rendered page. It is shaped by HTML, CSS, viewport size, writing direction, fonts, and other presentation conditions.

Document order is the sequence of elements in the page’s current Document Object Model, or DOM. Browsers initially build the DOM from the delivered HTML, but scripts can add, remove, or rearrange elements after the page loads.

The phrase source order is often used informally to describe this underlying sequence. Strictly speaking, however, the original HTML source and the live DOM are not always identical. When evaluating a working page, the live DOM is generally the more useful reference because it represents the document after the browser and page scripts have processed it.

CSS can change where an element appears without moving that element within the DOM. Common examples include:

  • the Flexbox order property;
  • reversed flex directions such as row-reverse and column-reverse;
  • explicit placement within a CSS Grid layout;
  • absolute positioning and transforms;
  • multi-column layouts; and
  • responsive styles that rearrange regions at different viewport widths.

This separation is part of the web’s broader distinction between structure and presentation. For more background, see Separation of Content and Presentation on the Web and Understanding the Document Object Model.

A simple sequence example

Consider a form divided into three visible steps:

  1. Choose a service.
  2. Select a date.
  3. Review the request.

Suppose the HTML places the review section before the date section:

<section class="steps">
  <div class="step service">
    <h2>1. Choose a service</h2>
    ...
  </div>

  <div class="step review">
    <h2>3. Review the request</h2>
    ...
  </div>

  <div class="step date">
    <h2>2. Select a date</h2>
    ...
  </div>
</section>

CSS Grid could display these sections visually as service, date, and review. A visual inspection might therefore suggest that the sequence is correct.

The underlying document still follows service, review, and date. If the sections contain links, form fields, or buttons, keyboard focus may also move from controls in the service section to controls in the review section before reaching the date section. If the CSS layout stops applying at a narrow viewport, the content may appear in its original document order and expose the mismatch.

A stronger foundation is to place the steps in a meaningful sequence in the document:

<section class="steps">
  <div class="step service">
    <h2>1. Choose a service</h2>
    ...
  </div>

  <div class="step date">
    <h2>2. Select a date</h2>
    ...
  </div>

  <div class="step review">
    <h2>3. Review the request</h2>
    ...
  </div>
</section>

CSS can then arrange that sequence into one column, several columns, or another suitable presentation without creating a conflicting path through the task.

Why order can affect usability

Visual order, reading order, and keyboard focus order are related, but they are not interchangeable.

Reading order

When sequence affects meaning, the document should expose a sequence that remains understandable without relying on visual positioning alone. Examples include:

  • numbered instructions;
  • a question followed by its answer;
  • a warning placed before the action it concerns;
  • an explanation associated with a form field;
  • chronological events; and
  • steps in a transaction or interactive task.

Screen readers commonly derive reading and navigation information from the browser’s accessibility representation of the page. That representation is influenced by the DOM, semantics, styles, and browser behavior. It should not be described as a simple copy of either the visual layout or the HTML source.

Assistive technologies also provide different reading and navigation modes, so there is no single behavior that describes every user or tool. A coherent document structure nevertheless provides the foundation those systems need. The Accessibility Tree Explained offers a closer look at how browsers expose page information to assistive technologies.

Keyboard focus order

Keyboard focus order concerns elements that can receive focus, such as links, buttons, form fields, and certain scripted controls. Ordinary paragraphs and headings do not usually become stops in the sequential keyboard focus order, although screen reader users may navigate them through other commands.

In typical documents, sequential keyboard navigation follows the DOM order of focusable elements. CSS that visually rearranges those elements usually does not make an equivalent change to the focus sequence.

This can produce an interface where focus appears to jump around the screen. For example, a person may tab from a button in the left column to a control in the far-right column and then return to the middle. The controls may all remain reachable, but the path can still make the interface harder to understand and operate.

WCAG 2.2 Success Criterion 2.4.3, Focus Order, requires focusable components to receive focus in an order that preserves meaning and operability when the sequence affects either one. This does not require every layout to follow one universal visual pattern. It requires the resulting interaction sequence to remain coherent.

For a broader review of focus behavior, see Keyboard Navigation Best Practices.

Meaningful sequence

WCAG 2.2 Success Criterion 1.3.2, Meaningful Sequence, applies when the sequence in which content is presented affects its meaning. In that situation, a correct reading sequence must be programmatically determinable.

The criterion allows for the possibility that more than one sequence may be meaningful. It does not say that every visual arrangement must exactly reproduce document order. The practical question is whether the available sequence preserves the content’s relationships and meaning.

Source order in responsive layouts

Responsive design often reveals ordering decisions that are less noticeable on a wide screen.

A desktop page might contain a main article, a related-information panel, and a task form arranged across several columns. At a narrow viewport, those regions usually become a single vertical sequence. The document order then has a strong influence on what appears first, which explanations precede the form, and whether related information remains near the content it supports.

Before choosing a multi-column arrangement, it helps to imagine the same page without its columns:

  • Does the one-column version tell a coherent story?
  • Do instructions appear before the controls they explain?
  • Are headings followed by the content they introduce?
  • Do warnings appear before a person reaches the relevant action?
  • Does the keyboard path remain understandable at each layout size?

A meaningful linear sequence gives responsive CSS a dependable foundation. Presentation can then adapt without requiring the document’s meaning to be reconstructed at every breakpoint.

See Responsive Layout Principles for Usable, Flexible Websites for related guidance on layouts that adapt across devices and viewport sizes.

When different orders may remain understandable

Not every difference between document order and visual order creates confusion. Some content regions are relatively independent, and more than one arrangement may preserve their meaning.

Examples may include:

  • a group of independent article cards;
  • a set of statistics that do not form a sequence;
  • supplementary links presented beside an article;
  • decorative elements that do not carry information; and
  • dashboard panels that can be understood separately.

Even in these cases, the difference deserves review. A set of cards that initially appears independent may contain dates, rankings, progressive steps, or controls whose order carries more meaning than expected.

A useful evaluation asks:

  1. Does either order change the meaning?
  2. Does one region need to be encountered before another?
  3. Does the focus path appear to jump unpredictably?
  4. Does the arrangement remain understandable when reduced to one column?
  5. Would a person miss instructions or context by following the document sequence?

If both arrangements answer these questions well, the difference may be harmless. Exact visual and document alignment is not an end in itself; understandable structure and usable interaction are the goals.

How to plan a meaningful document sequence

The most durable approach is usually to choose a sensible document sequence before using CSS to create the visual layout.

Start with the content relationships

Identify which pieces of information introduce, explain, depend on, or complete other pieces. Structure those relationships in HTML rather than relying on visual proximity alone.

Read the page as a linear document

Before considering columns or grid areas, read the content from beginning to end. The sequence should remain understandable even without its final presentation.

Use semantic HTML where it expresses the relationship

Headings, paragraphs, lists, forms, fieldsets, navigation regions, and other native elements communicate more than visual containers alone. Appropriate elements can make the intended structure clearer to browsers, assistive technologies, editors, and future developers.

Semantic HTML: Foundations, Structure, and Meaning provides additional context for building structure around the content’s actual purpose.

Arrange the presentation around that foundation

Use Flexbox, Grid, and responsive styles to support the intended relationships. Visual rearrangement should be approached carefully when sequence matters, particularly around instructions, forms, navigation, and multi-step tasks.

Avoid repairing structure with positive tabindex values

Adding positive tabindex values such as tabindex="1" and tabindex="2" can impose a custom focus order, but it is rarely a durable repair for a conflicting document structure. Custom sequences become difficult to maintain as controls are added, removed, or moved.

In most cases, arranging focusable elements in a logical DOM order and allowing the browser’s normal sequential navigation to follow that order is more dependable. The tabindex attribute still has legitimate uses, especially in carefully designed widgets and programmatic focus management, but it should not be treated as a general substitute for meaningful structure.

A practical source-order and visual-order review

A short review can reveal many ordering problems without becoming a comprehensive accessibility audit.

  1. Inspect the live DOM.Use browser developer tools to examine the order of major regions, headings, instructions, and controls. Remember that “View Source” may not show changes introduced by JavaScript.
  2. Read the document in sequence.Temporarily disable layout styles if practical, or inspect the page as a linear outline. Determine whether the content remains understandable.
  3. Compare the visual arrangement.Look for CSS Grid placement, Flexbox ordering, absolute positioning, and other techniques that cause the visible sequence to differ from the DOM.
  4. Test narrow and wide layouts.Resize the viewport or use responsive development tools. Check whether regions change position and whether the resulting sequence remains coherent.
  5. Navigate interactive elements by keyboard.Use the Tab and Shift+Tab keys to follow the sequential focus path. Confirm that focus remains visible and moves in an understandable order.
  6. Investigate meaningful mismatches.Prioritize differences that alter instructions, task sequence, context, or operability. A harmless variation between independent regions does not require the same response as a form whose focus order contradicts its visible steps.

Automated tools may identify some focus and structure concerns, but this comparison still benefits from human review. Meaning and sequence depend on the actual content and task, not only on detectable code patterns.

Frequently asked questions

Do source order and visual order always need to match?

No. Different arrangements may remain understandable when the content regions are independent or more than one sequence preserves meaning. Closer alignment becomes especially important when order affects comprehension, navigation, or task completion.

Does CSS Grid change keyboard focus order?

Visual placement in CSS Grid generally does not change the DOM order used for ordinary sequential keyboard navigation. A grid can therefore display controls in one arrangement while keyboard focus follows another.

Is the HTML source always the same as the DOM?

No. The browser builds the DOM from the delivered HTML, and JavaScript may then modify it. For a page that changes after loading, developer tools showing the live DOM provide a more accurate view of the current document structure than the original source alone.

A coherent underlying sequence supports flexible presentation

Visual layout is one way a webpage communicates order, but it is not the only one. The document sequence also shapes reading, responsive behavior, and the path through interactive controls.

The goal is not to prohibit visual rearrangement or require every order to be identical. It is to preserve meaning and operability across the different ways a person may encounter the page.

When the document begins with a coherent sequence, CSS has more freedom to adapt the presentation without making the page’s underlying relationships harder to follow.