CSS Flexbox Cheatsheet
cssComplete CSS Flexbox reference with visual descriptions.
Display & Direction
display: flex | inline-flex;Defines a flex container and enables flex context for direct children
.container {
display: flex;
}flex-direction: row | row-reverse | column | column-reverse;Establishes the main axis direction for flex items
.container {
flex-direction: column;
}flex-direction: row;Items are placed left to right in ltr (default)
.container { flex-direction: row; }flex-direction: row-reverse;Items are placed right to left in ltr
.container { flex-direction: row-reverse; }flex-direction: column;Items are placed top to bottom
.container { flex-direction: column; }flex-direction: column-reverse;Items are placed bottom to top
.container { flex-direction: column-reverse; }Wrapping & Flow
flex-wrap: nowrap | wrap | wrap-reverse;Controls whether flex items wrap onto multiple lines
.container {
flex-wrap: wrap;
}flex-wrap: nowrap;All items stay on one line (default)
.container { flex-wrap: nowrap; }flex-wrap: wrap;Items wrap onto multiple lines from top to bottom
.container { flex-wrap: wrap; }flex-wrap: wrap-reverse;Items wrap onto multiple lines from bottom to top
.container { flex-wrap: wrap-reverse; }flex-flow: <flex-direction> <flex-wrap>;Shorthand for flex-direction and flex-wrap combined
.container {
flex-flow: row wrap;
}Main Axis Alignment (justify-content)
justify-content: flex-start | flex-end | center | space-between | space-around | space-evenly;Aligns items along the main axis
.container {
justify-content: center;
}justify-content: flex-start;Items packed toward the start of main axis (default)
.container { justify-content: flex-start; }justify-content: flex-end;Items packed toward the end of main axis
.container { justify-content: flex-end; }justify-content: center;Items centered along the main axis
.container { justify-content: center; }justify-content: space-between;Items evenly distributed with first item at start and last at end
.container { justify-content: space-between; }justify-content: space-around;Items evenly distributed with equal space around each
.container { justify-content: space-around; }justify-content: space-evenly;Items distributed with equal space between all items and edges
.container { justify-content: space-evenly; }Cross Axis Alignment (align-items & align-content)
align-items: stretch | flex-start | flex-end | center | baseline;Aligns items along the cross axis on the current line
.container {
align-items: center;
}align-items: stretch;Items stretch to fill the container cross axis (default)
.container { align-items: stretch; }align-items: flex-start;Items aligned to the start of the cross axis
.container { align-items: flex-start; }align-items: flex-end;Items aligned to the end of the cross axis
.container { align-items: flex-end; }align-items: center;Items centered on the cross axis
.container { align-items: center; }align-items: baseline;Items aligned by their text baselines
.container { align-items: baseline; }align-content: flex-start | flex-end | center | space-between | space-around | stretch;Aligns flex lines when there is extra space on the cross axis
.container {
flex-wrap: wrap;
align-content: space-between;
}align-content: stretch;Lines stretch to fill remaining space (default)
.container { align-content: stretch; }align-content: space-between;Lines evenly distributed with first line at start and last at end
.container { align-content: space-between; }Gap Properties
gap: <row-gap> <column-gap>;Sets spacing between flex items in both directions
.container {
display: flex;
gap: 20px;
}row-gap: <length>;Sets spacing between rows of flex items
.container {
row-gap: 15px;
}column-gap: <length>;Sets spacing between columns of flex items
.container {
column-gap: 10px;
}gap: <row-gap> <column-gap>;First value sets row gap and second sets column gap
.container {
gap: 20px 10px;
}Flex Item Sizing
flex-grow: <number>;Defines how much an item should grow relative to siblings
.item {
flex-grow: 1;
}flex-shrink: <number>;Defines how much an item should shrink relative to siblings
.item {
flex-shrink: 0;
}flex-basis: <length> | auto | content;Defines the initial main size of a flex item before growing or shrinking
.item {
flex-basis: 200px;
}flex: <grow> <shrink> <basis>;Shorthand for flex-grow flex-shrink and flex-basis combined
.item {
flex: 1 0 auto;
}flex: auto;Equivalent to flex: 1 1 auto - item can grow and shrink
.item { flex: auto; }flex: none;Equivalent to flex: 0 0 auto - item is fully inflexible
.item { flex: none; }flex: 1;Equivalent to flex: 1 1 0% - items share space equally
.item { flex: 1; }Flex Item Ordering & Alignment
order: <integer>;Controls the order in which flex items appear in the container
.item {
order: 2;
}order: -1;Negative values place items before items with default order of 0
.item-first { order: -1; }align-self: auto | flex-start | flex-end | center | baseline | stretch;Overrides container align-items for individual flex items
.item {
align-self: flex-end;
}align-self: auto;Item uses the parent containers align-items value (default)
.item { align-self: auto; }align-self: center;Individual item is centered on the cross axis
.item { align-self: center; }align-self: stretch;Individual item stretches to fill the container
.item { align-self: stretch; }Common Flexbox Patterns
display: flex; justify-content: center; align-items: center;Perfect centering of content horizontally and vertically
.container {
display: flex;
justify-content: center;
align-items: center;
}display: flex; .item { flex: 1; }Creates equal width columns that share available space
.container { display: flex; }
.item { flex: 1; }display: flex; flex-direction: column; .main { flex: 1; }Footer sticks to bottom when content is short
.page {
display: flex;
flex-direction: column;
min-height: 100vh;
}
.main { flex: 1; }display: flex; justify-content: space-between; align-items: center;Common navbar layout with logo left and nav items right
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
}display: flex; flex-wrap: wrap; gap: 20px;Responsive card layout that wraps with consistent spacing
.cards {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.card { flex: 1 1 300px; }margin-left: auto;Pushes a single item to the far end using auto margins
.nav { display: flex; }
.logout { margin-left: auto; }