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
| Command | Description |
|---|---|
| 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
| Command | Description |
|---|---|
| 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
Git Commands Cheatsheet
This cheatsheet covers the 40 most essential Git commands grouped by workflow: setup, staging, branc...
Docker Commands Cheatsheet
This cheatsheet covers 35 essential Docker commands for managing containers, images, volumes, and ne...
Linux Commands Cheatsheet
This cheatsheet covers 40 essential Linux/Unix commands for daily development: file navigation, text...
HTTP Status Codes Cheatsheet
HTTP status codes are 3-digit numbers returned by servers. 1xx = informational, 2xx = success, 3xx =...