CSS order Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Flexbox & Grid

What You’ll Learn

The order property lets you change the visual order of flex items without rewriting your HTML. It is a handy tool for responsive layouts and quick rearrangements.

01

Flexbox Order

Rearrange flex items.

02

Integer Values

Positive, negative, zero.

03

Default 0

Source order by default.

04

Visual Only

HTML stays the same.

05

Responsive

Reorder on small screens.

06

Grid Too

Also works in CSS Grid.

Introduction

The order property in CSS is a part of the Flexible Box Layout Module, commonly known as Flexbox. It allows developers to control the order in which flex items appear within a flex container.

By default, flex items are displayed in the order they appear in the source code. However, the order property enables you to rearrange these items without altering the HTML structure, providing greater flexibility in layout design.

Definition and Usage

Apply order to a flex item (a direct child of a flex container). Lower values appear first; higher values appear later.

Use it for responsive design when you want a sidebar, image, or button to move visually on smaller screens while keeping a logical HTML structure for accessibility.

💡
Beginner Tip

Think of order as a sorting number. -1 moves an item to the front, 0 is default, and 2 pushes an item toward the back.

📝 Syntax

The syntax for the order property is simple. It accepts a single integer value, which determines the item’s position among its siblings within the flex container.

syntax.css
.item {
  order: <integer>;
}
  • <integer> — The value can be positive, negative, or zero. The default value is 0.

Basic Example

order.css
.container {
  display: flex;
}

.sidebar {
  order: -1;
}

Syntax Rules

  • The parent must be a flex container (display: flex or display: inline-flex).
  • Items are sorted by order value, then by source order for ties.
  • Negative values move items before those with order: 0.
  • order also works on grid items inside a grid container.

🎯 Default Value

The default value of the order property is 0. All items have the same order value by default, so they are displayed in the order they appear in the HTML source.

You only need to set order on items that should appear out of their normal source position.

⚡ Quick Reference

QuestionAnswer
Initial value0
Applies toFlex items and grid items
InheritedNo
AnimatableNo
Common useResponsive reordering in flex and grid layouts

💎 Property Values

ValueExampleDescription
Positive integerorder: 2;Items with higher positive values appear later in the order
Negative integerorder: -1;Items with negative values appear earlier in the order
Zeroorder: 0;Default value; item appears in its original source order relative to other zero values
-1 — move to front 0 — default 1 — move later 2+ — move toward back

👀 Live Preview

HTML order is Item 1, Item 2, Item 3 — but visual order is Item 2, Item 3, Item 1:

Item 1 (order: 2)
Item 2 (order: -1)
Item 3 (order: 0)

Examples Gallery

Reorder flex items with positive, negative, and zero values, then try responsive patterns.

📦 Basic Reordering

Rearrange three items using the reference example values.

Example 1 — Three Items Reordered

In this example, we rearrange the order of three items within a flex container using the order property.

flex-order.html
<style>
  .container { display: flex; }
  .item {
    padding: 10px;
    margin: 5px;
    background-color: #dbeafe;
    border: 1px solid #2563eb;
  }
  .item1 { order: 2; }
  .item2 { order: -1; }
  .item3 { order: 0; }
</style>

<div class="container">
  <div class="item item1">Item 1</div>
  <div class="item item2">Item 2</div>
  <div class="item item3">Item 3</div>
</div>
Result:
  • Item 1 has order: 2, so it appears last.
  • Item 2 has order: -1, so it appears first.
  • Item 3 has order: 0, so it appears in the middle.
Try It Yourself

How It Works

Flex items are sorted by their order number before they are laid out in the row or column.

Example 2 — Move a Call-to-Action to the Front

Use a negative order to pull one important button ahead of the others visually.

cta-order.css
.actions {
  display: flex;
  gap: 0.75rem;
}

.primary {
  order: -1;
}
Try It Yourself

How It Works

Even if the primary button comes second in HTML, order: -1 displays it first.

📱 Responsive & Grid

Change order at breakpoints or inside grid layouts.

