CSS Flexbox Cheatsheet — Complete Quick Reference (2026)
DodaTech
Updated 2026-06-20
2 min read
In this tutorial, you'll learn about CSS Flexbox Cheatsheet. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
CSS Flexbox provides a one-dimensional layout model that distributes space and aligns items within a container, ideal for rows, columns, and responsive components.
Container Properties
| Property | Values | Description |
|---|---|---|
display |
flex, inline-flex |
Enable Flexbox |
flex-direction |
row, row-reverse, column, column-reverse |
Main axis direction |
flex-wrap |
nowrap, wrap, wrap-reverse |
Allow wrapping |
flex-flow |
<direction> <wrap> |
Shorthand |
justify-content |
flex-start, flex-end, center, space-between, space-around, space-evenly |
Main axis alignment |
align-items |
stretch, flex-start, flex-end, center, baseline |
Cross axis alignment |
align-content |
stretch, flex-start, flex-end, center, space-between, space-around |
Multi-line cross axis |
gap |
<length> |
Space between items |
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
gap: 1rem;
}
Item Properties
| Property | Values | Description |
|---|---|---|
flex-grow |
<number> (default 0) |
Proportion of extra space |
flex-shrink |
<number> (default 1) |
Proportion to shrink |
flex-basis |
<length>, auto, content |
Initial size |
flex |
<grow> <shrink> <basis> |
Shorthand |
align-self |
auto, flex-start, flex-end, center, baseline, stretch |
Override align-items |
order |
<integer> (default 0) |
Visual order |
.item { flex: 1 1 200px; } /* grow, shrink, basis */
.item-grow { flex-grow: 2; } /* takes 2x space */
.item-fixed { flex: 0 0 300px; } /* no grow, no shrink */
.item-last { order: 1; } /* reorder visually */
Common Layout Patterns
Centering:
.centered {
display: flex;
justify-content: center;
align-items: center;
}
Sticky footer:
body { display: flex; flex-direction: column; min-height: 100vh; }
main { flex: 1; } /* pushes footer down */
Equal-height columns:
.row { display: flex; }
.col { flex: 1; } /* all equal width & height */
Holy grail layout:
body { display: flex; flex-direction: column; min-height: 100vh; }
.content { display: flex; flex: 1; }
nav, aside { flex: 0 0 200px; }
main { flex: 1; }
Must-Know Items
flex: 1=flex-grow: 1; flex-shrink: 1; flex-basis: 0%flex: auto=flex-grow: 1; flex-shrink: 1; flex-basis: autoflex: none=flex: 0 0 auto— item size determined by content- Negative
ordervalues place items before default (0) order gapworks in both row and column directions — replaces margin hacksmin-width: 0may be needed to prevent overflow on flex items (defaultmin-width: auto)align-contentonly affects multi-line flex containers (whenflex-wrap: wrap)- Cross-axis margins (
margin-left: auto) push items to opposite end
See full CSS tutorials for advanced layout techniques.
← Previous
Redis Cheatsheet — Complete Quick Reference (2026)
Next →
CSS Grid Cheatsheet — Complete Quick Reference (2026)
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro