core-logo

Flex

Quickly manage the layout, alignment, and sizing of grid columns, navigation, components, and more with a full suite of responsive flexbox utilities. For more complex implementations, custom CSS may be necessary.

On this page:



Enable flex behaviors

Apply display utilities to create a flexbox container and transform direct children elements into flex items. Flex containers and items are able to be modified further with additional flex properties.

I'm a flexbox container!
<div class="c-d-flex c-p-2 bd-highlight">I'm a flexbox container!</div>
I'm an inline flexbox container!
<div class="c-d-inline-flex c-p-2 bd-highlight">I'm an inline flexbox container!</div>

Responsive variations also exist for .c-d-flex and .c-d-inline-flex.

Direction

Set the direction of flex items in a flex container with direction utilities. In most cases you can omit the horizontal class here as the browser default is row. However, you may encounter situations where you needed to explicitly set this value (like responsive layouts).

Use .c-flex-row to set a horizontal direction (the browser default), or .c-flex-row-reverse to start the horizontal direction from the opposite side.

Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
<div class="c-d-flex c-flex-row bd-highlight c-mb-3">
  <div class="c-p-2 bd-highlight">Flex item 1</div>
  <div class="c-p-2 bd-highlight">Flex item 2</div>
  <div class="c-p-2 bd-highlight">Flex item 3</div>
</div>
<div class="c-d-flex c-flex-row-reverse bd-highlight">
  <div class="c-p-2 bd-highlight">Flex item 1</div>
  <div class="c-p-2 bd-highlight">Flex item 2</div>
  <div class="c-p-2 bd-highlight">Flex item 3</div>
</div>

Use .c-flex-column to set a vertical direction, or .c-flex-column-reverse to start the vertical direction from the opposite side.

Flex item 1
Flex item 2
Flex item 3
Flex item 1
Flex item 2
Flex item 3
<div class="c-d-flex c-flex-column bd-highlight c-mb-3">
  <div class="c-p-2 bd-highlight">Flex item 1</div>
  <div class="c-p-2 bd-highlight">Flex item 2</div>
  <div class="c-p-2 bd-highlight">Flex item 3</div>
</div>
<div class="c-d-flex c-flex-column-reverse bd-highlight">
  <div class="c-p-2 bd-highlight">Flex item 1</div>
  <div class="c-p-2 bd-highlight">Flex item 2</div>
  <div class="c-p-2 bd-highlight">Flex item 3</div>
</div>

Responsive variations also exist for flex-direction.

Justify content

Use c-justify-content utilities on flexbox containers to change the alignment of flex items on the main axis (the x-axis to start, y-axis if flex-direction: column). Choose from start (browser default), end, center, between, or around.

Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-justify-content-start">...</div>
<div class="c-d-flex c-justify-content-end">...</div>
<div class="c-d-flex c-justify-content-center">...</div>
<div class="c-d-flex c-justify-content-between">...</div>
<div class="c-d-flex c-justify-content-around">...</div>

Responsive variations also exist for c-justify-content.

Align items

