CSS Flexbox Cheatsheet
š§© CSS Flexbox Cheatsheet
Flexbox is a one-dimensional layout system. It solves common centering, spacing, and ordering problems with a small set of container and item properties.
ā Basic flex properties ā display ā flex-direction ā flex-wrap ā flex-flow ā gap / row-gap / column-gap ā order ā flex-grow ā flex-shrink ā flex-basis ā flex
#css #flexbox #layout #frontend #webdev #responsive #alignment #spacing #csslayout #uidesign
Basic flex properties
CSS Flexbox is a one-dimensional layout system.
| Property | Notes |
|---|---|
display | flex or inline-flex establishes a flex formatting context. |
flex-direction | Main axis direction: row, row-reverse, column, column-reverse. |
flex-wrap | Whether items wrap: nowrap, wrap, wrap-reverse. |
flex-flow | Shorthand for flex-direction and flex-wrap. |
gap | Spacing between flex items. |
row-gap | Spacing between rows when wrapped. |
column-gap | Spacing between columns. |
order | Controls visual order of a flex item. |
flex-grow | How much an item grows relative to others. |
flex-shrink | How much an item shrinks relative to others. |
flex-basis | Initial size of an item before grow/shrink. |
flex | Shorthand for flex-grow, flex-shrink, and flex-basis. |
align-self | Overrides cross-axis alignment for a single item. |
display
Turns an element into a flex container.
.container {
display: flex; /* or inline-flex */
}flex-direction
Sets the main axis direction.
.container {
display: flex;
flex-direction: row; /* row | row-reverse | column | column-reverse */
}row
1
2
3
row-reverse
1
2
3
column
1
2
3
column-reverse
1
2
3
flex-wrap
Controls whether items wrap onto multiple lines.
.container {
display: flex;
flex-wrap: wrap; /* nowrap | wrap | wrap-reverse */
}wrap
1
2
3
4
nowrap
1
2
3
4
wrap-reverse
1
2
3
4
flex-flow
Shorthand for flex-direction and flex-wrap.
.container {
display: flex;
flex-flow: row wrap;
}gap / row-gap / column-gap
Spacing between flex items.
.container {
display: flex;
gap: 16px;
}1
2
3
.container {
display: flex;
flex-wrap: wrap;
row-gap: 12px;
column-gap: 24px;
}1
2
3
4
order
Changes the visual order of a flex item.
.container {
display: flex;
gap: 16px;
}
.item-first {
order: -1; /* default is 0 */
}1
2 (first)
3
flex-grow
Controls how much an item grows relative to others.
.item-grow {
flex-grow: 2; /* default is 0 */
}grow 2
flex-shrink
Controls how much an item shrinks relative to others.
.item-shrink {
flex-shrink: 0; /* default is 1 */
}shrink 2
flex-basis
Sets the initial size of an item before grow/shrink.
.item-basis {
flex-basis: 200px; /* default is auto */
}80px
160px
320px
flex
Shorthand for flex-grow, flex-shrink, and flex-basis.
.item {
flex: 1 1 200px; /* flex: <grow> <shrink> <basis> */
}Full-Stack AI Developer Roadmap
From HTML & CSS to working with AI models, all in one structured roadmap.