CSS order Property

The CSS order property controls the visual order in which flex and grid items are arranged within their containers.

Items with lower order values appear before items with higher values. By default, every item has an order value of 0. The property changes visual placement without changing the order of elements in the HTML document.

order Syntax

The order property accepts an integer. Negative numbers, zero, and positive numbers are valid.

Basic Syntax

selector {
  order: 1;
}

Default Order

.item {
  order: 0;
}

Positive Order

.item {
  order: 2;
}

Negative Order

.item {
  order: -1;
}

Multiple Order Values

.item-one {
  order: 3;
}
.item-two {
  order: 1;
}
.item-three {
  order: 2;
}

CSS-Wide Keywords

.item {
  order: initial;
}
.item {
  order: inherit;
}
.item {
  order: unset;
}
.item {
  order: revert;
}
.item {
  order: revert-layer;
}

The initial value is 0. All items with the same order value retain their relative document order within that group.

Property Values

Value Description
<integer> Sets the item's order group using a whole number, including negative values and zero.
initial Resets the property to 0.
inherit Uses the computed order value of the parent element.
unset Resets the property to 0 because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value 0
Inherited No
Applies to Flex items, grid items, and absolutely positioned children of flex or grid containers
Computed value Specified integer
Animation type Integer
Default value 0

Valid and Invalid Values

.item {
  order: -3;
}
.item {
  order: 0;
}
.item {
  order: 5;
}

All three declarations contain valid integer values.

.item {
  order: 1.5;
}
.item {
  order: 20px;
}
.item {
  order: 50%;
}

These declarations are invalid because order requires an integer rather than a decimal, length, or percentage.

How It Works

The browser sorts flex and grid items into order groups based on their computed order values. Lower values are placed before higher values in the order-modified document order.

Items with equal values retain their relative source order. The layout algorithm then uses that ordering to arrange the items.

HTML Source Order

<div class="container">
  <div class="item-one">One</div>
  <div class="item-two">Two</div>
  <div class="item-three">Three</div>
</div>

CSS Order Values

.container {
  display: flex;
}
.item-one {
  order: 3;
}
.item-two {
  order: 1;
}
.item-three {
  order: 2;
}

Visual Result

The items appear in this order:

Two - Three - One

The HTML source remains One, Two, Three. Only the visual arrangement changes.

Important Consideration

The order property does not modify the DOM, keyboard navigation order, or the logical reading sequence used by assistive technologies.

Default Order

Every flex and grid item has an initial order value of 0.

Default Flex Items

.container {
  display: flex;
}
.item {
  order: 0;
}

All items remain in their original relative order.

Default Grid Items

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.item {
  order: 0;
}

Items participate in grid placement using their normal source order, unless explicit placement or other layout rules change their positions.

Resetting an Order Value

.item {
  order: 0;
}

Setting an item back to 0 returns it to the default order group.

Important Consideration

An item with order: 0 does not necessarily appear first. Items with negative order values are placed before the zero group.

Positive Order Values

Positive order values place items after those with smaller values.

Moving an Item Later

.container {
  display: flex;
}
.item-one {
  order: 2;
}
.item-two,
.item-three {
  order: 0;
}

The visual order becomes Two, Three, One.

Assigning Each Item a Value

.item-one {
  order: 10;
}
.item-two {
  order: 20;
}
.item-three {
  order: 30;
}

The items appear in their original order because their values increase in the same sequence.

Changing the Sequence

.item-one {
  order: 30;
}
.item-two {
  order: 10;
}
.item-three {
  order: 20;
}

The visual order becomes Two, Three, One.

Important Consideration

Order values do not need to be consecutive. The browser compares their relative values rather than requiring a sequence such as 1, 2, and 3.

Negative Order Values

Negative values place items before those with an order value of 0 or greater.

Moving an Item First

.container {
  display: flex;
}
.item-three {
  order: -1;
}

If the source order is One, Two, Three, the visual order becomes Three, One, Two.

Multiple Negative Values

.item-one {
  order: -1;
}
.item-two {
  order: -3;
}
.item-three {
  order: -2;
}

The visual order becomes Two, Three, One.

Mixing Negative and Positive Values

.item-one {
  order: 2;
}
.item-two {
  order: -1;
}
.item-three {
  order: 0;
}

The visual order becomes Two, Three, One.

Important Consideration

Negative values are useful when an item needs to appear before the default group without assigning a positive value to every other item.

Equal Order Values

Items with identical order values retain their relative source order.

All Items Equal

.item-one,
.item-two,
.item-three {
  order: 1;
}

The items appear as One, Two, Three.

Two Items Share a Value

.item-one {
  order: 2;
}
.item-two {
  order: 1;
}
.item-three {
  order: 1;
}

The visual order becomes Two, Three, One. Items Two and Three retain their relative HTML order.

Using Order Groups

.featured {
  order: -1;
}
.standard {
  order: 0;
}
.secondary {
  order: 1;
}

Items are grouped into featured, standard, and secondary positions. Within each group, source order is preserved.

Important Consideration

You do not need to assign a unique order value to every item. Shared values are often easier to maintain.

Using order with Flexbox

The order property is commonly used with Flexbox to change the visual sequence of flex items.

Basic Flexbox Ordering

<div class="flex-container">
  <div class="flex-item first">One</div>
  <div class="flex-item second">Two</div>
  <div class="flex-item third">Three</div>
</div>
.flex-container {
  display: flex;
  gap: 10px;
}
.first {
  order: 3;
}
.second {
  order: 1;
}
.third {
  order: 2;
}

The flex items appear as Two, Three, One.

Ordering Wrapped Flex Items

.flex-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.featured-item {
  order: -1;
}

The featured item is considered before items with higher order values when the browser distributes flex items across lines.

Column Layout

.flex-container {
  display: flex;
  flex-direction: column;
}
.last-item {
  order: -1;
}

The last item in the HTML can appear at the top of the flex column.

Important Consideration

Flexbox uses order-modified document order for layout. However, the direction of the flex container also affects where the first item is visually placed.

Using order with CSS Grid

The order property also works with grid items. It influences the order in which items are considered during grid auto-placement.

Basic Grid Ordering

<div class="grid-container">
  <div class="grid-item first">One</div>
  <div class="grid-item second">Two</div>
  <div class="grid-item third">Three</div>
</div>
.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.first {
  order: 3;
}
.second {
  order: 1;
}
.third {
  order: 2;
}

With automatic grid placement, the items appear as Two, Three, One.

Featured Grid Item

.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.featured-item {
  order: -1;
}

The featured item is considered before items in the default order group during auto-placement.

Explicit Grid Placement

.grid-item {
  order: -1;
  grid-column: 3;
  grid-row: 1;
}

Explicit grid placement determines the item's assigned grid position. The order property does not override those coordinates.

Important Consideration

For precise grid placement, use grid-column, grid-row, or named grid areas. Use order primarily when changing the sequence of automatically placed items.

order and flex-direction

The order property determines the order groups, while flex-direction determines the direction in which flex items are laid out.

Normal Row Direction

.container {
  display: flex;
  flex-direction: row;
}
.item-one {
  order: 1;
}
.item-two {
  order: 2;
}
.item-three {
  order: 3;
}

In a typical left-to-right layout, the items appear from left to right as One, Two, Three.

Reversed Row Direction

.container {
  display: flex;
  flex-direction: row-reverse;
}
.item-one {
  order: 1;
}
.item-two {
  order: 2;
}
.item-three {
  order: 3;
}

In a left-to-right writing mode, the items appear visually from left to right as Three, Two, One.

Reversed Column Direction

.container {
  display: flex;
  flex-direction: column-reverse;
}

The items are laid out along the column in the reverse direction.

Important Consideration

Order values are still sorted from lowest to highest. The flex direction determines the visual direction in which that sorted sequence is displayed.

Responsive Layouts

The order property can be changed inside media queries to adjust the visual arrangement of flex or grid items at different viewport sizes.

Responsive Flexbox Layout

.layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.main-content {
  order: 1;
}
.sidebar {
  order: 2;
}
@media (min-width: 768px) {
  .layout {
    flex-direction: row;
  }
  .sidebar {
    order: 0;
  }
  .main-content {
    order: 1;
  }
}

On smaller screens, the main content appears before the sidebar. On wider screens, the sidebar appears first.

Responsive Grid Ordering

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.featured-card {
  order: -1;
}
@media (min-width: 768px) {
  .card-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .featured-card {
    order: 0;
  }
}

The featured card is placed first on narrow screens, while wider layouts use the default order group.

Important Consideration

Responsive visual reordering can create accessibility problems if the visual sequence no longer matches the keyboard focus or reading order. Prefer keeping the HTML source in a logical sequence that works across screen sizes.

Accessibility and Document Order

The order property changes visual layout but does not change the underlying HTML source order.

Screen readers and keyboard navigation generally follow the document's logical order rather than the visual order created by CSS.

Visual and Keyboard Order Mismatch

<nav class="menu">
  <a href="#first" class="first">First</a>
  <a href="#second" class="second">Second</a>
  <a href="#third" class="third">Third</a>
</nav>
.menu {
  display: flex;
}
.first {
  order: 3;
}
.second {
  order: 1;
}
.third {
  order: 2;
}

The links appear visually as Second, Third, First, but keyboard navigation still follows First, Second, Third.

