Menu
Box Model & Layout

CSS Flexbox

One-dimensional layouts: align, distribute, and order items easily.

1The Flex Container

Set display: flex on a parent to make all direct children flex items.

Example Code
.container {
  display: flex;
  gap: 12px;
}

2Main Axis & Cross Axis

justify-content aligns along the main axis. align-items aligns on the cross axis.

Example Code
.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

3Wrapping & Direction

flex-wrap controls overflow; flex-direction switches between row and column.

Example Code
.container {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
}

4Item Sizing

flex: 1 makes items grow to fill available space. flex-basis sets the starting size.

Example Code
.item { flex: 1; }
.featured { flex: 2; }

Finished reading?

Mark this topic as complete to track progress.