order
Specifies the visual display order of flex items. You can change the visual order without altering the DOM order.
Sample Code
/* Initial value (follows DOM order) */
.item { order: 0;}
/* Move to the front */
.item-first { order: -1;}
/* Move to the end */
.item-last { order: 1;}
/* Specify arbitrary order */
.item-a { order: 3;}
.item-b { order: 1;}
.item-c { order: 2;}
Available Values
| Value | Description |
|---|---|
| <integer> | An integer value. The initial value is '0'. Negative values are allowed. Items with smaller values are placed earlier. |
Specification
| Item | Details |
|---|---|
| Initial value | 0 |
| Applies to | Flex items |
| Inherited | No |
| Animation | Yes (interpolated as integer) |
Browser Compatibility
28 △
27 △
26 △
25 △
24 △
23 △
22 △
21 △
20 and earlier ×
19 and earlier ×
7 △
6 and earlier ×
8 ×
7 ×
6 ×
11 and earlier ×
7 △
6 and earlier ×
Android Browser
4.4+ ○
3 and earlier ×Details
'order' is a property applied to flex items that changes only the visual display order without altering the DOM order. All items have an initial value of '0'. Items with smaller values are placed earlier, and items with larger values are placed later. Items with the same value follow their DOM order.
Ordering Rules
Items are arranged from smallest to largest 'order' value. Items with the same value are arranged according to their DOM order.
/* DOM order: A → B → C → D */
.item-a { order: 2;} /* 3rd */
.item-b { order: -1;} /* 1st (smallest value) */
.item-c { order: 0;} /* 2nd */
.item-d { order: 2;} /* 4th (same value as A but comes after A in DOM) */
/* Display order: B → C → A → D */
Pattern 1: Reordering for Responsive Layouts
/* Normal order on PC, main content first on SP */
.sidebar { order: 0;}
.main-content { order: 0;}
@media (max-width: 768px) {
.main-content { order: -1;} /* Move main to the top */
}
Pattern 2: Moving a Specific Item to the End
/* Always place the "Load More" button at the end */
.card { order: 0;}
.more-button { order: 999;}
Accessibility Note
'order' only changes the visual display order via CSS — the HTML DOM order remains unchanged. Screen readers and keyboard Tab navigation follow the DOM order, so the visual order and the interaction order may differ.
For purely decorative reordering this is generally not a problem, but when reordering interactive elements such as navigation or forms, it is preferable to change the order in the HTML itself wherever possible.
Difference from 'flex-direction: reverse'
To reverse the entire order, use 'flex-direction: row-reverse' or 'column-reverse'. Use 'order' when you want to change the order of individual items independently.
Related Properties
| Property | Description |
|---|---|
| flex-direction | Specifies the direction items are placed. Use 'row-reverse' or 'column-reverse' to reverse the entire order. |
If you find any errors or copyright issues, please contact us.