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

flex-direction: Reverse Variants

Use row-reverse and column-reverse to flip the order of flex items along the main axis without changing HTML.

What You'll Learn

You'll learn how to use flex-direction: row-reverse and column-reverse to flip the visual order of flex items without touching your HTML.

Why Reverse the Order?

Sometimes you need items to display in the opposite order from how they appear in your HTML. Maybe you want navigation links to flow right-to-left, or a vertical list to stack from bottom-to-top. Instead of rewriting your markup, you can simply reverse the flex direction.

The Reverse Variants

When you set flex-direction on a flex container, you have four options. You've already learned row and column. Now meet their reverse cousins:

  • row-reverse: Items flow horizontally along the main axis, but start from the right and move left (opposite of row)
  • column-reverse: Items stack vertically along the main axis, but start from the bottom and move up (opposite of column)

Think of it like reversing the direction of a conveyor belt. The items themselves don't change, but they arrive from the opposite end.

How It Works

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

If your HTML has three items (A, B, C in that order), row-reverse displays them visually as C, B, A from left to right. The HTML order stays the same—only the visual presentation reverses.

Important Note About Accessibility

The HTML order still matters for screen readers and keyboard navigation. Reversing with CSS is purely visual. Users navigating by keyboard will still tab through items in the original HTML order, not the reversed visual order.

Key Takeaway: Use row-reverse or column-reverse to flip the visual display order of flex items along the main axis while keeping your HTML structure intact—perfect for layout adjustments without markup changes.