Course contentsShow
← Web Development
Lesson 286 of 2,9825. FlexboxFree lesson

order: Changing Visual Sequence

Reorder flex items visually without changing the HTML source order.

order: Changing Visual Sequence

You'll learn how to rearrange flex items on screen without touching your HTML source order.

What Is the order Property?

In Flexbox, the order property lets you control the visual sequence of flex items independently of how they appear in your HTML. By default, all flex items have order: 0, and they display in the same sequence as your source code. By changing an item's order value, you can move it earlier or later in the visual flow.

Think of it like dealing cards: the order you pick them up (HTML source) doesn't have to match the order you lay them on the table (visual display).

How It Works

The order property accepts integer values (negative, zero, or positive). Items are arranged from lowest to highest order value:

.item-1 { order: 2; }   /* appears third */
.item-2 { order: 1; }   /* appears second */
.item-3 { order: 0; }   /* appears first (default) */
.item-4 { order: -1; }  /* appears before all others */

Items with the same order value maintain their HTML source order relative to each other.

Why Use It?

This is powerful for responsive design. You might want a sidebar to appear first on mobile but last on desktop, without writing duplicate HTML. You can also highlight a featured item by moving it to the front visually.

Important: The order property only changes visual order. Screen readers and keyboard navigation still follow the HTML source order, so use it thoughtfully for accessibility.

Key Takeaway: The order property lets you rearrange flex items visually using integer values, without changing your HTML structure—but remember that source order still matters for accessibility.