A CSS Flexbox cheatsheet is a quick reference for all flex container and flex item properties. Flexbox is the most widely-used CSS layout system for building responsive one-dimensional layouts — rows or columns of items that distribute space automatically. Click any value below to see a live preview of exactly how it affects item placement.

display
Activates flexbox on the container element
1
2
3

flex makes the container a block-level flex container. inline-flex makes it inline-level.

flex-direction
Sets the main axis direction for flex items
1
2
3

row (default) lays items left-to-right. column stacks them top-to-bottom.

justify-content
Aligns items along the main axis
1
2
3

space-between distributes items with equal space between. space-evenly includes equal space at edges too.

align-items
Aligns items along the cross axis
1
2
3

stretch (default) makes items fill the container height. center vertically centers them.

flex-wrap
Controls whether items wrap to new lines
1
2
3
4
5

nowrap (default) keeps all items on one line, shrinking them if needed. wrap allows overflow onto new lines.

align-content
Aligns flex lines when there is extra cross-axis space (requires wrapping)
1
2
3
4
5

Only has an effect when flex-wrap creates multiple lines. Controls vertical spacing between those lines.

gap
Sets spacing between flex items (row-gap and column-gap)
1
2
3
4

gap is shorthand for row-gap column-gap. Replaces older margin hacks. Works with both wrapped and unwrapped layouts.

Quick Reference: Shorthand Properties

Shorthand Equivalent Use case
flex: 1 grow:1 shrink:1 basis:0% Equal-width flexible columns
flex: auto grow:1 shrink:1 basis:auto Grow and shrink from content size
flex: none grow:0 shrink:0 basis:auto Rigid item, fixed to content size
flex: 0 1 200px grow:0 shrink:1 basis:200px Fixed base size, can shrink
flex-flow: row wrap direction + wrap Responsive wrapping row layout
place-content: center align + justify-content Center content on both axes

Common Flexbox Patterns

Perfect centering
display: flex;
justify-content: center;
align-items: center;
Sticky footer layout
display: flex;
flex-direction: column;
min-height: 100vh;
/* main gets: flex: 1 */
Equal-width columns
display: flex;
gap: 1rem;
/* children get: flex: 1 */
Responsive card grid
display: flex;
flex-wrap: wrap;
gap: 1rem;
/* children: flex: 1 1 200px */