CSS Flexbox Cheatsheet - Flexbox Layout Reference

All essential CSS Flexbox commands organized by use case, with 44+ entries you can copy and run directly. Find the right command fast when you need it.

Web Services·44 commands·Last updated 2026-07-21
Back to Web Services

Container Properties 8

display: flex
Enable flex layout (block-level)
display: inline-flex
Enable flex layout (inline-level)
flex-direction: row
Main axis = row, horizontal (default)
flex-direction: column
Main axis = column, vertical
flex-direction: row-reverse
Row, reversed order
flex-direction: column-reverse
Column, reversed order
flex-wrap: wrap
Allow wrap (default nowrap)
flex-flow: row wrap
Shorthand for direction + wrap

Gap & Main-axis Alignment 8

gap: 16px
Gap between items (row & column)
row-gap: 16px
Row gap only
column-gap: 16px
Column gap only
justify-content: flex-start
Start of main axis (default)
justify-content: center
Center on main axis
justify-content: flex-end
End of main axis
justify-content: space-between
Space between, ends flush
justify-content: space-around
Equal space around each item

Cross-axis Alignment 7

justify-content: space-evenly
All gaps exactly equal
align-items: stretch
Stretch to fill cross axis (default)
align-items: flex-start
Start of cross axis
align-items: center
Center on cross axis
align-items: flex-end
End of cross axis
align-items: baseline
Align on baseline
align-content: center
Cross-axis alignment of wrapped lines

Item Properties 10

flex-grow: 1
Grow factor, 0 = no grow (default)
flex-shrink: 1
Shrink factor, 0 = no shrink (default 1)
flex-basis: 200px
Initial size (default auto)
flex: 1
Shorthand: 1 1 0%, share free space
flex: 0 0 200px
Shorthand: no grow/shrink, fixed 200px
flex: auto
Shorthand: 1 1 auto
flex: none
Shorthand: 0 0 auto, no grow/shrink
align-self: flex-end
Override align-items for one item
order: 1
Display order, default 0, can be negative
order: -1
Move to the front

Common Patterns 6

justify-content: center; align-items: center
Horizontal & vertical center
justify-content: space-between
Space-between (navbar left/right)
flex: 1
Share remaining space
margin-left: auto
Push item to end of main axis
min-height: 100vh
Sticky footer with column (child flex:1)
flex: 1 0 auto
Fixed base, no shrink (sidebar)

Responsive Tips 5

flex-wrap: wrap
Auto wrap when window narrows
flex-basis: 200px; flex-grow: 1
Responsive card grid
flex-wrap: wrap-reverse
Reverse 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 是 flex: 1 1 0% 的简写,表示等分剩余空间。
  • align-items 是交叉轴对齐,flex-direction: column 时交叉轴变为水平方向。
  • gap 属性替代了旧的 margin 技巧,更简洁地设置项目间距。
  • flex-wrap: wrap 配合 flex-basis 可以实现响应式网格布局。
  • flex 简写优先使用,单独设置 flex-grow/shrink/basis 容易覆盖预期行为。

Official References

Commands are compiled from the official docs below. Click to verify the latest usage.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Found an error? Report it

Wrong command or description? Open an issue to help us fix it.

Found an error? Report it