Flexbox & Grid Playground
Try every flexbox and CSS grid property on live boxes and copy the CSS or Tailwind classes.
Click an item to edit its own properties. Drag the bottom-right corner to resize the container.
Container
Item
Select an item in the preview to change flex-grow, order, spans and alignment for that item.
.container {
display: flex;
gap: 12px;
}<div class="flex gap-3"> <div>1</div> <div>2</div> <div>3</div> <div>4</div> <div>5</div> </div>
About this tool
Flexbox and CSS Grid are the two layout systems of modern CSS. Flexbox arranges items along one axis, a row or a column, and is ideal for navigation bars, button groups, media objects and centering. Grid places items in rows and columns at the same time, which suits page layouts, card galleries and dashboards. Most layout bugs come from not knowing exactly what a property does, and reading the spec rarely helps as much as seeing it.
This playground shows every important property on real, numbered boxes. Change the container settings and watch the items move, click an item to give it its own flex-grow, order, span or alignment, and drag the container corner to see how the layout reacts to less space. The tool writes only the declarations that differ from the defaults, so the CSS stays short, and it also produces the equivalent Tailwind classes as ready-to-paste HTML.
How to use Flexbox & Grid Playground
- Choose Flexbox or Grid and set how many items you want to see.
- Change the container properties such as direction, wrapping, justify-content, align-items, gap, or grid template columns and rows.
- Click an item in the preview to edit its own properties, for example flex-grow, order or a column span.
- Copy the CSS or the Tailwind HTML. Use Reset to go back to the defaults.
Examples
Center anything
Flexbox, justify-content: center, align-items: center
.container {
display: flex;
justify-content: center;
align-items: center;
}
Tailwind: flex justify-center items-center Navigation bar
Flexbox, space-between, align-items: center, gap 16px
flex justify-between items-center gap-4
Responsive card grid
Grid template “Responsive cards”, gap 16px
.container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
gap: 16px;
} Columns are added or removed automatically as the container gets wider or narrower, with no media queries.
Flexbox in a nutshell
- flex-direction sets the main axis. justify-content distributes items along it; align-items aligns them on the cross axis.
- flex-wrap lets items move to new lines. align-content only works when there are several lines.
- flex: grow shrink basis decides how an item uses free space. flex: 1 (1 1 0%) makes items share space equally; flex: none keeps an item at its natural size.
- gap adds space between items without margins on the outer edges.
- order changes the visual order only. Screen readers and keyboard focus still follow the HTML order, so do not use it to fix content order.
Grid in a nutshell
- grid-template-columns defines the column tracks. fr units share leftover space; repeat(3, 1fr) makes three equal columns.
- repeat(auto-fill, minmax(140px, 1fr)) creates as many columns as fit, each at least 140px wide: responsive without media queries.
- grid-column: span 2 makes an item two tracks wide; grid-row: span 2 makes it two rows tall.
- justify-items and align-items align items inside their cells; justify-self and align-self override that for one item.
- grid-auto-flow: dense fills holes left by large items, again changing visual order but not reading order.
Frequently asked questions
Everything you need to know about this tool and data security.
Should I use flexbox or grid?
Use flexbox when content decides the size and you lay out one row or column, such as a toolbar. Use grid when you want items to line up in both directions or the layout decides the size, such as a gallery or page frame. They combine well: a grid page whose cards use flexbox inside.
Why does justify-content not work in my flex column?
In a column the main axis is vertical, so justify-content needs free vertical space. Give the container a height (or let it stretch in a parent) and it will work. To center horizontally in a column, use align-items instead.
Why does my flex item overflow instead of shrinking?
Flex items have min-width: auto, so they never shrink below their content, for example a long word or URL. Add min-width: 0 (Tailwind: min-w-0) to the item, or overflow: hidden, to let it shrink.
Is my data safe when using this tool?
Yes, 100% safe. This tool operates entirely inside your web browser using client-side JavaScript and WebAssembly. Your data never touches any external server.
Related Tools
Convert px, rem, em, pt, vw and more, generate fluid clamp() font sizes and rewrite whole stylesheets to rem.
Build layered CSS box shadows with a live preview, plus neumorphism and glassmorphism styles.
Minify or beautify HTML, CSS and JavaScript and see how many bytes you save.
Featured Projects tech-fun.net
Explore more AI & productivity tools
Nihongo GameBox
Master Japanese typing, Kana, and JLPT N5–N1 vocabulary through interactive retro arcade games.
ResumeGPT
Tailors CVs and cover letters to every job opportunity with a multi-agent LLM pipeline, job tracking, and scheduled discovery.
CollectMind
Turns your bookmarks into a searchable AI knowledge base — entirely on-device, powered by Chrome's built-in Gemini Nano.