CSS Flexbox playground
This is a hands-on flexbox playground that generates ready-to-paste display: flex rules. It is for developers learning flexbox or fine-tuning a row or column of items — navbars, button groups, card rows, centred hero content. Change a property, watch the preview rearrange, and copy the exact CSS.
How it works
The playground sets five container properties and writes them out as a display: flex block. flex-direction chooses the main axis (row or column, optionally reversed). justify-content positions items along that main axis; align-items positions them along the cross axis — so swapping the direction swaps which control does what. flex-wrap decides whether items stay on one line or flow onto new lines, and gap sets the spacing between items. The preview is a live flex container using the same values, with the item count adjustable so you can test crowding and wrapping.
Common layout recipes
Navbar (items pushed to edges, vertically centred):
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
gap: 16px;
Perfect centre (single item in the middle of a container):
display: flex;
justify-content: center;
align-items: center;
This pattern works for centring a modal, a hero badge, or an icon inside a button — combine with a minimum height on the container.
Card row that wraps on smaller screens:
display: flex;
flex-direction: row;
flex-wrap: wrap;
gap: 1rem;
Child cards get a flex: 1 1 280px to set a minimum width before wrapping; the flex container then distributes remaining space among those on each line.
Vertical sidebar menu:
display: flex;
flex-direction: column;
gap: 4px;
align-items: flex-start;
justify-content values at a glance
| justify-content | End gaps | Gaps between items |
|---|---|---|
| flex-start | items packed at start | none |
| center | items packed at centre | none |
| flex-end | items packed at end | none |
| space-between | none | equal |
| space-around | half-size | equal (double between) |
| space-evenly | equal | equal |
When to reach for flexbox vs grid
Use flexbox when you have a single row or column of items and want the items themselves to determine the distribution. It excels at navigation bars, button groups, form rows, and any layout where one axis is the natural primary axis.
Use CSS grid when you need precise control over both rows and columns simultaneously — product grids, page templates, dashboards where cells must align across rows and columns. Grid also makes it straightforward to place items into specific named areas.
The two can nest: a grid layout can contain flex rows inside its cells, and a flex container can hold a grid child.
Everything runs in your browser — nothing is uploaded.