CSS Flexbox Generator
Learn and build flexbox layouts: change each property and see the boxes move instantly.
How to use the Flexbox Generator
- Set the directionChoose row or column, and whether items wrap onto new lines.
- Align the itemsUse justify-content for the main direction and align-items for the cross direction, and watch the boxes move.
- Copy the CSSOnly properties that differ from the defaults are included, so the code stays short.
Example
Center anything: display: flex; justify-content: center; align-items: center;
Navigation bar: justify-content: space-between; align-items: center; gap: 12px; puts the logo left and links right.
Frequently asked questions
What is the difference between justify-content and align-items?
justify-content positions items along the main direction (left to right in a row), and align-items positions them across it (top to bottom in a row). In a column they swap.
When does align-content do anything?
Only when items wrap onto more than one line. It controls the spacing between those lines.
What does flex: 1 do?
It lets each item grow to share the leftover space equally, so the items fill the whole row.