Skip to content
JustTools

CSS Flexbox & Grid Playground

Click through every flexbox and grid property and watch a live layout change, with plain-English explanations, item sizes and grid line numbers — then copy the code as CSS, HTML, Tailwind or React.

Runs in your browser Free · no sign-up

At a glance

  • Covers every flexbox container property (flex-direction, flex-wrap, justify-content, align-items, align-content, gap) and every flex item property (flex-grow, flex-shrink, flex-basis, align-self, order).
  • Covers CSS grid too: grid-template-columns and -rows with fr, minmax(), repeat(auto-fill / auto-fit), grid-auto-rows, grid-auto-flow (dense), justify/align-items and -content, and line-based placement with spans.
  • Each choice comes with a one-line explanation of what it does, and the preview shows the real size of every item in pixels, so flex-grow and flex-basis stop being guesswork.
  • In grid mode the line numbers are drawn on the layout, and you can drag across the grid to place an item.
  • Copies the layout as CSS, HTML, Tailwind CSS v4 classes or a React component; the Tailwind output is checked against the real Tailwind v4 compiler to produce the same CSS.
  • Warns when order, reversed directions, dense packing or line placement make the visual order differ from the HTML — which screen readers and the Tab key still follow.
  • Flexbox gap works in Chrome 84+, Firefox 63+ and Safari 14.1+; CSS grid in Chrome 57+, Firefox 52+ and Safari 10.1+ (MDN browser-compat data).
  • Free, no sign-up; layouts are saved in your browser and can be shared as a link.

Step by step

How to build a layout with flexbox or grid

  1. 1

    Pick Flexbox or Grid

    Flexbox lays items out in one direction (a row or a column); grid places them in rows and columns at once. Or start from one of the examples.

  2. 2

    Set the container

    Click values such as justify-content: space-between or grid-template-columns: repeat(3, 1fr) and watch the preview.

  3. 3

    Adjust single items

    Click an item, then give it flex-grow, a fixed flex-basis, its own alignment, or grid lines and spans. In grid mode you can drag its area on the grid.

  4. 4

    Test it

    Drag the container width slider to see how the layout responds on narrow screens.

  5. 5

    Copy the code

    Choose CSS, HTML, Tailwind or React, then Copy or Download. Share builds a link to this exact layout.

Features

Everything you need, nothing you don’t

See what each property does

Every value is a button, and the preview updates as you click. A sentence under each property explains the current value — no need to keep a cheat sheet open.

Main axis, cross axis, made visible

The preview names the main and cross axes for the current flex-direction, so justify-content and align-items finally make sense when you switch to column.

Real sizes on every item

Change flex-grow, flex-shrink or flex-basis and watch each item’s width in pixels. Narrow the container to see shrinking and wrapping happen.

Grid lines you can draw on

Numbered grid lines sit over the layout. Turn on drawing and drag across cells to give an item its column and row lines.

Code in four flavours

Plain CSS with HTML, Tailwind CSS v4 classes, or a ready React component — with or without demo colours.

Ready-made layouts

Start from a centred box, navbar, wrapping cards, sidebar, sticky footer, responsive card grid, holy grail or dashboard and adjust from there.

Flexbox or grid?

Flexbox is for laying things out along one line — a navigation bar, a row of buttons, a card’s header and footer — where the content decides the sizes and items may wrap. Grid is for two-dimensional layouts — page structure, galleries, dashboards — where you define the columns and rows first and place items into them.

They work well together: a grid for the page, flexbox inside each card.

The properties people mix up

In flexbox, switching flex-direction to column swaps the axes: justify-content then works vertically and align-items horizontally. justify-items does nothing in flexbox.

PropertyWorks alongWhat it moves
justify-contentMain axis (flex) / inline axis (grid)The items as a group (flex) or the whole set of tracks (grid)
align-itemsCross axis (flex) / block axis (grid)Each item inside its line or grid area
align-contentCross axisWhole lines of wrapped items (flex) or rows of tracks (grid)
justify-itemsInline axis (grid only)Each item inside its grid area
align-self / justify-selfSame as align-items / justify-itemsOne item, overriding the container

flex-grow, flex-shrink and flex-basis

  • flex-basis is the starting size along the main axis. auto uses the item’s width (or its content); 0 ignores content so space is shared purely by flex-grow.
  • flex-grow shares out leftover space: an item with 2 gets twice as much of the extra as an item with 1. With 0 it never grows.
  • flex-shrink decides who gives up space when there is not enough; 0 means the item never shrinks below its basis.
  • The shorthand flex: 1 means 1 1 0%; flex: auto means 1 1 auto; flex: none means 0 0 auto. This tool always writes all three values so nothing is hidden.

auto-fill vs auto-fit

repeat(auto-fill, minmax(140px, 1fr)) makes as many 140px-or-wider columns as fit, keeping empty columns when there are few items. auto-fit does the same but collapses empty columns, so a few items stretch across the full width. Load the Responsive cards example, remove items and switch between the two to see the difference.

FAQ

Frequently asked questions

What is the difference between justify-content and align-items?

justify-content distributes items along the main axis (left to right in a row); align-items positions them on the cross axis (top to bottom in a row). Switch flex-direction to column and they swap directions.

Why does align-content do nothing?

In flexbox it only affects containers whose items wrap onto more than one line — set flex-wrap: wrap and give the container some height. In grid it moves the rows when they are shorter than the container.

Why does my flex item not shrink below its text?

Flex items have a default min-width of auto, so they will not shrink below their longest word or a fixed-size child. Add min-width: 0 to the item (min-w-0 in Tailwind) to let it shrink.

What does 1fr mean in CSS grid?

One fraction of the leftover space. In grid-template-columns: 1fr 2fr, the second column gets twice the free space of the first. Note that 1fr has a minimum of auto, so long content can widen it; minmax(0, 1fr) — what Tailwind’s grid-cols-3 uses — prevents that.

Is the Tailwind code for Tailwind v3 or v4?

Tailwind CSS v4. Most classes are the same in v3, but v4 accepts any spacing step (gap-13, basis-30); in v3 use an arbitrary value such as gap-[52px] for steps the default scale lacks.

Can I use gap with flexbox?

Yes — in Chrome 84+, Edge 84+, Firefox 63+ and Safari 14.1+. For much older browsers use margins on the items instead.

Does order change the reading order?

No. order, row-reverse, column-reverse and grid placement change only what you see. Screen readers and keyboard focus follow the HTML, so the tool warns you when the two may differ.

Is my layout saved?

Yes, in your browser on this device. Use Share to copy a link that opens the same layout anywhere — it is stored in the link itself, not on a server.

Keep going

Browse every tool

Last updated Report a problem or suggest a feature