Recommended Approach

For navigation, forms, and other interactive content, arrange the HTML elements in the intended logical order whenever possible.

Appropriate Use of order

Visual reordering is most appropriate when the change is purely presentational and does not alter the meaning, reading sequence, or expected interaction order.

Important Consideration

Do not use order as a substitute for meaningful document structure. A logical source order benefits keyboard users, screen reader users, and layouts that do not apply the same CSS.

order Example

This example demonstrates how different order values change the visual arrangement of three flex items.

HTML Example

<div class="order-demo">
  <div class="order-item item-one">One</div>
  <div class="order-item item-two">Two</div>
  <div class="order-item item-three">Three</div>
</div>

CSS Example

.order-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px;
  background-color: #f1f5f9;
}
.order-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 90px;
  height: 70px;
  color: #fff;
  font-weight: 700;
}
.item-one {
  background-color: #2563eb;
  order: 3;
}
.item-two {
  background-color: #16a34a;
  order: 1;
}
.item-three {
  background-color: #c2410c;
  order: 2;
}
Browser Result
One
Two
Three

Although the HTML lists One, Two, Three, the browser displays Two, Three, One because their order values are 1, 2, and 3.

Negative Order Example

This second example moves the last item to the beginning using a negative value.

<div class="negative-order-demo">
  <div class="order-item">One</div>
  <div class="order-item">Two</div>
  <div class="order-item featured">Three</div>
</div>
.negative-order-demo {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px;
  background-color: #f1f5f9;
}
.negative-order-demo .order-item {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 90px;
  height: 70px;
  background-color: #2563eb;
  color: #fff;
  font-weight: 700;
}
.negative-order-demo .featured {
  background-color: #16a34a;
  order: -1;
}
Browser Result
One
Two

The green item appears first because its order value is -1, while the other items retain the default value of 0.

Common Mistakes

Using order on Regular Block Elements

.container {
  display: block;
}
.item {
  order: 1;
}

The order property does not reorder ordinary block elements in a block layout. Use an appropriate flex or grid container.

Using Decimal Values

.item {
  order: 1.5;
}

Order values must be integers.

Assuming Higher Values Appear First

Items with lower order values are considered before items with higher values.

Assuming order Changes HTML Source Order

The property changes visual arrangement, not the DOM sequence.

Ignoring Keyboard Navigation

Visually reordered interactive elements may still receive keyboard focus in their original HTML order.

Expecting Unique Values to Be Required

Multiple items can share an order value. They retain their relative source order within that group.

Confusing order with z-index

order affects item ordering in layout, while z-index controls stacking order in applicable stacking contexts.

Expecting order to Override Explicit Grid Placement

Grid items assigned to specific rows and columns remain in those locations regardless of their order values.

Overusing order for Page Structure

Complex reordering can make stylesheets difficult to maintain and create inconsistencies between visual and logical content order.

Important Considerations

Keep the following points in mind when using order:

  • The property controls the order-modified document order used by flex and grid layout.
  • Its initial value is 0.
  • The property is not inherited.
  • It accepts integer values, including negative numbers and zero.
  • Decimal, length, and percentage values are invalid.
  • Items with lower values are considered before items with higher values.
  • Items with equal values retain their relative source order.
  • Order values do not need to be consecutive or unique.
  • Negative values can move items before the default order group.
  • Positive values can move items after the default order group.
  • The property works with both Flexbox and CSS Grid.
  • In Flexbox, flex-direction also affects the visual direction of item placement.
  • In Grid, order influences automatic placement but does not override explicit grid coordinates.
  • Order values can be changed using media queries.
  • The property does not modify the HTML source order.
  • The property does not automatically change keyboard navigation order.
  • Screen reader reading order generally follows the logical document structure.
  • Use logical HTML ordering for interactive and meaningful content sequences.
  • Use grid-column and grid-row for precise grid placement.
  • Use z-index for applicable stacking control rather than visual layout ordering.
  • Prefer simple order groups over unnecessarily complex numbering schemes.

Browser Support

The CSS order property is Baseline - Widely available and has been supported in modern browsers for many years.

Current versions of Chrome, Edge, Firefox, Safari, and other major browsers support the property for flex and grid layouts.

For current compatibility information, visit Can I Use? and search for CSS order.

When working with older browsers, verify support for the layout mode being used, particularly Flexbox and CSS Grid.

Specifications

The order property is defined in CSS Display Module Level 3 and is used by the CSS Flexible Box Layout and CSS Grid Layout specifications.

CSS Display Module Level 3: The order Property

For details about flex item ordering, see the CSS Flexible Box Layout specification.

CSS Flexible Box Layout Module Level 1: Reordering and Accessibility

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: order