Home/Utilities/Flexbox

Flexbox

Flex direction, wrap, alignment, justify, sizing, and order utilities - all with responsive variants.

Flex direction

Control the main axis of a flex container. All classes support responsive prefixes.

1
2
3
.flex-row
1
2
3
.flex-col
<div class="flex flex-row">...</div>
<div class="flex flex-col">...</div>
<div class="flex flex-row-reverse">...</div>
<div class="flex flex-col-reverse">...</div>
ClassCSS
.flex-rowflex-direction: row
.flex-colflex-direction: column
.flex-row-reverseflex-direction: row-reverse
.flex-col-reverseflex-direction: column-reverse

Flex wrap

Control whether flex items wrap onto multiple lines.

<div class="flex flex-wrap">...</div>
<div class="flex flex-nowrap">...</div>
<div class="flex flex-wrap-reverse">...</div>
ClassCSS
.flex-wrapflex-wrap: wrap
.flex-nowrapflex-wrap: nowrap
.flex-wrap-reverseflex-wrap: wrap-reverse

Align items

Control how flex children align along the cross axis.

A
B
C
.items-end
<div class="flex items-start">...</div>
<div class="flex items-center">...</div>
<div class="flex items-end">...</div>
<div class="flex items-stretch">...</div>
<div class="flex items-baseline">...</div>
ClassCSS
.items-startalign-items: flex-start
.items-endalign-items: flex-end
.items-centeralign-items: center
.items-stretchalign-items: stretch
.items-baselinealign-items: baseline

Justify content

Distribute space along the main axis.

.justify-between

A
B
C

.justify-center

A
B
C
<div class="flex justify-start">...</div>
<div class="flex justify-center">...</div>
<div class="flex justify-end">...</div>
<div class="flex justify-between">...</div>
<div class="flex justify-around">...</div>
<div class="flex justify-evenly">...</div>
ClassCSS
.justify-startjustify-content: flex-start
.justify-endjustify-content: flex-end
.justify-centerjustify-content: center
.justify-betweenjustify-content: space-between
.justify-aroundjustify-content: space-around
.justify-evenlyjustify-content: space-evenly
.justify-stretchjustify-content: stretch

Flex sizing

Control how a flex item grows and shrinks relative to its siblings. Values map to flex: grow shrink basis.

flex-1
flex-2 (twice as wide)
flex-1
<div class="flex">
  <div class="flex-1">Equal width</div>
  <div class="flex-2">Double width</div>
  <div class="flex-auto">Shrinks to content</div>
  <div class="flex-none">Does not grow or shrink</div>
</div>
ClassCSS
.flex-1.flex-12flex: n n 0%
.flex-autoflex: 1 1 auto
.flex-noneflex: none
.flex-spandisplay: flex; flex: 1 - fills remaining space

Align self

Override the cross-axis alignment for an individual flex child.

<div class="flex items-start">
  <div class="self-center">Centered individually</div>
  <div class="self-end">Pinned to end</div>
</div>
ClassCSS
.self-startalign-self: flex-start
.self-endalign-self: flex-end
.self-centeralign-self: center
.self-stretchalign-self: stretch
.self-baselinealign-self: baseline

Flex grow & shrink

Toggle how an individual flex item grows or shrinks, independent of the flex-{n} shorthand.

flex-1
flex-grow-0
<div class="flex">
  <div class="flex-1">Grows to fill</div>
  <div class="flex-grow-0">Does not grow</div>
  <div class="flex-shrink-0">Never shrinks</div>
</div>
ClassCSS
.flex-grow-0flex-grow: 0
.flex-grow-1flex-grow: 1
.flex-shrink-0flex-shrink: 0
.flex-shrink-1flex-shrink: 1

Order

Reorder flex children with .item-{key}. Shortcuts .item-first and .item-last pin an item to each end.

<div class="flex">
  <div class="item-first">First</div>
  <div class="item-2">Second</div>
  <div class="item-3">Third</div>
  <div class="item-last">Last</div>
</div>

Numeric keys follow the flexItems config map (item-1 through item-12) and all order classes support responsive variants, e.g. md:item-2.

Justify items & self

.justify-items-* distributes items on the inline axis; .justify-self-* does the same for a single item. Both also apply to CSS grid.

<div class="flex justify-items-center">
  <div>One</div>
  <div>Two</div>
</div>
<div class="flex items-center">
  <div class="justify-self-end">Pushed right</div>
</div>
ClassCSS
.justify-items-{key}justify-items: {key}
.justify-self-{key}justify-self: {key}

Both accept the same keys as .justify-*: start, end, center, between, around, evenly, and stretch.

Flex row & col shortcut

.flex-row / .row is a responsive shorthand: items stack in a column on small screens, wrap from md, and display as a row from lg up. Children can use .col to auto-size.

<!-- Stacks on mobile, row on desktop -->
<div class="row">
  <div class="col">Column A</div>
  <div class="col">Column B</div>
</div>
Responsive variants. All flexbox utilities - direction, wrap, align, and justify - support breakpoint prefixes like md:flex-col, lg:justify-between, and sm:items-center.