Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Flexbox

The order property

Reference for the CSS order property: how it changes the visual order of flex and grid items, how ties are broken, and why it never changes keyboard order.

The order property changes the visual order of items inside a flex or grid container without touching the HTML. Items are sorted by their order value, lowest first. Items with the same value stay in their source order.

Every item starts with order: 0. To move one item to the end, give it a positive number; to move it to the front, give it a negative number.

CSS
.last { order: 1; }
.first { order: -1; }

Try it

Reordering with order
Reordering a grid on small screens

Syntax

CSS
order: <integer>;

order: 0;
order: -1;
order: 5;
  • Initial value: 0
  • Applies to: flex items and grid items (including absolutely positioned children of a flex container)
  • Inherited: no
  • Animatable: yes, as an integer
  • Computed value: as specified

Values

Value Description
<integer> Any integer, positive or negative. Items are laid out in ascending order of this value. Ties keep their order in the HTML.

Usage notes

  • Only the picture changes. Keyboard focus, screen readers and text selection still follow the HTML order. Reordering can therefore make Tab jump around the page in a confusing way, and it can break the reading order for assistive technology. Use it for cosmetic changes, and put content in the right order in the HTML.
  • Source order stays the default. Because ties keep the HTML order, you only need to give a number to the items that must move.
  • Leave gaps. Using steps such as 10, 20, 30 leaves room to insert items later, although for few items -1, 0 and 1 are enough.
  • Works with flex-direction. Ordering happens first; then row-reverse or column-reverse flips the whole sequence.
  • In Grid. Automatically placed grid items are sorted by order before they are placed. Items you place explicitly with grid-row and grid-column keep the cells you gave them.
  • Not a stacking tool. To control which element is painted on top, use z-index.
  • Don't use it for sorting data. If a list is sorted by name or date, sort it in the HTML (or on the server).

Browser support

Supported in every browser for flex and grid items.