Default. Items are placed left to right in a horizontal row.
Flex Direction
The flex-direction property defines the main axis direction. Items are laid out along this axis.
Items are placed right to left in reverse order.
Items are placed top to bottom in a vertical column.
Items are placed bottom to top in reverse order.
.container { display: flex; }
.row { flex-direction: row; }
.row-reverse { flex-direction: row-reverse; }
.column { flex-direction: column; }
.column-reverse { flex-direction: column-reverse; }Justify Content
The justify-content property aligns items along the main axis (horizontal for row, vertical for column).
Items packed at the start of the main axis.
Items centered along the main axis.
Items packed at the end of the main axis.
Equal space between items, no space at edges.
Equal space around items (half-size at edges).
Equal space between and around all items.
.start { justify-content: flex-start; }
.center { justify-content: center; }
.end { justify-content: flex-end; }
.between { justify-content: space-between; }
.around { justify-content: space-around; }
.evenly { justify-content: space-evenly; }Align Items
The align-items property aligns items along the cross axis (vertical for row, horizontal for column).
Default. Items stretch to fill the container height.
Items aligned to the top of the container.
Items centered vertically in the container.
Items aligned to the bottom of the container.
Items aligned by their text baseline.
.stretch { align-items: stretch; }
.start { align-items: flex-start; }
.center { align-items: center; }
.end { align-items: flex-end; }
.baseline { align-items: baseline; }Flex Wrap
The flex-wrap property controls whether items wrap to new lines when they don't fit in the container.
Default. Items shrink to fit on one line.
Items wrap to new lines when needed.
Items wrap in reverse, new lines appear above.
.nowrap { flex-wrap: nowrap; }
.wrap { flex-wrap: wrap; }
.wrap-reverse { flex-wrap: wrap-reverse; }Gap
The gap property adds space between flex items without affecting the outer edges. You can also use row-gap and column-gap.
Small gap between all items.
Medium gap between all items.
Large gap between all items.
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.gap-lg { gap: 1.5rem; }
.gap-xl { gap: 2rem; }
.gap-row-col { row-gap: 1rem; column-gap: 2rem; }Flex grow, shrink, basis — and flex: 1 in CSS
Half the Stack Overflow answers just say “use flex: 1” Here is what that actually expands to: flex-grow, flex-shrink, and flex-basis in one line. Tweak those pieces when equal columns are not quite what you need.
All items grow equally to fill available space.
Middle item grows twice as much as others.
Item won't shrink below its content/basis size.
Set the initial size before growing/shrinking.
.grow { flex-grow: 1; }
.grow-double { flex-grow: 2; }
.no-shrink { flex-shrink: 0; }
.basis { flex-basis: 200px; }
/* Shorthand: flex: grow shrink basis */
.flex-1 { flex: 1 1 0%; }
.flex-auto { flex: 1 1 auto; }
.flex-none { flex: 0 0 auto; }Common Flexbox Patterns
Practical flexbox layouts you can use in real projects.
Center any element both horizontally and vertically.
Logo on left, links on right with space-between.
Cards with flex: 1 share space equally.
Responsive footer that wraps on smaller screens.
/* Perfect centering */
.center { display: flex; justify-content: center; align-items: center; }
/* Navigation */
.nav { display: flex; justify-content: space-between; align-items: center; }
/* Equal cards */
.cards { display: flex; gap: 1rem; }
.card { flex: 1; }
/* Footer columns */
.footer { display: flex; flex-wrap: wrap; gap: 2rem; }
.footer-col { flex: 1; min-width: 150px; }