🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

Order

AI & DATA SCIENCE // order

The order property changes the visual order in which a flex (or grid) item is displayed relative to its siblings, without altering its actual position in the underlying HTML source.

Syntax

order: integer;

Deep Dive Course

Every flex item has a default order value of 0, and items are displayed in ascending order of their order value, lowest first, with items sharing the same value falling back to their original source order relative to each other. This makes it possible to visually reorder items, like moving a specific item to the front or back of a row, purely through CSS, without touching the actual HTML markup — but critically, this reordering is purely visual, meaning it doesn't affect the DOM's actual source order at all, which can create a meaningful mismatch for keyboard navigation, tab order, and screen readers, both of which typically still follow the original, un-reordered source order.

1Understanding Order

Every flex item has a default order value of 0, and items are displayed in ascending order of their order value, lowest first, with items sharing the same value falling back to their original source order relative to each other. This makes it possible to visually reorder items, like moving a specific item to the front or back of a row, purely through CSS, without touching the actual HTML markup — but critically, this reordering is purely visual, meaning it doesn't affect the DOM's actual source order at all, which can create a meaningful mismatch for keyboard navigation, tab order, and screen readers, both of which typically still follow the original, un-reordered source order.

💡

Use order sparingly and thoughtfully — since it only changes visual order, not the underlying DOM order, overusing it can create a confusing mismatch where a page's visual left-to-right or top-to-bottom order no longer matches its keyboard tab order or the order a screen reader announces content in.

editor.html
.item-a { order: 2; }
.item-b { order: 1; }
.item-c { order: 3; }
localhost:3000

2Practical Example

Here is a real-world application of Order showing how it is used in production CSS code.

First in HTML
Second in HTML
localhost:3000
'Second in HTML' visually appears before 'First in HTML', since its order value (-1) is lower, but it still comes after it in the actual DOM and for keyboard tab order

3Best Practices

Follow these guidelines when working with Order:

1. Use order for small, deliberate visual reordering needs, like moving a specific call-to-action button, rather than as a substitute for writing HTML in a sensible source order to begin with

2. Test keyboard tab order and screen reader behavior on any layout using order, since visual order and DOM/interaction order can diverge and create a confusing mismatch

3. Prefer writing HTML in its intended logical, accessible source order first, using order only for specific, limited visual exceptions rather than as a primary layout tool

⚠️

Tip: Use order sparingly and thoughtfully — since it only changes visual order, not the underlying DOM order, overusing it can create a confusing mismatch where a page's visual left-to-right or top-to-bottom order no longer matches its keyboard tab order or the order a screen reader announces content in.

editor.html
.item-a { order: 2; }
.item-b { order: 1; }
.item-c { order: 3; }
localhost:3000

Examples

Example 01Basic Usage
.item-a { order: 2; }
.item-b { order: 1; }
.item-c { order: 3; }
Example 02Advanced Example
<div class="row">
  <div>First in HTML</div>
  <div style="order: -1;">Second in HTML</div>
</div>

Best Practices

  • Use order for small, deliberate visual reordering needs, like moving a specific call-to-action button, rather than as a substitute for writing HTML in a sensible source order to begin with
  • Test keyboard tab order and screen reader behavior on any layout using order, since visual order and DOM/interaction order can diverge and create a confusing mismatch
  • Prefer writing HTML in its intended logical, accessible source order first, using order only for specific, limited visual exceptions rather than as a primary layout tool

Interview Question

Why can using the order property to visually reorder items create an accessibility problem, even though the page might look perfectly correct visually?

Hint: Think about what keyboard tab order and screen readers actually follow — the CSS-determined visual order, or the underlying HTML source order.

Keyboard tab order, determined by pressing Tab to move focus between interactive elements, and the order in which a screen reader announces content, both fundamentally follow the actual underlying HTML source order in the DOM, not whatever visual order CSS's order property happens to display things in — order is purely a visual, presentational reordering that has no effect at all on this underlying structural order. This means a page can look completely correct and logically ordered visually, thanks to order rearranging things exactly as intended, while a keyboard user tabbing through the page, or a screen reader user listening to it, experiences an entirely different, source-order-based sequence that might jump around confusingly or present information in an order that doesn't match what's visually shown, actively working against, rather than complementing, what a sighted mouse user sees. This exact mismatch is precisely why heavy reliance on order for significant layout reordering is generally discouraged in favor of writing HTML in a sensible, already-correct source order from the start, reserving order for only small, carefully-considered visual exceptions.

Exercises

MediumPractice using Order in a real scenario.
View Solution
.item-a { order: 2; }
.item-b { order: 1; }
.item-c { order: 3; }

Frequently Asked Questions

Why can using the order property to visually reorder items create an accessibility problem, even though the page might look perfectly correct visually?

Keyboard tab order, determined by pressing Tab to move focus between interactive elements, and the order in which a screen reader announces content, both fundamentally follow the actual underlying HTML source order in the DOM, not whatever visual order CSS's order property happens to display things in — order is purely a visual, presentational reordering that has no effect at all on this underlying structural order. This means a page can look completely correct and logically ordered visually, thanks to order rearranging things exactly as intended, while a keyboard user tabbing through the page, or a screen reader user listening to it, experiences an entirely different, source-order-based sequence that might jump around confusingly or present information in an order that doesn't match what's visually shown, actively working against, rather than complementing, what a sighted mouse user sees. This exact mismatch is precisely why heavy reliance on order for significant layout reordering is generally discouraged in favor of writing HTML in a sensible, already-correct source order from the start, reserving order for only small, carefully-considered visual exceptions.

Related Functions

Display-flexFlex-directionGrid-column