Flexbox & Grid Playground
See CSS layout actually work. Flip flexbox and grid settings on numbered boxes, watch them react live, and copy the real container CSS when it clicks. Free, private, no signup.
The dashed box is the container — your CSS applies to it.
Your CSS
How to build layouts with flexbox and grid
Flexbox and grid are the two modern CSS layout systems. Flexbox arranges items along one axis — a row or a column. Grid arranges them along two axes at once — rows and columns. Between them, they cover almost every layout on the modern web.
- Pick your system. Components like nav bars, button rows, and card decks are flexbox. Page layouts and galleries are grid.
- Set the direction. For flexbox, choose row or column (and the reverse variants). For grid, choose how many columns you want — the items will fill rows automatically.
- Spread the items.
justify-contentpushes items along the main axis (try space-between for a nav bar);align-itemslines them up across it. - Space them evenly with
gap— one number, no margin math. - Copy the CSS. The generated block goes on the container element — the parent that wraps your items.
The centering trick everyone googles
To center something perfectly with flexbox: display: flex; justify-content: center; align-items: center;. That's it — horizontal and vertical centering in three lines. No negative margins, no transforms, no wrapper divs.
Grid fractions without the math
The fr unit is grid's secret weapon: it means "a share of the leftover space". grid-template-columns: repeat(3, 1fr) gives three equal columns; 2fr 1fr gives a main column twice as wide as a sidebar. Type any template into the custom field above — including mixed units like 2fr 1fr 200px — and the preview will render it instantly.
- When should I use flexbox vs grid?
- Flexbox lays things out in one direction — a row or a column — and is best for components like nav bars, card rows, and form fields. Grid works in two directions at once — rows and columns — and is best for full page layouts and photo galleries.
- What is the difference between justify-content and align-items?
justify-contentspreads items along the main direction (horizontal for a row, vertical for a column);align-itemsspreads them along the other, cross direction. Flipflex-directionto column and the two axes swap.- What does the gap value do?
- Gap puts even spacing between every item — rows and columns alike — without the double-margin headaches of old margin tricks. One value sets both; in raw CSS you can also use
row-gapandcolumn-gapseparately. - What does fr mean in a grid template?
fris a fraction of the free space.1fr 1fr 1frsplits a row into three equal columns;2fr 1frmakes the first column twice as wide as the second.- Why did my flex items shrink?
- Flex items shrink by default (
flex-shrink: 1) to fit the container. To keep their size, give them a fixed width or setflex-shrink: 0. This playground shows the default shrinking behavior. - Is my data sent anywhere?
- No. Everything runs in your browser with plain JavaScript. Nothing is uploaded or stored.
More from the codex
Flexbox & Grid Playground
Learn CSS layout visually with a live playground.
CSS Gradient Generator
Linear, radial, and repeating gradients with live preview.
Open tool → NewBox Shadow Generator
Design box shadows with sliders — blur, spread, inset — and copy the CSS.
Open tool → LiveColor Picker
Pick colors and get hex, RGB, and HSL codes instantly.
Open tool → LiveCSS Minifier
Shrink your CSS down for faster page loads.
Open tool → LiveMarkdown Previewer
Write Markdown and see it rendered live.
Open tool → LiveHTML Entity Codec
Encode and decode HTML entities.
Open tool → LiveJSON Formatter
Format and validate JSON in one click.
Open tool → LiveMeta Tag Generator
Build SEO and social meta tags for any page.
Open tool → LiveQR Generator
Make QR codes for any link or text.
Open tool → LiveWord Counter
Count words and estimate reading time instantly.
Open tool → LiveBase64 Encoder
Encode and decode Base64, URL-safe too.
Open tool →Support the codex
This tool is free, with no account and no ads. If it saved you a trip to a search engine, consider supporting the indie dev behind it.
Questions about this tool?
Found a wrong code or have a suggestion? Email [email protected] — every message is read by the indie dev behind the codex.