DD
DevDash

Last updated: April 12, 2026

CSS Flexbox Cheatsheet

Quick Answer

Flexbox is a 1D layout system for rows or columns. Set display: flex on the container, then use justify-content for main-axis alignment and align-items for cross-axis alignment. This covers 90% of flexbox use cases.

Container

CommandDescription
display: flex

Create a flex container (block-level)

display: inline-flex

Create an inline flex container

flex-direction: row

Main axis is horizontal, left to right (default)

flex-direction: column

Main axis is vertical, top to bottom

flex-direction: row-reverse

Main axis is horizontal, right to left

flex-wrap: wrap

Allow items to wrap to the next line

flex-wrap: nowrap

All items on one line (default, may overflow)

justify-content: flex-start

Pack items at the start of the main axis (default)

justify-content: center

Center items along the main axis

justify-content: space-between

Equal space between items, no space at edges

justify-content: space-around

Equal space around each item

justify-content: space-evenly

Equal space between and around items

align-items: stretch

Stretch items to fill the cross axis (default)

align-items: center

Center items on the cross axis

align-items: flex-start

Align items at the start of the cross axis

gap: 1rem

Set space between flex items (row and column)

gap: 16px or gap: 1rem 2rem

Items

CommandDescription
flex-grow: 1

Allow item to grow to fill available space

flex-shrink: 0

Prevent item from shrinking below its base size

flex-basis: 200px

Set initial size before growing/shrinking

align-self: center

Override align-items for a single item

Frequently Asked Questions

More Cheatsheets

Want API access + no ads? Pro coming soon.