Start a project

Tool 63 of 244 · Layout

Grid & Flexbox Playground

Lay out a page with CSS Grid or Flexbox by changing settings and watching the preview, then copy the CSS and HTML it writes for you.

Grid & Flexbox Playground at a glanceIllustration: 1, Columns and gaps; 2, processed in your browser; 3, Grid or flex CSS.Grid & Flexbox Playground1Columns and gaps</>3Grid or flex CSS2In yourbrowser
1 Columns and gaps 2 processed on your device 3 Grid or flex CSS

Grid & Flexbox Playground

Container

Selected item: Item 1

Click or tab to an item in the preview to select it.

Preview

Your code

CSS
HTML

01

What it does

Build Grid and Flexbox layouts visually, set spans and flex values per item, and copy the CSS and HTML.

  • Fixed, auto-fill and custom column templates
  • Gaps, alignment and dense packing
  • Per-item column and row spans
  • Flex direction, wrap, grow, shrink and basis

02

Private by design

Everything happens in your browser. Nothing you type, paste or upload is sent anywhere, and it keeps working offline once the page has loaded.

03

What you get

CSS and HTML, with a Copy and a Download button on every result.

  • CSS Grid
  • Flexbox
  • Layout

Why it matters

Grid and Flexbox replaced floats and frameworks for layout years ago, and every current browser supports both. But the properties are easy to mix up: justify-items or justify-content, auto-fill or auto-fit, and which ones belong on the container rather than the items.

Seeing the result as you change each setting is the quickest way to learn them, and the fastest way to get a tricky layout right. The code this writes is plain CSS with no framework, ready to paste.

How it works

  1. InputColumns, rows, gaps and alignment
  2. In your browserLive CSS Grid or Flexbox layout
  3. OutputThe CSS and HTML for the layout

Where it fits in a designer's workflow

  1. Plan
  2. Design
  3. Build
  4. Test
  5. Launch
Sketch layouts in the browser before writing components.

By the numbers

grid-template-columns: 1fr 2fr 1fr with a 24px gap, at three widths390px: 85.5px, 171px, 85.5px; 768px: 180px, 360px, 180px; 1200px: 288px, 576px, 288px390px container171768px container1803601801200px container288576288
Computed: the gaps come off first, then the free space is shared out in proportion to the fr values (1 + 2 + 1 = 4 shares). Drawn to scale against a 1200px container. Source: CSS Grid Layout Module Level 2: flexible lengths.
Show the numbers as a table
Container1fr2fr1fr
390px85.5px171px85.5px
768px180px360px180px
1200px288px576px288px

How to use it

  1. Choose CSS Grid or Flexbox, or start from a preset.
  2. Set the columns, rows, gaps and alignment for the container.
  3. Select an item in the preview to change its span or flex values.
  4. Copy or download the CSS and HTML.

FAQ

What's the difference between auto-fill and auto-fit?

Both fit as many columns as there's room for. With only a few items, auto-fill keeps the empty column tracks, so items stay their minimum size; auto-fit collapses them, so items stretch to fill the row. This tool writes auto-fit with min(220px, 100%), so a single card never overflows a narrow phone.

When should I use Grid rather than Flexbox?

Use Grid when you're placing things in rows and columns at the same time, like a card grid or a page layout. Use Flexbox for one row or column of things, like a navigation bar or a row of buttons.

What does dense do?

grid-auto-flow: dense lets later, smaller items fill gaps left by bigger ones. It can change the visual order, so keep the HTML order sensible for keyboard and screen reader users.

Does it work on phones?

Yes. The preview scrolls sideways if your layout is wider than the screen.

Work with me

Want a site that gets these right?

I build fast, accessible websites and web apps that pass these checks from day one. Tell me about your project and I'll reply personally with honest next steps.

All developer tools · Back to leej.uk