Cssgrid
Cssgrid
HOME / GUIDES /
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/9
3/12/24, 10:14 PM A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
(#aa-background) Background
(#aa-properties-for-the-
parentflex-container) Properties
for the Parent
(flex container)
(#aa-display) display
This defines a flex container; inline or block
depending on the given value. It enables a flex
context for all its direct children.
CSS
.container {
display: flex; /* or inline-flex */
}
(#aa-flex-direction) flex-direction
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 2/9
3/12/24, 10:14 PM A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
CSS
.container {
flex-direction: row | row-reverse | column | column-reverse;
}
(#aa-flex-wrap) flex-wrap
CSS
.container {
flex-wrap: nowrap | wrap | wrap-reverse;
}
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 3/9
3/12/24, 10:14 PM A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
(#aa-flex-flow) flex-flow
This is a shorthand for the flex-direction and
flex-wrap properties, which together define the
flex container’s main and cross axes. The default
value is row nowrap.
CSS
.container {
flex-flow: column wrap;
}
(#aa-justify-content) justify-content
(#aa-properties-for-the-
childrenflex-items) Properties for
the Children
(flex items)
(#aa-order) order
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 4/9
3/12/24, 10:14 PM A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
.container {
CSS
Items with the same order revert to source order.
justify-content: flex-start | flex-end | center | space-betw
}
(#aa-flex-grow) flex-grow
flex-start (default): items are packed toward
the start of the flex-direction.
flex-end: items are packed toward the end of
the flex-direction.
start: items are packed toward the start of the
writing-mode direction.
space-between: items are evenly distributed in space either one of the others (or it will try, at
the line; first item is on the start line, last item least).
on the end line
CSS
CSS
Note that that browser support for these values is .item {
flex-shrink: 3; /* default 1 */
nuanced. For example, space-between never got }
(https://developer.mozilla.org/en-
US/docs/Web/CSS/justify-content) . The safest
values are flex-start, flex-end, and center.
(#aa-flex-basis) flex-basis
There are also two additional keywords you can This defines the default size of an element before
pair with these values: safe and unsafe. Using the remaining space is distributed. It can be a
safe ensures that however you do this type of length (e.g. 20%, 5rem, etc.) or a keyword. The
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 5/9
3/12/24, 10:14 PM A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
positioning, you can’t push an element such that auto keyword means “look at my width or height
it renders off-screen (e.g. off the top) in such a property” (which was temporarily done by the
way the content can’t be scrolled too (called “data main-size keyword until deprecated). The
loss”). content keyword means “size it based on the
item’s content” – this keyword isn’t well
supported yet, so it’s hard to test and harder to
(#aa-align-items) align-items know what its brethren max-content, min-
content, and fit-content do.
CSS
.item {
flex-basis: | auto; /* default auto */
}
(#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-
This defines the default behavior for how flex basis) are optional. The default is 0 1 auto, but
items are laid out along the cross axis on the if you set it with a single number value, like flex:
current line. Think of it as the justify-content 5;, that changes the flex-basis to 0%, so it’s like
version for the cross-axis (perpendicular to the setting flex-grow: 5; flex-shrink: 1; flex-
main-axis). basis: 0%;.
CSS
CSS
.container { .item {
align-items: stretch | flex-start | flex-end | center | base flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basi
} }
stretch (default): stretch to fill the container It is recommended that you use this
(still respect min-width/max-width) shorthand property rather than set the
flex-start / start / self-start: items are individual properties. The shorthand sets the
placed at the start of the cross axis. The other values intelligently.
difference between these is subtle, and is
about respecting the flex-direction rules or
the writing-mode rules.
flex-end / end / self-end: items are placed at (#aa-align-self) align-self
the end of the cross axis. The difference again
is subtle and is about respecting flex-
direction rules vs. writing-mode rules.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 6/9
3/12/24, 10:14 PM A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
CSS
.item {
align-self: auto | flex-start | flex-end | center | baseline
}
CSS
.container {
align-content: flex-start | flex-end | center | space-betwee
}
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 7/9
3/12/24, 10:14 PM A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
(#aa-gap-row-gap-column-gap) gap,
row-gap, column-gap
https://css-tricks.com/snippets/css/a-guide-to-flexbox/ 8/9
3/12/24, 10:14 PM A Complete Guide to Flexbox | CSS-Tricks - CSS-Tricks
CSS
.container {
display: flex;
...
gap: 10px;
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/ 9/9