Example 3 — Responsive Sidebar Reorder

Move the sidebar below the main content on small screens using a media query.

responsive-order.css
.layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar {
  order: 2;
}

.main {
  order: 1;
}

@media (min-width: 768px) {
  .layout { flex-direction: row; }
  .sidebar, .main { order: 0; }
}
Try It Yourself

How It Works

On mobile, main content appears first even if the sidebar comes first in HTML.

Example 4 — Order in CSS Grid

order also works on grid items to change their visual placement order.

grid-order.css
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.featured {
  order: -1;
}
Try It Yourself

How It Works

Grid auto-placement respects order when placing items without explicit grid positions.

Requires a flex or grid container

order only affects items inside a flex or grid container. The parent needs display: flex, display: inline-flex, or display: grid.

For larger layout changes, also learn flex-direction, flex-wrap, and justify-content alongside order.

flex-container.css
.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
}

♿ Accessibility

  • DOM order matters — Screen readers follow HTML source order, not visual order.
  • Keep focus logical — Tab order follows the DOM, which may not match what users see.
  • Do not hide important actions — Moving buttons visually can confuse keyboard users if focus jumps unexpectedly.
  • Prefer semantic HTML first — Reorder in HTML when possible; use order for responsive visual tweaks.

🧠 How order Works

1

Items live in a flex or grid container

The parent uses display: flex or display: grid.

Container
2

Each item gets an order number

Default is 0. Lower numbers appear earlier visually.

Integer
3

Browser sorts by order value

Tied values keep their original source order among each other.

Sort
=

Visual reorder without HTML changes

Layout adapts while the markup structure stays the same.

Browser Compatibility

The order property is widely supported in modern browsers, including the latest versions of Chrome, Firefox, Safari, Edge, and Opera. Test across browsers to ensure consistent behavior.

Baseline · Modern browsers

Strong support in current browsers

order works reliably with flexbox and grid in all up-to-date desktop and mobile browsers.

97% Modern browser support
Google Chrome 29+ · Desktop & Mobile
Full support
Mozilla Firefox 28+ · Desktop & Mobile
Full support
Apple Safari 9+ · macOS & iOS
Full support
Microsoft Edge 12+ · All versions
Full support
Opera 17+ · Modern versions
Full support
order property 97% supported

Bottom line: order is safe to use with flexbox and grid in modern projects.

Conclusion

The order property is a powerful feature of Flexbox, enabling developers to control the visual arrangement of elements without modifying the underlying HTML structure.

This property is particularly useful for responsive designs, where the layout needs to adapt to different screen sizes and orientations. By using the order property, you can create more flexible and dynamic layouts for your web projects.

💡 Best Practices

✅ Do

  • Use order for responsive visual rearrangements
  • Keep HTML in a logical reading order when possible
  • Use small integer values like -1, 0, and 1
  • Combine with media queries for mobile layouts
  • Test keyboard focus order after reordering visually

❌ Don’t

  • Assume order changes screen reader or tab order
  • Apply order without a flex or grid parent
  • Overuse large order numbers when simple values work
  • Hide critical content by pushing it far back visually
  • Rely on order when HTML reordering is clearer

Key Takeaways

Knowledge Unlocked

Five things to remember about order

Use these points when rearranging flex and grid layouts.

5
Core concepts
02

Default 0

Source order.

Default
📝 03

Integers

Negative to positive.

Values
📱 04

Responsive

Reorder on breakpoints.

Use case
05

Accessibility

DOM order stays.

A11y

❓ Frequently Asked Questions

order controls the visual order of flex items (and grid items) inside their container without changing the HTML source order.
The default value is 0. Items with the same order value appear in source order.
order is most commonly used with display: flex, but it also works with CSS Grid layouts.
Yes. Negative values move items earlier, while higher positive values move items later.
No. order changes visual layout only. The accessibility tree still follows the HTML source order.

Practice in the Live Editor

Open the HTML editor, build a flex container, and experiment with different order values.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful