CSS Tool
CSS Flexbox & Grid Playground
A live layout studio for the two CSS models that actually place things on a page. Switch Flexbox or Grid, drag the real properties, click an item to grow or span it, and copy clean HTML and CSS — not a screenshot of a tutorial.
- Flex + Grid
- Live preview
- Per-item spans
- 12 presets
- Copy CSS
- Shareable
Controls
Mode
Use Flexbox when the layout is one-dimensional.
Presets
Container
Flexbox
display
flex-direction
flex-wrap
Only applies when the items wrap onto extra lines.
Grid
display
Column tracks
Selected item
Click a box in the preview to edit grow, span, order or size for that item only.
Playground
Click an item to inspect itCode
Layouts are built in your browser. Nothing is uploaded. A share link encodes the state in the address bar, and autosave stays on this device.
Flexbox and Grid are different jobs
Most “CSS playgrounds” treat Flexbox as a toy: a row of boxes and a justify dropdown. Real layout work is deciding which model owns the page, then using the other inside it. This studio keeps both in one place so you can feel the difference instead of reading another comparison table.
Flexbox is one-dimensional. The container picks a main axis — row or column —
and justify-content distributes leftover space along that axis.
align-items works on the other axis. Wrapping is opt-in. That is why it is the
right tool for a navbar, a chip row, or a sidebar beside a stretching main column.
Grid is two-dimensional. You declare tracks, then place items on them —
including items that occupy several cells. fr shares leftover space after fixed
tracks are laid out. Named areas let you draw a page shell in a string rather than counting
line numbers. That is why it is the right tool for a dashboard or a holy-grail page.
Property cheat sheet
| Property | Model | What it actually does |
|---|---|---|
display: flex | Flex | Children become flex items on one axis. |
flex-direction | Flex | Sets the main axis. Reverse also flips start and end. |
justify-content | Both | Flex: packs the main axis. Grid: packs the whole grid when it is smaller than the container. |
align-items | Both | Flex: cross axis. Grid: default alignment inside each cell. |
flex | Flex | Shorthand for grow, shrink and basis. Basis is the starting size before leftover space is shared. |
gap | Both | Space between items, not around the container. Prefer this over margins on children. |
grid-template-columns | Grid | Defines column tracks. repeat(), minmax() and fr belong here. |
grid-column | Grid | Places one item, including a span. Line numbers start at 1. |
grid-auto-flow: dense | Grid | Back-fills holes left by spanning items. Visual order can then differ from DOM order. |
grid-template-areas | Grid | Names regions. Adjacent identical names merge into one cell. |
When to reach for which
Flexbox, space-between, nowrap. Logo on the start edge, actions on the end.
Flexbox with wrap and a pixel basis, or Grid auto-fit + minmax. Grid wins if every card should share a column track.
Either model. Flex with a fixed basis and flex-grow: 1 on main, or Grid 200px 1fr.
Grid with named areas. Header, nav, main, footer as regions — not nested flex columns pretending to be a page.
Grid, with a couple of items spanning two columns. Flex inside each card for the card’s own header.
Flexbox, both axes set to center. Grid place-items: center is the same idea on a one-cell grid.
Frequently Asked Questions
What is CSS Flexbox?
Flexbox is a one-dimensional layout model. A container with display:flex lays its children out along a main axis (row or column). justify-content distributes them along that axis and align-items along the cross axis. It is the right tool for navbars, button groups, wrapping card rows and a sidebar beside a main column.
What is CSS Grid?
CSS Grid is a two-dimensional layout model. You define column and row tracks, then place items on that grid — including items that span several cells. It is the right tool for page shells, dashboards, galleries and anything that needs simultaneous control of rows and columns.
When should I use Flexbox vs Grid?
Use Flexbox when the layout is one-dimensional — a row of controls, a wrapping card list, or a sidebar plus main. Use Grid when you need two dimensions at once: a header, sidebar, main and footer; a dashboard of mixed spans; or named regions. They compose: a Grid page can contain Flexbox toolbars.
What is the difference between justify-content and align-items?
In Flexbox, justify-content works along the main axis (horizontal in a row, vertical in a column) and align-items works along the cross axis. In Grid, justify-items and align-items position each item inside its cell, while justify-content and align-content pack the whole grid when it is smaller than the container.
What does flex-grow do?
flex-grow is the share of leftover space an item is allowed to take. 0 means it keeps its size; 1 means it grows equally with other growing siblings; 2 means it takes twice as much leftover space as an item with grow 1. It does not make an item twice as wide as another unless they started from the same basis.
What is the fr unit in CSS Grid?
fr is a fraction of leftover free space after fixed tracks are laid out. repeat(3, 1fr) makes three equal columns. 200px 1fr makes a 200 pixel sidebar and a main column that takes the rest. fr tracks shrink when the container shrinks, unlike a raw percentage of a parent that may overflow.
What is the difference between auto-fit and auto-fill?
Both fill a row with as many minmax() tracks as will fit. auto-fill keeps empty tracks, so leftover space stays as empty columns. auto-fit collapses empty tracks and the remaining items stretch to fill the row. Use auto-fit for a card gallery that should look full even with two cards.
How do grid-template-areas work?
You name regions in a string grid that matches your columns and rows, then assign items with grid-area. A holy-grail layout is three quoted rows such as "header header header" then "nav main aside". Identical names in adjacent cells merge into one region. The playground emits those quoted strings for you.
Can I copy HTML and CSS?
Yes. The code panel updates on every change. Copy CSS, HTML, or both together, or download a standalone HTML file that renders the layout with item colours included.
Does this work on mobile?
Yes. On narrow screens the studio becomes Controls, Preview and Code tabs so the playground stays large enough to judge the layout.
Is the generated CSS production-ready?
Yes for the layout itself. Default per-item rules are omitted, so you only get declarations you actually changed. Colours in the preview are for the playground; the downloaded page includes them as a demo, while copied CSS is the layout rules only.
Is this CSS generator free?
Yes. It is free, needs no account, and has no export limits or watermarks.
Why does align-content do nothing?
In Flexbox, align-content only runs when there is more than one line of items, so flex-wrap must not be nowrap. In Grid it packs extra space between tracks when the grid is smaller than the container. This playground omits align-content from the Flex CSS until wrapping is on, so the exported rule matches what you can actually see.
Does the order property change keyboard tab order?
No. order and grid-auto-flow: dense change visual placement only. Tab order and screen-reader order still follow the HTML. If a visually first item should also be first for the keyboard, move it in the markup rather than using order.
Is my layout uploaded anywhere?
No. The playground runs entirely in your browser. Autosave writes to your own browser storage only, and the share link encodes the layout in the page address rather than on a server.