A Complete Guide To Flexbox - CSS-Tricks - CSS-Tricks
A Complete Guide To Flexbox - CSS-Tricks - CSS-Tricks
HOME /
GUIDES /
Our comprehensive guide to CSS flexbox layout. This complete guide explains
everything about flexbox, focusing on all the different possible properties for the
parent element (the flex container) and the child elements (the flex items). It also
includes history, demos, patterns, and a browser support chart.
Table of contents
Part 1: (#aa-introduction) Background (#aa-background)
Part 2: (#aa-introduction) Basics and terminology (#aa-basics-and-terminology)
Part 3: (#aa-introduction) Flexbox properties (#aa-flexbox-properties)
Part 4: (#aa-introduction) Prefixing Flexbox (#aa-prefixing-flexbox)
Part 5: (#aa-introduction) Examples (#aa-examples)
Part 6: (#aa-introduction) Flexbox tricks (#aa-flexbox-tricks)
Part 7: (#aa-introduction) Browser support (#aa-browser-support)
Part 8: (#aa-introduction) Bugs (#aa-bugs)
Part 9: (#aa-introduction) Related properties (#aa-related-properties)
Part 10: (#aa-introduction) More information (#aa-more-information)
Part 11: More sources (#aa-more-sources)
Reference this guide a lot? Here’s a high-res image you can print!
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 1/10
26/11/22, 12:03 A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
(#aa-background) Background
(#aa-properties-for-the- (#aa-properties-for-the-
parentflex-container) Properties childrenflex-items) Properties for
for the Parent
the Children
CSS
.container {
(#aa-flex-direction) flex- By default, flex items are laid out in the source
direction order. However, the order property controls
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 2/10
26/11/22, 12:03 A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
CSS
.item {
order: 5; /* default is 0 */
CSS
.container {
row-reverse: right to left in ltr; left to This defines the ability for a flex item to grow
right in rtl if necessary. It accepts a unitless value that
column: same as row but top to bottom serves as a proportion. It dictates what
column-reverse: same as row-reverse amount of the available space inside the flex
but bottom to top container the item should take up.
CSS
.item {
flex-grow: 4; /* default 0 */
CSS
.container {
(#aa-flex-shrink) flex-shrink
flex-wrap: nowrap | wrap | wrap-reverse;
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 3/10
26/11/22, 12:03 A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
}
wrap-reverse: flex items will wrap onto
multiple lines from bottom to top.
Negative numbers are invalid.
There are some visual demos of flex-wrap
here (https://css-
tricks.com/almanac/properties/f/flex-wrap/) .
(#aa-flex-basis) flex-basis
This defines the default size of an element
before the remaining space is distributed. It
(#aa-flex-flow) flex-flow can be a length (e.g. 20%, 5rem, etc.) or a
This is a shorthand for the flex-direction keyword. The auto keyword means “look at
and flex-wrap properties, which together my width or height property” (which was
define the flex container’s main and cross temporarily done by the main-size keyword
axes. The default value is row nowrap. until deprecated). The content keyword
means “size it based on the item’s content” –
CSS
.container {
this keyword isn’t well supported yet, so it’s
flex-flow: column wrap;
}
hard to test and harder to know what its
brethren max-content, min-content, and
fit-content do.
CSS
.item {
(#aa-justify-content) justify-
flex-basis: | auto; /* default auto */
content }
(#aa-flex) flex
This is the shorthand for flex-grow, flex-
shrink and flex-basis combined. The
second and third parameters (flex-shrink
and flex-basis) are optional. The default is
0 1 auto, but if you set it with a single
number value, like flex: 5;, that changes
the flex-basis to 0%, so it’s like setting
flex-grow: 5; flex-shrink: 1; flex-
basis: 0%;.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 4/10
26/11/22, 12:03 A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
.item {
CSS
This defines the alignment along the main flex: none | [ <'flex-grow'> <'flex-shrink'>? |
}
axis. It helps distribute extra free space
leftover when either all the flex items on a line
are inflexible, or are flexible but have reached It is recommended that you use this
their maximum size. It also exerts some shorthand property rather than set the
control over the alignment of items when they individual properties. The shorthand sets the
CSS
.container {
.item {
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 5/10
26/11/22, 12:03 A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
(#aa-align-items) align-items
CSS
.container {
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 6/10
26/11/22, 12:03 A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
}
(#aa-align-content) align-
content
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 7/10
26/11/22, 12:03 A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
CSS
.container {
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 8/10
26/11/22, 12:03 A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
(#aa-gap-row-gap-column-gap)
gap, row-gap, column-gap
CSS
.container {
display: flex;
...
gap: 10px;
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 9/10
26/11/22, 12:03 A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
gap: 10px 20px; /* row-gap column gap */
row-gap: 10px;
column-gap: 20px;
(#aa-examples) Examples
(#aa-bugs) Bugs
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 10/10