This is a preview, you can find the current version here.
Last updated: 12/5/2025

Flex

Stacks provides extensive utility and helper classes for flex layouts. If you are new to flex layouts, check out this interactive introduction by Joshua Comeau.

Stacks provides extensive utility and helper classes for flex layouts. If you are new to flex layouts, check out this interactive introduction by Joshua Comeau.

Basic flex layout

A flex layout is initiated with the .d-flex class. By default, display: flex; starts a non-wrapping row. To convert it to a column, apply the .fd-column atomic class.

<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex fd-column">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.flex--item
.flex--item
.flex--item
.flex--item

Fluid

By default, all flex items will only be as wide as their content. If you would like a flex item or all the flex items to fill the remaining space, apply the .fl-grow1 to the individual item, or .flex__fl-equal to the parent to apply to all children.

Fluid examples

<div class="d-flex">
    <div class="flex--item fl-grow1"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex flex__fl-equal">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.flex--item.fl-grow1
.flex--item
.flex--item
.flex--item
.flex--item

Fixed cells

You can either fix the width of an individual element or fix the width of all child elements within a parent container by setting the width on the parent. The cell widths are based on a 12-column flex layout system.

Fixed classes

Individual WidthUniform WidthOutput
.flex--item1.flex__allitems1flex-basis: 8.333333333%;
.flex--item2.flex__allitems2flex-basis: 16.666666667%;
.flex--item3.flex__allitems3flex-basis: 24.999999999%;
.flex--item4.flex__allitems4flex-basis: 33.333333332%;
.flex--item5.flex__allitems5flex-basis: 41.666666665%;
.flex--item6.flex__allitems6flex-basis: 50%;
.flex--item7.flex__allitems7flex-basis: 58.333333331%;
.flex--item8.flex__allitems8flex-basis: 66.666666664%;
.flex--item9.flex__allitems9flex-basis: 74.999999997%;
.flex--item10.flex__allitems10flex-basis: 83.33333333%;
.flex--item11.flex__allitems11flex-basis: 91.666666663%;
.flex--item12.flex__allitems12flex-basis: 100%;

Fixed examples

<div class="d-flex">
    <div class="flex--item2"></div>
    <div class="flex--item10"></div>
</div>
<div class="d-flex">
    <div class="flex--item3"></div>
    <div class="flex--item6"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex flex__allitems4">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.flex--item[x]
.flex--item2
.flex--item10
.flex--item[x] and standard .flex--item
.flex--item3
.flex--item6
.flex--item
.d-flex.flex__allitems4
.flex--item
.flex--item
.flex--item
.flex--item

Helpers

We have a few helper classes you can add to a .d-flex container that affect the child .flex—items.

Helper classes

ClassDefinitionResponsive?
.flex__centerCenters child elements along a parent's main and cross axis.
.flex__fl-shrink0Disables shrinking from all child elements
.flex__fl-equalMakes each child element grow equally

Helpers examples

<div class="d-flex flex__center">
    <div class="flex--item"></div>
</div>
<div class="d-flex flex__fl-shrink0">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex flex__fl-equal">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.flex__center
.flex--item
.flex__fl-shrink0
.flex--item
.flex--item
.flex--item
.flex__fl-equal
.flex--item
.flex--item
.flex--item

Nested flex layouts

Flex layouts can be nested within each other. This allows you to create unique, custom layouts without needing to create new, custom code or override existing styles.

Nested examples

<div class="d-flex">
    <div class="d-flex">
        <div class="flex--item"></div>
        <div class="flex--item"></div>
    </div>
    <div class="flex--item2"></div>
    <div class="flex--item2"></div>
</div>
.flex--item
.flex--item
.flex--item2
.flex--item2

Gutters

Deprecation: gutters will be removed in a future release.
Please use gap classes to set spacing on flex items.

Sometimes gutters are desired between cells. To do so apply the appropriate class to the parent wrapper. The gutter applies a margin to all sides. The sizes available are the same as the spacing units.

Gutter classes

ClassOutput
.gs22px
.gs44px
.gs66px
.gs88px
.gs1212px
.gs1616px
.gs2424px
.gs3232px
.gs4848px
.gs6464px
.gsxApplies margins only to left and right
.gsyApplies margins only to top and bottom

Gutter examples

<div class="d-flex flex__fl-equal gs16">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex flex__fl-equal gs16 gsx">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex flex__fl-equal gs16 gsy">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.gs16
.gs16
.gs16
.gs16
.gs16.gsx -- Row gutters only
.gs16.gsx -- Row gutters only
.gs16.gsx -- Row gutters only
.gs16.gsx -- Row gutters only
.gs16.gsy -- Column gutters only
.gs16.gsy -- Column gutters only
.gs16.gsy -- Column gutters only
.gs16.gsy -- Column gutters only

Nested gutters

