Epic CSS / Documentation

Flexbox

Arrange a group of items along a row or column. Add flex to the parent, then choose its direction, alignment, wrapping, and spacing.

Start a flex layout

flex sets display: flex. Direct children become flex items. The default direction is a row.

One
Two
Three
HTML
<div class="flex gap-16">
  <div class="docs-demo-item">One</div>
  <div class="docs-demo-item">Two</div>
  <div class="docs-demo-item">Three</div>
</div>

Direction

ClassEffect
flex-rowPlace items in a row.
flex-colPlace items in a column.
flex-col-reverseReverse the visual order in a column. DOM and keyboard order stay unchanged.
One
Two
Three
HTML
<div class="flex flex-col gap-12">
  <div class="docs-demo-item">One</div>
  <div class="docs-demo-item">Two</div>
  <div class="docs-demo-item">Three</div>
</div>

Responsive direction

Start with flex-col, then use a breakpoint-prefixed row class. Resize this example: it becomes a row at 820 pixels.

Stacked on small screens
Side by side from md
HTML
<div class="flex flex-col md-flex-row gap-16">
  <div class="docs-demo-item">Stacked on small screens</div>
  <div class="docs-demo-item">Side by side from md</div>
</div>
Row classMinimum viewport width
xs-flex-row0 px
sm-flex-row480 px
md-flex-row820 px
lg-flex-row960 px
xl-flex-row1200 px

These prefixes change direction, not display. Keep flex on the parent. The current stylesheet does not generate responsive display classes such as md-flex, or an inline-flex utility.

Alignment

Justification distributes items along the main axis. Item alignment positions them along the cross axis; those axes change when the direction is a column.

Brand Navigation
HTML
<div class="flex justify-between items-center gap-16">
  <span class="docs-demo-item">Brand</span>
  <span class="docs-demo-item">Navigation</span>
</div>
Utility familyAvailable values
Justify contentjustify-start, justify-end, justify-center, justify-between, justify-around, justify-evenly
Align itemsitems-start, items-end, items-center
Align multiple linescontent-start, content-end, content-center, content-between, content-around

The content-* utilities need wrapped lines and spare cross-axis space to have a visible effect. Additional alignment and responsive variants are not assumed by these examples.

Wrapping and item size

flex-wrap allows items to move onto another line. flex-basis-300 sets flex: 0 0 300px: it fixes the basis at 300 pixels and disables growing and shrinking. Use it where that fixed item width fits your layout.

First item
Another item
One more item
Items wrap as space runs out
HTML
<div class="flex flex-wrap gap-16">
  <div class="docs-demo-item">First item</div>
  <div class="docs-demo-item">Another item</div>
  <div class="docs-demo-item">One more item</div>
  <div class="docs-demo-item">Items wrap as space runs out</div>
</div>

Spacing

Use gap-16 for one rem between items, or another key from the shared spacer scale. Gap utilities work with both Flexbox and Grid. They do not add space around the outside of the parent.