Flexbox and Grid Playground
Build flexbox and CSS grid layouts visually. Set container and item properties, name grid areas, see the result live and copy clean CSS and HTML.
Presets
Click an item in the preview to select it and edit its properties below.
How to use the flexbox and grid playground
- Pick a Layout: Flexbox or Grid, or start from one of the Presets (Centered, Navigation bar, Wrapping cards, Sidebar, Responsive card grid, Holy grail, 12 columns).
- Set the Container properties. For flexbox:
flex-directionandflex-wrap. For grid:grid-template-columns,grid-template-rows,grid-auto-flow,justify-itemsandgrid-template-areas. Both sharejustify-content,align-items,align-content,row-gap (px)andcolumn-gap (px). - Manage the Items with Add item, Remove selected item and Reset selected item. Click an item in the preview (or tab to it and press Enter) to select it.
- Edit the selected item:
orderandalign-selfin both modes,flex-grow,flex-shrinkandflex-basisfor flexbox, andgrid-area,grid-column,grid-rowandjustify-selffor grid. - Copy the CSS code and the matching HTML code with their Copy buttons.
Every control is a standard form field, so the whole playground works with the keyboard alone. The CSS only contains the properties you changed from their defaults, which keeps it short, and items with identical settings share one rule (.item when they all match).
Flexbox in a nutshell
Flexbox lays items out along one axis. flex-direction sets the main axis (a row or a column); justify-content distributes items along it (center, space-between…), and align-items positions them on the cross axis. With flex-wrap: wrap, items that do not fit move to a new line, and align-content then spaces those lines.
Each item has three sizing properties, usually written together as flex:
flex-basis: the starting size (autouses the content orwidth);flex-grow: how much of the free space the item takes (0 = none, 1 = an equal share);flex-shrink: how much it gives up when space is short (0 = never shrinks).
The Sidebar preset shows the classic pattern: a sidebar with flex-basis: 200px and flex-shrink: 0, and a main area with flex-grow: 1.
CSS Grid in a nutshell
Grid lays items out in two dimensions. grid-template-columns: repeat(3, 1fr) creates three equal columns; fr is a share of the free space. repeat(auto-fill, minmax(120px, 1fr)) creates as many columns of at least 120px as fit, which makes a responsive card grid without any media query.
Items fill the cells in order, unless you place them: grid-column: span 2 makes an item two columns wide, and grid-column: 1 / -1 stretches it across the whole row.
grid-template-areas lets you draw the layout with names. Type one row per line, for example header header then nav main, and give items grid-area: header or grid-area: main. A dot marks an empty cell. Every row needs the same number of cells and each name must form a rectangle; the tool warns you otherwise.
Frequently asked questions
Should I use flexbox or grid?
Flexbox for one-dimensional content such as toolbars, button groups or centering. Grid when rows and columns must line up, as in page layouts and card galleries. They combine well: a grid of cards whose insides use flexbox.
Why doesn't align-items change anything?
In a row, items stretch to the height of the container by default, and the container is only as tall as its content. Give it a height, or look at the preview, which has a minimum height.
What does gap do?
It sets the space between items (not around them). It works in both flexbox and grid in all current browsers.
Does order change the reading order?
No. order only moves items visually; screen readers and keyboard navigation still follow the HTML order, so use it sparingly.
Related tools
- CSS Formatter and Minifier Beautify messy CSS with clean indentation or minify it with csso, and see the size before and after. Runs in your browser; nothing is uploaded.
- Border Radius Generator Shape CSS border-radius visually with draggable handles. Set each corner in px or %, use the 8-value elliptical syntax, make blob shapes and copy the code.
- Box Shadow Generator Design layered CSS box shadows with a live preview. Set offset, blur, spread, color, opacity and inset, try neumorphism presets and copy the code.