Note: Nested flex layouts with gutter spacing will conflict with each other in unpredictable ways. TL;DR? Don't stick a .d-flex directly into a .d-flex, instead stick a .d-flex into a .flex--item like so:

If you are nesting a flex layout with gutter spacing into another flex layout that also has gutter spacing, the child’s parent wrapper margins will be overwritten by the parent. To have the child flex layout’s gutter spacing honored, you have to put the child flex layout within a .flex—item wrapper first. This allows the parent and child flex layout gutter spacing to act correctly without interfering with each other.

Do

<div class="d-flex gs32">
    <div class="flex--item"></div>
    <div class="flex--item">
        <div class="d-flex gs16">
            <div class="flex--item"></div>
            <div class="flex--item"></div>
        </div>
    </div>
</div>
.flex--item
.flex--item
.flex--item

Don’t

<div class="d-flex gs32">
    <div class="flex--item"></div>
    <div class="d-flex gs16">
        <div class="flex--item"></div>
        <div class="flex--item"></div>
    </div>
</div>
.flex--item
.flex--item
.flex--item

Flex direction

On a flex container, you can set the direction of the child items.

Flex direction classes

ClassDefinitionResponsive?
.fd-rowSets the flex direction to a row.
.fd-row-reverseReverses the row flex direction.
.fd-columnSets the flex direction to a column.
.fd-column-reverseReverses the column flex direction.

Flex direction examples

<div class="d-flex fd-row">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex fd-row-reverse">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex fd-column">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex fd-column-reverse">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.fd-row
Default
.flex--item 1
.flex--item 2
.flex--item 3
.fd-row-reverse
.flex--item 1
.flex--item 2
.flex--item 3
.fd-column
.flex--item 1
.flex--item 2
.flex--item 3
.fd-column-reverse
.flex--item 1
.flex--item 2
.flex--item 3

Flex wrap

On a flex container, you can control if the children wrap.

Flex wrap classes

ClassDefinitionResponsive?
.fw-wrapWraps the child cells within a parent.
.fw-reverseReverses the wrap direction.
.fw-nowrapRemoves the wrap direction.

Flex wrap examples

<div class="d-flex fw-wrap">
    <div class="flex--item"></div></div>
<div class="d-flex fw-wrap-reverse">
    <div class="flex--item"></div></div>
<div class="d-flex fw-nowrap">
    <div class="flex--item"></div></div>
.fw-wrap
.flex--item 1
.flex--item 2
.flex--item 3
.flex--item 4
.flex--item 5
.flex--item 6
.flex--item 7
.flex--item 8
.fw-reverse
.flex--item 1
.flex--item 2
.flex--item 3
.flex--item 4
.flex--item 5
.flex--item 6
.flex--item 7
.flex--item 8
.fw-nowrap
Default
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item

Justify content

Flex items can be controlled with atomic classes on the container’s main axis. This means controlling how a .flex—item is aligned left to right when in an .fd-row, and top and bottom in an .fd-column.

Justify content classes

ClassDefinitionResponsive?
.jc-centerCenters child elements along the parent's main axis.
.jc-endAligns child elements at the end of the parent's main axis.
.jc-space-aroundEqually distributes the remaining space around child elements. Note that this doesn't mean the spaces are visually equal, but that the same space unit is applied to both sides of a child element. The first item would have one unit of space against the container edge, but the next item would have two units of space between itself and the first item.
.jc-space-betweenEvenly distributes the space between child elements along a parent's main axis with the first item starting on the start line and the last item on the end line.
.jc-space-evenlyThe spacing between any two items (and spacing between the edges) are equal.
.jc-startAligns child elements at the start of the parent's main axis.

Justify content examples

<div class="d-flex jc-center">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex jc-end">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex jc-space-around">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex jc-space-between">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex jc-space-evenly">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex jc-start">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.jc-center
.flex--item
.flex--item
.flex--item
.jc-end
.flex--item
.flex--item
.flex--item
.jc-space-around
.flex--item
.flex--item
.flex--item
.jc-space-between
.flex--item
.flex--item
.flex--item
.jc-space-evenly
.flex--item
.flex--item
.flex--item
.jc-start
Default
.flex--item
.flex--item
.flex--item

Align items

Flex items can be controlled with atomic classes on the container’s cross axis. This means controlling how a .flex—item is aligned top to bottom when in an .fd-row, and left to right in an .fd-column.

Align items classes

ClassDefinitionResponsive?
.ai-baselineAligns child elements along the baseline of a parent's cross axis.
.ai-centerCenters child elements along the parent's cross axis.
.ai-endPlaces child elements at the end of the parent's cross axis.
.ai-startPlaces child elements at the start of the parent's cross axis.
.ai-stretchStretches child elements along the parent's cross axis.

Align items examples

