CSS Flexbox Cheatsheet - Flexbox Layout Reference
For developers who have fought with floats or inline-block for centering and equal-width rows. Flexbox is the modern way to lay out a single row or column quickly. The recurring confusion is that Flexbox is one-dimensional and that justify-content and align-items act on different axes. By the end you can center anything, build a toolbar and a wrapping card row, and control item sizing with flex-grow/flex-shrink/flex-basis without trial and error.
Container Properties 8
display: flexEnable flex layout (block-level)
display: inline-flexEnable flex layout (inline-level)
flex-direction: rowMain axis = row, horizontal (default)
flex-direction: columnMain axis = column, vertical
flex-direction: row-reverseRow, reversed order
flex-direction: column-reverseColumn, reversed order
flex-wrap: wrapAllow wrap (default nowrap)
flex-flow: row wrapShorthand for direction + wrap
Gap & Main-axis Alignment 8
gap: 16pxGap between items (row & column)
row-gap: 16pxRow gap only
column-gap: 16pxColumn gap only
justify-content: flex-startStart of main axis (default)
justify-content: centerCenter on main axis
justify-content: flex-endEnd of main axis
justify-content: space-betweenSpace between, ends flush
justify-content: space-aroundEqual space around each item
Cross-axis Alignment 7
justify-content: space-evenlyAll gaps exactly equal
align-items: stretchStretch to fill cross axis (default)
align-items: flex-startStart of cross axis
align-items: centerCenter on cross axis
align-items: flex-endEnd of cross axis
align-items: baselineAlign on baseline
align-content: centerCross-axis alignment of wrapped lines
Item Properties 10
flex-grow: 1Grow factor, 0 = no grow (default)
flex-shrink: 1Shrink factor, 0 = no shrink (default 1)
flex-basis: 200pxInitial size (default auto)
flex: 1Shorthand: 1 1 0%, share free space
flex: 0 0 200pxShorthand: no grow/shrink, fixed 200px
flex: autoShorthand: 1 1 auto
flex: noneShorthand: 0 0 auto, no grow/shrink
align-self: flex-endOverride align-items for one item
order: 1Display order, default 0, can be negative
order: -1Move to the front
Common Patterns 6
justify-content: center; align-items: centerHorizontal & vertical center
justify-content: space-betweenSpace-between (navbar left/right)
flex: 1Share remaining space
margin-left: autoPush item to end of main axis
min-height: 100vhSticky footer with column (child flex:1)
flex: 1 0 autoFixed base, no shrink (sidebar)
Responsive Tips 5
flex-wrap: wrapAuto wrap when window narrows
flex-basis: 200px; flex-grow: 1Responsive card grid
flex-wrap: wrap-reverseReverse wrap layout
@media (max-width: 768px) { flex-direction: column }Switch to column on mobile
flex: 1 1 100%Fill full row, force wrap
Tips
- flex: 1 is shorthand for flex: 1 1 0% — it divides the remaining space equally.
- align-items aligns on the cross axis; with flex-direction: column the cross axis becomes horizontal.
- The gap property replaces the old margin trick, setting item spacing more cleanly.
- flex-wrap: wrap combined with flex-basis enables responsive grid-like layouts.
- Prefer the flex shorthand; setting flex-grow/shrink/basis separately easily overrides intended behavior.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us