Skip to content

FlexBox

A flex container is defined this way: it is block by default or inline depending on the value.
This creates a flex context for all direct children.


PropertyValueDescription
displayflexGenerates a block-level flex container inside the element.
inline-flexGenerates an inline-level flex container inside the element.

The flex-direction property establishes the main axis of the container.

ValueDescription
row(default) Left to right (or right to left if RTL language).
row-reverseReverses the direction of row.
columnTop to bottom.
column-reverseSame as column, but bottom to top.

Defines whether the container has a single line or multiple lines.

ValueDescription
nowrap(default) Single line, items may overflow the container.
wrapMulti-line, items automatically wrap to the next line.
wrap-reverseMulti-line in reverse order (bottom to top or right to left).

Shorthand combining flex-direction and flex-wrap.

Default: row nowrap.


Defines alignment along the main axis.

ValueDescription
flex-start(default) Items grouped at the start of the line.
flex-endItems grouped at the end of the line.
centerItems centered on the line.
space-betweenItems distributed across the line (first at start, last at end).
space-aroundEqual spacing around each item.

Aligns items along the cross axis.

ValueDescription
flex-startAligned at the start of the cross axis.
flex-endAligned at the end of the cross axis.
centerCentered on the cross axis.
baselineAligned along the text baseline.
stretch(default) Stretches items to fill the container.

Aligns the lines of a flex container when there are multiple lines.
⚠️ Has no effect if the container has only one line.


The gap property defines the spacing between items.


Controls the visual order of flex items independently of the DOM.


Defines an item’s ability to grow.


Defines an item’s ability to shrink.


Defines the initial size of an element before space distribution.


Allows an individual item to override the align-items value.


  • display: flex → creates a flex container.
  • flex-direction → main axis (row/column).
  • flex-wrap → line wrapping.
  • justify-content → aligns along the main axis.
  • align-items → aligns along the cross axis.
  • align-self → overrides alignment for a single item.
  • flex-grow, flex-shrink, flex-basis → control space distribution.
  • gap → preferable to margin for handling spacing.
  • order → changes visual order without modifying the DOM.