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.
<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>
Enable flex from medium screens
flex-md sets display: flex at the medium breakpoint and above. Its minimum width comes from the md entry in the Sass breakpoint map, currently 820 pixels. Below that width it leaves the element's display unchanged, so ordinary block children stack naturally. Use it on the parent without flex when you want flex layout to begin at medium.
Share available space with flex-1
Add flex-1 to direct children of a flex container. It sets flex: 1, allowing those items to grow and shrink from a zero basis and share available space equally, subject to their minimum content sizes. It does not enable flex on the parent.
Combine the two utilities for a mobile-first two-column layout. Resize this example: the block elements stack below medium and share a row from 820 pixels.
<div class="flex-md gap-24">
<div class="flex-1 docs-demo-item">First column</div>
<div class="flex-1 docs-demo-item">Second column</div>
</div>
Direction
| Class | Effect |
|---|---|
flex-row | Place items in a row. |
flex-col | Place items in a column. |
flex-col-reverse | Reverse the visual order in a column. DOM and keyboard order stay unchanged. |
<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 property-first row class with the breakpoint between flex and row. Resize this example: it becomes a row at 820 pixels.
<div class="flex flex-col flex-md-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 class | Minimum viewport width |
|---|---|
flex-xs-row | 0 px |
flex-sm-row | 480 px |
flex-md-row | 820 px |
flex-lg-row | 960 px |
flex-xl-row | 1200 px |
These responsive row classes change direction, not display. Keep flex on the parent for an always-active flex layout. To enable flex only from medium, use flex-md instead. The names distinguish the two behaviors: flex-md-row changes direction, while flex-md enables display. The current stylesheet does not generate md-flex or inline-flex utilities.
Responsive ordering
flex-lg enables display: flex from the large breakpoint, 960 pixels, leaving display unchanged below it.
order-lg-last sets order: 1 from 960 pixels. Apply it to a direct flex or grid child to place it after siblings with the default order. Below large, HTML order applies. The image-right card keeps its image first in the HTML, then moves its image link wrapper last when flex-lg enables the horizontal layout. Visual ordering leaves reading and keyboard navigation order unchanged.
Alignment
Bottom spacing while stacked
Use mb-24 mb-lg-0 on an image wrapper to separate it from the copy below. The base margin is 1.5rem; from 960 pixels the margin resets to zero and the horizontal gap supplies the spacing.
<div class="flex-lg gap-24">
<div class="docs-demo-item flex-1 mb-24 mb-lg-0">Image area</div>
<div class="docs-demo-item flex-1">Card copy</div>
</div>
Justification distributes items along the main axis. Item alignment positions them along the cross axis; those axes change when the direction is a column.
<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 family | Available values |
|---|---|
| Justify content | justify-start, justify-end, justify-center, justify-between, justify-around, justify-evenly |
| Align items | items-start, items-end, items-center |
| Align multiple lines | content-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.
flex-basis-100 sets flex: 0 0 100%, with min-width: 0 and border-box sizing. All three panels in the slider example use it to fill one track width without shrinking. The 300-pixel helper remains supported and documented, but currently has no first-party template usages.
<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.