CSS Flexbox Tutorial

Flex Property Values Description Example Usage
display: flex; flex Sets the element as a flex container, enabling flex properties on its child elements.
...
justify-content flex-start, flex-end, center, space-between, space-around Specifies how flex items are distributed along the main axis of the flex container.

  • flex-start: Items are aligned at the start of the container.
  • flex-end: Items are aligned at the end of the container.
  • center: Items are centered within the container.
  • space-between: Items are evenly distributed with space between them.
  • space-around: Items are evenly distributed with space around them.
...
align-items flex-start, flex-end, center, baseline, stretch Specifies how flex items are aligned along the cross axis of the flex container.

  • flex-start: Items are aligned at the start of the cross axis.
  • flex-end: Items are aligned at the end of the cross axis.
  • center: Items are centered along the cross axis.
  • baseline: Items are aligned based on their text baseline.
  • stretch: Items are stretched to fill the container along the cross axis.
...
flex-direction row, row-reverse, column, column-reverse Specifies the direction of the main axis and cross axis within the flex container.

  • row: Items are laid out horizontally in the order they appear.
  • row-reverse: Items are laid out horizontally in reverse order.
  • column: Items are laid out vertically in the order they appear.
  • column-reverse: Items are laid out vertically in reverse order.
...
flex-wrap nowrap, wrap, wrap-reverse Specifies whether flex items should wrap or stay on a single line.

  • nowrap: Items are forced to stay on a single line.
  • wrap: Items wrap onto multiple lines if necessary.
  • wrap-reverse: Items wrap onto multiple lines in reverse order.
...
flex-grow number Specifies the ability for a flex item to grow if necessary within the flex container.
...
flex-shrink number Specifies the ability for a flex item to shrink if necessary within the flex container.
...
flex-basis length, auto Specifies the initial size of a flex item before any remaining space is distributed.

  • length: Specifies a fixed length for the flex item.
  • auto: The default size of the flex item based on its content.
...