Use c-align-items utilities on flexbox containers to change the alignment of flex items on the cross axis (the y-axis to start, x-axis if flex-direction: column). Choose from start, end, center, baseline, or stretch (browser 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
Flex item
Flex item
Flex item
<div class="c-d-flex c-align-items-start">...</div>
<div class="c-d-flex c-align-items-end">...</div>
<div class="c-d-flex c-align-items-center">...</div>
<div class="c-d-flex c-align-items-baseline">...</div>
<div class="c-d-flex c-align-items-stretch">...</div>

Responsive variations also exist for c-align-items.

Align self

Use c-align-self utilities on flexbox items to individually change their alignment on the cross axis (the y-axis to start, x-axis if flex-direction: column). Choose from the same options as c-align-items: start, end, center, baseline, or stretch (browser default).

Flex item
Aligned flex item
Flex item
Flex item
Aligned flex item
Flex item
Flex item
Aligned flex item
Flex item
Flex item
Aligned flex item
Flex item
Flex item
Aligned flex item
Flex item
<div class="c-align-self-start">Aligned flex item</div>
<div class="c-align-self-end">Aligned flex item</div>
<div class="c-align-self-center">Aligned flex item</div>
<div class="c-align-self-baseline">Aligned flex item</div>
<div class="c-align-self-stretch">Aligned flex item</div>

Responsive variations also exist for c-align-self.

Fill

Use the .c-flex-fill class on a series of sibling elements to force them into widths equal to their content (or equal widths if their content does not surpass their border-boxes) while taking up all available horizontal space.

Flex item with a lot of content
Flex item
Flex item
<div class="c-d-flex bd-highlight">
  <div class="c-p-2 c-flex-fill bd-highlight">Flex item with a lot of content</div>
  <div class="c-p-2 c-flex-fill bd-highlight">Flex item</div>
  <div class="c-p-2 c-flex-fill bd-highlight">Flex item</div>
</div>

Responsive variations also exist for c-flex-fill.

Grow and shrink

Use .c-flex-grow-* utilities to toggle a flex item’s ability to grow to fill available space. In the example below, the .c-flex-grow-1 elements uses all available space it can, while allowing the remaining two flex items their necessary space.

Flex item
Flex item
Third flex item
<div class="c-d-flex bd-highlight">
  <div class="c-p-2 c-flex-grow-1 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Third flex item</div>
</div>

Use .c-flex-shrink-* utilities to toggle a flex item’s ability to shrink if necessary. In the example below, the second flex item with .c-flex-shrink-1 is forced to wrap it’s contents to a new line, “shrinking” to allow more space for the previous flex item with .c-w-100.

Flex item
Flex item
<div class="c-d-flex bd-highlight">
  <div class="c-p-2 c-w-100 bd-highlight">Flex item</div>
  <div class="c-p-2 c-flex-shrink-1 bd-highlight">Flex item</div>
</div>

Responsive variations also exist for c-flex-grow and c-flex-shrink.

Auto margins

Flexbox can do some pretty awesome things when you mix flex alignments with auto margins. Shown below are three examples of controlling flex items via auto margins: default (no auto margin), pushing two items to the right (.c-mr-auto), and pushing two items to the left (.c-ml-auto).

Unfortunately, IE10 and IE11 do not properly support auto margins on flex items whose parent has a non-default c-justify-content value. See this StackOverflow answer for more details.

Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex bd-highlight c-mb-3">
  <div class="c-p-2 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Flex item</div>
</div>

<div class="c-d-flex bd-highlight c-mb-3">
  <div class="c-mr-auto c-p-2 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Flex item</div>
</div>

<div class="c-d-flex bd-highlight c-mb-3">
  <div class="c-p-2 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Flex item</div>
  <div class="c-ml-auto c-p-2 bd-highlight">Flex item</div>
</div>

With align-items

Vertically move one flex item to the top or bottom of a container by mixing c-align-items, flex-direction: column, and margin-top: auto or margin-bottom: auto.

Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-align-items-start c-flex-column bd-highlight c-mb-3" style="height: 200px;">
  <div class="c-mb-auto c-p-2 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Flex item</div>
</div>

<div class="c-d-flex c-align-items-end c-flex-column bd-highlight c-mb-3" style="height: 200px;">
  <div class="c-p-2 bd-highlight">Flex item</div>
  <div class="c-p-2 bd-highlight">Flex item</div>
  <div class="c-mt-auto c-p-2 bd-highlight">Flex item</div>
</div>

Wrap

Change how flex items wrap in a flex container. Choose from no wrapping at all (the browser default) with .c-flex-nowrap, wrapping with .c-flex-wrap, or reverse wrapping with .c-flex-wrap-reverse.

Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-flex-nowrap">
  ...
</div>
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-flex-wrap">
  ...
</div>
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-flex-wrap-reverse">
  ...
</div>

Responsive variations also exist for c-flex-wrap.

Order

Change the visual order of specific flex items with a handful of order utilities. We only provide options for making an item first or last, as well as a reset to use the DOM order. As order takes any integer value (e.g., 5), add custom CSS for any additional values needed.

First flex item
Second flex item
Third flex item
<div class="c-d-flex c-flex-nowrap bd-highlight">
  <div class="c-order-3 c-p-2 bd-highlight">First flex item</div>
  <div class="c-order-2 c-p-2 bd-highlight">Second flex item</div>
  <div class="c-order-1 c-p-2 bd-highlight">Third flex item</div>
</div>

Responsive variations also exist for c-order.

Align content

Use c-align-content utilities on flexbox containers to align flex items together on the cross axis. Choose from start (browser default), end, center, between, around, or stretch. To demonstrate these utilities, we’ve enforced flex-wrap: wrap and increased the number of flex items.

Heads up! This property has no effect on single rows of flex items.

Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-align-content-start c-flex-wrap">
  ...
</div>
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-align-content-end c-flex-wrap">...</div>
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-align-content-center c-flex-wrap">...</div>
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-align-content-between c-flex-wrap">...</div>
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-align-content-around c-flex-wrap">...</div>
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
Flex item
<div class="c-d-flex c-align-content-stretch c-flex-wrap">...</div>

Responsive variations also exist for c-align-content.