CSS flex-direction
- type
- property (on the flex container)
- applies to
- a flex container
- inherits
- no
- common values
- row (default), column, row-reverse, column-reverse
Where it goes
On the flex parent, next to display: flex. The classic use is a row on desktop that becomes a column inside a @media query on phones.
Example
.stack {
display: flex;
flex-direction: column;
gap: 12px;
}
@media (max-width: 600px) {
.row {
flex-direction: column;
}
}Common mistakes
- Switching to column and then wondering why justify-content: center no longer centers left to right. In a column, justify-content is the vertical axis. Use align-items: center.
- Using flex-direction: column on a tag whose children should just stack. Blocks already stack. Flex column is for when you also need gap, alignment or stretching.
- Using row-reverse or column-reverse to change the visual order. Keyboard and a screen reader (software that reads the page aloud) order still follow the HTML, so visitors tab through it backwards. Reorder the HTML instead.