Skip to content

Flexbox — One-Dimensional Layout

If you have used Auto Layout in Figma, you already understand Flexbox. They work on exactly the same idea: a parent container controls how its children are arranged along one axis. You set rules on the parent, and the children obey.

The only difference is the syntax. Let us map what you already know to what CSS calls it.

Figma Auto Layout settingCSS Flexbox property
Direction: Horizontalflex-direction: row (default)
Direction: Verticalflex-direction: column
Alignment: Left/Topjustify-content: flex-start
Alignment: Centerjustify-content: center
Alignment: Right/Bottomjustify-content: flex-end
Alignment: Space betweenjustify-content: space-between
Cross-axis alignment: Centeralign-items: center
Gap (spacing between items)gap: 1rem
Wrap itemsflex-wrap: wrap

display: flex — This activates Flexbox on the parent. Nothing else changes until you add this one line.

flex-direction — Which way do the children flow?

  • row — left to right (the default)
  • column — top to bottom

justify-content — How are children distributed along the main axis (the direction they flow)?

  • flex-start / flex-end / center / space-between / space-around / space-evenly

align-items — How are children aligned on the cross axis (perpendicular to the flow)?

  • flex-start / flex-end / center / stretch

gap — Consistent spacing between items. No more margin hacks. This is the same as the gap value in Figma Auto Layout.

flex-wrap — Should items wrap to the next line when there is not enough space?

  • nowrap (default, items shrink to fit) / wrap (items wrap to a new row)

Below is a navigation bar with three links. Try changing the properties in the CSS panel to see how Flexbox responds.

Things to try:

  • Change .cards justify-content to center or space-between
  • Change .cards flex-direction to column
  • Add align-items: center to .nav (it already has it — try removing it)
  • Change the .cards gap to 0.25rem or 3rem
Which CSS property is the direct equivalent of Figma Auto Layout gap?
You want items in a flex container to be centered vertically. Which property do you use?
What does flex-wrap: wrap do?
To distribute three items with equal space between them (but not outside), you use: