Flex Properties

justify, align, wrap, grow, basis — the Full Toolkit

Flex Properties

Beyond direction and gap, flex has properties for alignment, wrapping, and item sizing.

6 min read Level 2/5 #css#flexbox#alignment
What you'll learn
  • Align with `justify-content` and `align-items`
  • Let items grow / shrink
  • Wrap a row to multiple lines

Now the rest of flexbox. These properties live on the container unless otherwise noted.

Alignment Along the Main Axis — justify-content

The “main axis” is the direction of the flex. For a row, it’s horizontal.

ValueWhat it does
flex-startPack at the start (default)
flex-endPack at the end
centerCentered
space-betweenEqual space BETWEEN items, none at the edges
space-aroundEqual space around each item
space-evenlyEqual space EVERYWHERE (including edges)
.nav {
  display: flex;
  justify-content: space-between;
}

A logo on the left, links on the right — classic header pattern.

Alignment Along the Cross Axis — align-items

The cross axis is perpendicular to the main axis. For a row, it’s vertical.

ValueWhat it does
stretchItems fill the cross axis (default)
flex-startTop (or start)
flex-endBottom (or end)
centerCentered
baselineAlign by text baselines

Centering Anything

The flex-centering one-liner:

.center {
  display: flex;
  justify-content: center;
  align-items: center;
}

For a full-page hero:

.hero {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
}

Wrapping

By default, flex items don’t wrap — they shrink to fit. To wrap:

.gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}
.gallery > * {
  flex: 1 1 200px;   /* grow, shrink, basis 200px */
}

Items wrap to a new line when there’s no room. The flex: 1 1 200px shorthand means “grow to fill, shrink if needed, base size 200px”.

Item Sizing

Per item (these go on the FLEX ITEM, not the container):

PropertyWhat
flex-growHow much to grow when there’s extra space (default 0)
flex-shrinkHow much to shrink when overflowing (default 1)
flex-basisThe starting size before grow/shrink
flexShorthand: <grow> <shrink> <basis>
.sidebar { flex: 0 0 250px; }   /* fixed 250px, no grow, no shrink */
.main    { flex: 1; }            /* take all remaining space */

Classic “sidebar + main” layout.

Aligning One Item

align-self overrides align-items for one item:

.special { align-self: center; }

Order

Reorder items visually without changing the HTML:

.first  { order: -1; }   /* before everything */
.last   { order: 99; }

Use sparingly — visual and source order diverging breaks keyboard / screen-reader navigation.

Up Next

Grid — the two-dimensional cousin.

Grid Intro →