Learn how to create flexible and responsive layouts using CSS Flexbox
Flexbox Container and Items
display
property to flex
or inline-flex
:
flex-direction
property establishes the main axis, defining the direction flex items are placed in the flex container.
Flex Direction Options
flex-wrap
property controls whether flex items are forced onto a single line or can wrap onto multiple lines.
Flex Wrap Options
flex-flow
property is a shorthand for flex-direction
and flex-wrap
.
justify-content
property aligns flex items along the main axis, distributing extra free space.
Justify Content Options
align-items
property aligns flex items along the cross axis (perpendicular to the main axis).
Align Items Options
align-content
property aligns a flex container’s lines within the flex container when there is extra space in the cross axis. It only applies when there are multiple lines (when flex-wrap: wrap
or flex-wrap: wrap-reverse
).
Align Content Options
order
property controls the order in which flex items appear in the flex container. By default, items are laid out in the source order, but order
can change this.
Order Property Example
flex-grow
property defines the ability for a flex item to grow if necessary. It accepts a unitless value that serves as a proportion, determining how much of the available space the item should take up.
Flex Grow Example
flex-shrink
property defines the ability for a flex item to shrink if necessary. Like flex-grow
, it accepts a unitless value.
flex-basis
property defines the default size of an element before the remaining space is distributed. It can be a length (e.g., 20%, 5rem, etc.) or a keyword (auto, content).
flex
property is a shorthand for flex-grow
, flex-shrink
, and flex-basis
.
flex
shorthand is recommended over the individual properties. The shorthand sets the other values intelligently.align-self
property allows the default alignment (set by align-items
) to be overridden for individual flex items.
Align Self Example
display: flex