<div class="d-flex ai-baseline">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex ai-center">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex ai-end">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex ai-start">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex ai-stretch">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.ai-baseline
.flex--item
.flex--item
.flex--item
.ai-center
.flex--item
.flex--item
.flex--item
.ai-end
.flex--item
.flex--item
.flex--item
.ai-start
.flex--item
.flex--item
.flex--item
.ai-stretch
Default
.flex--item
.flex--item
.flex--item

Align content

Flex items can be controlled with atomic classes on the container’s cross axis.

Align content classes

ClassDefinitionResponsive?
.ac-centerDistributes child elements starting from the center along a parent's cross axis. This only works with more than one line.
.ac-endDistributes child elements starting from the end along a parent's cross axis. This only works with more than one line.
.ac-space-aroundDistributes child elements with space around along a parent's cross axis. This only works with more than one line.
.ac-space-betweenDistributes child elements with space between along a parent's cross axis. This only works with more than one line.
.ac-startDistributes child elements starting from the start along a parent's cross axis. This only works with more than one line.
.ac-stretchDistributes child elements stretching them along a parent's cross axis. This only works with more than one line.

Align content examples

<div class="d-flex ac-center">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex ac-end">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex ac-space-around">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex ac-space-between">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex ac-start">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex ac-stretch">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.ac-center
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.ac-end
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.ac-space-around
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.ac-space-between
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.ac-start
Default
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item
.flex--item

Align self

A flex container’s align-items can be overridden on individual items within a flex layout.

Align self classes

ClassDefinitionResponsive?
.as-autoAuto re-aligns a child element along the parent's main axis based on the ai-[x] value.
.as-baselineRe-aligns a child element along the baseline of the parent's main axis.
.as-centerCenters a child element along the parent's main axis.
.as-endRe-aligns a child element to the end of the parent's main axis.
.as-startRe-aligns a child element to the start of the parent's main axis.
.as-stretchStretches a child element along the parent's main axis.

Align self examples

<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item as-auto"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item as-baseline"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item as-center"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item as-end"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item as-start"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item as-stretch"></div>
    <div class="flex--item"></div>
</div>
.as-auto
Default
.flex--item
.flex--item
.flex--item
.as-baseline
.flex--item
.flex--item
.flex--item
.as-center
.flex--item
.flex--item
.flex--item
.as-end
.flex--item
.flex--item
.flex--item
.as-start
.flex--item
.flex--item
.flex--item
.as-stretch
.flex--item
.flex--item
.flex--item

Order

Within a flex layout, you can force the position of individual elements.

Order classes

ClassDefinitionResponsive?
.order-firstPlaces the child element first within a parent container.
.order-lastPlaces the child element last within a parent container.

Order examples

<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item"></div>
    <div class="flex--item order-first"></div>
</div>
<div class="d-flex">
    <div class="flex--item order-last"></div>
    <div class="flex--item"></div>
    <div class="flex--item"></div>
</div>
.order-first
.flex--item 1
.flex--item 2
.flex--item 3
.order-last
.flex--item 1
.flex--item 2
.flex--item 3

Flex shrink and grow

You can control the growing and shrinking behavior of individual elements within a flex layout.

Flex classes

ClassDefinitionResponsive?
.fl-grow1Sets flex-grow to allow a flex item to grow to fill any available space.
.fl-grow0Prevents a flex item from growing.
.fl-shrink1Allows a flex item to shrink if needed.
.fl-shrink0Prevents a flex item from shrinking.
.fl-nonePrevents a flex item from growing or shrinking.
.fl-initialAllows a flex item to shrink but not grow, taking into account its initial size.
.fl-autoAllows a flex item to grow and shrink, taking into account its initial size.
.fl-equalAllow a flex item to grow and shrink as needed, ignoring its initial size. If all children within a flex layout have ..fl-equal enabled, they'll be the same size. See also .flex__fl-equal

Flex examples

<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item fl-grow1"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item fl-grow0"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item fl-shrink1"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item fl-shrink0"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item fl-none"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item fl-initial"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item"></div>
    <div class="flex--item fl-auto"></div>
    <div class="flex--item"></div>
</div>
<div class="d-flex">
    <div class="flex--item fl-equal"></div>
    <div class="flex--item fl-equal"></div>
    <div class="flex--item fl-equal"></div>
</div>
.fl-grow1
.flex--item
.flex--item
.flex--item
.fl-grow0
.flex--item
.flex--item
.flex--item
.fl-shrink1
.flex--item
.flex--
item
.flex--item
.fl-shrink0
.flex--item
.flex--item
.flex--item
.fl-none
.flex--item
.flex--item
.flex--item
.fl-initial
.flex--item
.flex--item
.flex--item
.fl-auto
.flex--item
.flex--item.ws2
.flex--item
.fl-equal
.flex--item
.flex--item
.flex--item
Edit on GitHub