LAY-002 Keep the order in the code telling the same story as the order on screen
- Level
- Rule
- Verdict
- Requirement
- Area
- Layout
- Status
- decided, version 1.0.2
Rule
Where the order of content carries meaning or affects how it is used, the order in the code, which screen readers read and the keyboard follows, tells the same story as the order on screen, and layout tools such as grid placement or the order property never rearrange that content so the two disagree.
Examples
Live examples built with Justified's components. Try them with the mouse, the keyboard or a screen reader.
Do: Steps in the same order in code and on screen
Don't: CSS order rearranges the steps
order moves it back down. Click in Full name and press Tab: focus jumps to Card number, then back up to Postcode. A screen reader reads Payment before Delivery.Why
A sighted person reads the page in the order it is drawn. A screen reader user hears it, and a keyboard user moves through it, in the order it is written in the code. When a layout tool moves things on screen but leaves the code as it was, these people get a different page: step 3 before step 2, a price before the product it belongs to, a button before the text that explains it. The meaning breaks, or the page becomes hard to use. WCAG 2.2, 1.3.2 Meaningful Sequence and 2.4.3 Focus Order require an order that keeps meaning and use intact wherever order matters. They do not ask that the two orders be identical, and neither does this rule.
Do
- Write the code in the order people should meet the content, and let the layout follow it. This is the simplest way to meet the rule.
- On a product page, keep Wool cardigan, the price "$89", the size picker and Add to bag in that order in the code as well as on screen.
- In a form with numbered steps, such as "1. Your details", "2. Delivery" and "3. Payment", keep the steps and the fields inside each step in the same order in the code as on screen.
- When a layout changes at a breakpoint, let content move and change size, but keep the sequence of anything whose order matters. A row with Cancel and Save that stacks on a small screen keeps the two buttons in the same order.
- Keep a label, an instruction or a heading in the same position relative to its field, control or section in the code as on screen. If the label of a checkbox is shown after the box, it comes after the box in the code too.
- When a menu, popover or panel opens from a button, let the keyboard reach its content next. Either place it right after the button in the code, or move focus into it when it opens and back to the button when it closes. A modal dialog always takes the second way, as DLG-006 says.
- Treat order between independent regions as free. A news article and a box with today's weather shown beside it may come in either order in the code. Inside each region, the order still follows this rule.
Don't
- Use
orderor grid placement to show the steps "1. Your details", "2. Delivery" and "3. Payment" in the right order on screen while the code has them as 1, 3, 2, so a screen reader reads Payment before Delivery and Tab goes there first. - Reverse a flex row so Add to bag appears after the price on screen but comes before the product name in the code.
- Use absolute positioning to lift a warning such as "Just 2 left" to the top of a card while it is read last.
- Add a positive
tabindexto patch an order that the layout broke. Fix the order in the code instead. - Put the panel that opens from Filters at the end of the page in the code and leave focus on the button, so a keyboard user must pass the rest of the page to reach the filters.
Exceptions
- Order without meaning. Content whose order carries no meaning, such as a gallery of photos without ranking, is outside the rule. A ranking, a date order or a chosen sort makes the order meaningful again.
- Decorative moves. Showing an image above a heading that comes before it in the code is fine when it does not change what the content means. Use judgement, and when in doubt, show the content in the same order as it has in the code.
- Right-to-left languages. Mirroring a layout for Arabic or Hebrew keeps the logical order the same. It is not a rearrangement.
Verdict
Requirement. Only the judges decide; the expert witnesses are shown but do not vote. How verdicts work
| Source | Role | Stance | Page |
|---|---|---|---|
| WCAG 2.2 | Law | Requires | 1.3.2 Meaningful Sequence |
| WCAG 2.2 | Law | Requires | 2.4.3 Focus Order |
| Material Design | Judge | Supports | Buttons: guidelines |
| Apple Human Interface Guidelines | Judge | No position | |
| Carbon Design System | Judge | No position | |
| GOV.UK Design System | Expert witness | No position | |
| Nielsen Norman Group | Expert witness | No position |
Each stance links to the page it rests on, read on the date in the source register. This page never repeats what a source says; read the source itself.
History
- Version 1.0.2, : Refers to DLG-006 for modal dialogs.
- Version 1.0.1, : Examples in English.
- Version 1.0.0, : First version.
Last checked against the other rules for conflicts on .
More in Layout: 4 rules and 0 guidelines · All rules
Justified is an independent project. It is not affiliated with, sponsored or endorsed by the organisations whose guidance it cites. Read the full statement.
Apple is a trademark of Apple Inc., registered in the U.S. and other countries and regions.