CSS Flexbox Playground
CSS ToolsBuild flex layouts interactively — see changes live, copy production CSS. Free, private — all processing in your browser.
display: flex; flex-direction: row; justify-content: flex-start; align-items: stretch; flex-wrap: nowrap; gap: 8px;
The CSS Flexbox Playground turns Flexbox learning and experimentation into a visual, interactive experience. Every flex property — flex-direction, justify-content, align-items, align-content, flex-wrap, gap, flex-grow, flex-shrink, flex-basis, align-self — has a control you can toggle or slide, with the result rendering live in a preview area. Add or remove flex items, change their individual properties, and see how the container responds instantly. When you reach the layout you want, copy the generated CSS (ready to paste into your stylesheet) plus the corresponding HTML structure.
Flexbox is the most-used CSS layout mechanism in modern web development — powering navigation bars, card grids, form layouts, centered content, and responsive components. But remembering which property does what (justify-content vs align-items? what does flex-wrap: wrap-reverse look like?) is hard from documentation alone. Playing with live preview builds intuition fast. This playground helps junior developers learn Flexbox, senior developers prototype layouts quickly, and designers verify exactly what a CSS value will produce.
CSS Flexbox Playground — key features
Live visual preview
See every property change reflected instantly. No refresh, no guessing — just experiment and watch.
Every flex property
Controls for all container and item properties: direction, wrap, justify, align, gap, grow, shrink, basis, order, align-self.
Add and remove items
Click to add flex items. Each can be customized individually. See how items interact with container rules.
Copy CSS output
Generated CSS includes all relevant properties, formatted and commented. Ready to paste into your stylesheet.
Copy HTML structure
Matching HTML for the container and items. Use directly or adapt to your framework.
Preset layouts
Common patterns (centered, nav bar, cards, equal columns) as one-click starting points.
Responsive preview
Change viewport width to see how the flex layout responds. Test on mobile, tablet, desktop breakpoints.
100% client-side
No server involvement. Experiment freely — your work stays in your browser.
How to use the CSS Flexbox Playground
- 1
Start with a preset or blank
Pick a preset (nav bar, centered, cards) or start from scratch with basic display: flex.
- 2
Adjust container properties
Change flex-direction, justify-content, align-items, gap. See the preview update.
- 3
Add items as needed
Click Add Item to create more flex children. Modify text, color, padding to visualize your real content.
- 4
Customize individual items
Select an item to access flex-grow, flex-shrink, flex-basis, order, align-self. Build asymmetric layouts.
- 5
Test responsive behavior
Drag the preview width to see how the flex layout adapts. Verify wrapping behavior.
- 6
Copy CSS and HTML
When the layout is right, copy both the CSS rules and HTML markup to your project.
Common use cases for the CSS Flexbox Playground
Navigation and headers
- →Horizontal nav bar: Logo left, links right, all centered vertically. Classic justify-content: space-between + align-items: center.
- →Hamburger menu mobile: Flex-direction flips to column on small screens. Menu items stack vertically.
- →Breadcrumb trails: Row of links with separators. Flexbox gives perfect spacing.
- →Action toolbars: Icon buttons grouped. Flexbox centers content and manages wrapping for narrow windows.
Content layouts
- →Card grids that wrap: Equal-width cards that wrap to new rows on narrow screens. flex-wrap: wrap + flex-basis.
- →Two-column content: Sidebar + main content. Flexbox with flex: 1 on the main column.
- →Form layouts: Labels and inputs aligned consistently. Flex for each row, consistent widths.
- →Hero sections: Centered hero content with big heading and CTA. justify-content and align-items center make this trivial.
UI components
- →Button groups: Rows of buttons with consistent spacing. flex + gap.
- →Tag lists: Wrapping tags (like blog post tags). flex-wrap handles overflow gracefully.
- →Image galleries: Thumbnail grids where item count varies. flex-wrap: wrap.
- →Centered modals: Modal content centered on screen. display: flex on the backdrop, justify/align center.
Data visualization
- →Progress bars: Fill percentage with flex-grow on the filled section.
- →Score comparisons: Side-by-side metrics with consistent alignment.
- →Timeline views: Horizontal timeline with evenly-spaced events.
CSS Flexbox Playground — examples
Perfect centering
Any content centered horizontally and vertically.
Container display:flex, justify-content:center, align-items:center, height:100vh
.container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}Navigation bar
Logo left, links right.
justify-content:space-between, align-items:center
.nav {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 2rem;
}Equal-width columns
N columns that divide available space equally.
flex:1 on each child
.row {
display: flex;
gap: 1rem;
}
.row > * {
flex: 1;
}Card grid with wrapping
Cards wrap on narrow screens.
flex-wrap:wrap + flex:1 1 300px
.cards {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.card {
flex: 1 1 300px;
}Sidebar layout
Fixed sidebar, fluid main.
sidebar width 250px, main flex:1
.layout {
display: flex;
min-height: 100vh;
}
.sidebar {
width: 250px;
flex-shrink: 0;
}
.main {
flex: 1;
}Spaced action buttons
Primary button right, others left.
marginAuto on last item
.actions {
display: flex;
gap: 0.5rem;
}
.primary {
margin-left: auto;
}Technical details
CSS Flexbox (Flexible Box Layout, CSS Level 1 stable since 2012, Level 2 under development) is a one-dimensional layout model. It arranges items in a row or column and distributes space among them according to rules you specify.
Container properties (applied to parent):
``css``
.flex-container {
display: flex; /* or inline-flex */
flex-direction: row; /* row | row-reverse | column | column-reverse */
flex-wrap: nowrap; /* nowrap | wrap | wrap-reverse */
justify-content: flex-start; /* flex-start | flex-end | center | space-between | space-around | space-evenly */
align-items: stretch; /* stretch | flex-start | flex-end | center | baseline */
align-content: stretch; /* for wrapped multi-line only */
gap: 0; /* shorthand for row-gap and column-gap */
row-gap: 0;
column-gap: 0;
}
Item properties (applied to children):
``css``
.flex-item {
order: 0; /* integer, rearranges visual order */
flex-grow: 0; /* how much this item grows (0 = not at all) */
flex-shrink: 1; /* how much this item shrinks */
flex-basis: auto; /* initial size before grow/shrink */
flex: 0 1 auto; /* shorthand for grow/shrink/basis */
align-self: auto; /* override align-items for this item */
}
The shorthand flex:
The most confusing and common part. Common values:
- flex: 1 → 1 1 0% (grow to fill, shrink if needed, start from 0) — common for equal-width items
- flex: auto → 1 1 auto (grow to fill, shrink if needed, respect intrinsic width)
- flex: initial → 0 1 auto (default, no growing, can shrink)
- flex: none → 0 0 auto (no growing, no shrinking — fixed size)
Main axis vs cross axis:
In flex-direction: row (default), main axis is horizontal (left-right), cross axis is vertical (top-bottom). In column, axes swap. justify-content works on the main axis; align-items works on the cross axis.
Common patterns:
Horizontal center with vertical center:
``css``
.container {
display: flex;
justify-content: center; /* horizontal */
align-items: center; /* vertical */
min-height: 100vh;
}
Navigation bar (equal spacing):
``css``
.nav {
display: flex;
justify-content: space-between;
align-items: center;
}
Equal width columns:
``css``
.row {
display: flex;
gap: 1rem;
}
.row > * {
flex: 1;
}
Responsive wrapping cards:
``css``
.cards {
display: flex;
flex-wrap: wrap;
gap: 1rem;
}
.card {
flex: 1 1 300px; /* grow, shrink, min-width 300px */
}
Flexbox vs Grid:
- Flexbox: one-dimensional (row OR column). Ideal for: navigation, button groups, toolbars, alignment within components.
- Grid: two-dimensional. Ideal for: full-page layouts, card grids with rows AND columns, dashboards.
- Use both: Grid for outer layout, Flexbox for inner component layout.
Common bugs:
- justify-content: space-evenly not supported in IE11.
- gap in Flexbox not supported in Safari before 14.1 (2021).
- Margins on flex items do not collapse like in block layout.
- Implicit min-width: auto on flex items causes content to overflow — set min-width: 0 or overflow: hidden.
Common problems and solutions
⚠Flex items overflow their container
Flex items have implicit min-width: auto — they do not shrink below content width. Fix: set min-width: 0 on flex items, or use overflow: hidden. Most common on text-heavy items.
⚠gap not working in old Safari
gap property on flex containers is supported in Safari 14.1+ (2021). For older support, use margin workarounds: margin-right on items + negative margin-left on container.
⚠align-items vs align-content confusion
align-items aligns items on the cross axis (works with or without wrap). align-content aligns whole lines of items when flex-wrap is active and there are multiple lines.
⚠flex-direction changes meaning of justify vs align
In flex-direction: row, justify-content is horizontal, align-items is vertical. In flex-direction: column, they swap. Remember: justify-content is always the main axis, align-items is cross axis.
⚠order property breaks screen reader logic
order rearranges visual appearance but not DOM order. Screen readers follow DOM order. Relying on order can confuse accessibility. Reorder in HTML when logical reading matters.
⚠flex: 1 shrinks images
flex: 1 = flex-basis: 0, which makes intrinsic width (like an image native size) irrelevant. Images in flex: 1 containers may become 0 width. Use flex: 1 1 auto or give the container a defined size.
⚠Cannot justify wrapped content
Once content wraps, justify-content operates per line. If last line has fewer items, they stick to the left by default. Solutions: add invisible filler items, or use grid layout instead.
⚠flex-basis: 0 and percentages
Percentages in flex-basis are relative to the container main axis size. If you set flex-basis: 50% but content is wider, content overflows (unless flex-wrap is on). Be aware of this interaction.
CSS Flexbox Playground — comparisons and alternatives
Flexbox vs CSS Grid: Flexbox is 1D (row OR column). Grid is 2D (row AND column). Use Flexbox for components (nav, toolbar, button group). Use Grid for page layouts (dashboards, complex forms). Most pages use both: Grid outside, Flexbox inside.
Flexbox vs Floats (legacy): Floats were the standard for layout before Flexbox (pre-2015). They are finicky, require clearfix hacks, and hard to center vertically. Flexbox solved all of it. No reason to use floats for layout in 2026 (still useful for text wrapping around images).
Flexbox vs Table-based layout (legacy): Tables for layout date to the 1990s. Completely inappropriate for modern layout — inaccessible, hard to style, inflexible. Flexbox is the modern replacement.
Flexbox vs Inline-block: inline-block is simpler for basic horizontal item alignment but has quirks (whitespace between items, vertical alignment headaches). Flexbox is cleaner and more powerful.
Flexbox vs Position: absolute: Absolute positioning removes items from the flow. Use for overlays, modals, tooltips. Do not use for main content layout — brittle on responsive.
Flex-direction row vs column: Row is default (horizontal flow). Column stacks items vertically. Neither is better — choose based on what you are building.
Frequently asked questions about the CSS Flexbox Playground
▶What is CSS Flexbox?
Flexbox (Flexible Box Layout) is a CSS layout mode designed for distributing space among items in a container, along a single axis (row or column). Introduced to modern browsers around 2012 and now universally supported. It replaces older techniques (floats, inline-block) for most layout tasks.
▶When should I use Flexbox vs Grid?
Flexbox for 1-dimensional layouts — items in a row OR column. Navigation bars, button groups, centered content. Grid for 2-dimensional layouts — rows AND columns together. Full-page layouts, dashboards, complex forms. Most real projects use both: Grid for the outer layout, Flexbox inside components.
▶How do I center something with Flexbox?
Container with display: flex + justify-content: center + align-items: center. The child is perfectly centered horizontally and vertically. This is Flexbox most famous use case — replaced years of hacky centering techniques.
▶What does flex: 1 do?
flex: 1 is shorthand for flex-grow: 1, flex-shrink: 1, flex-basis: 0%. Means: grow to fill available space, shrink if needed, start from size 0. When applied to multiple items, they share space equally. Most common use: equal-width columns.
▶What is the difference between justify-content and align-items?
justify-content distributes space along the main axis. align-items aligns items on the cross axis. In flex-direction: row (default), main is horizontal. So justify-content centers horizontally, align-items centers vertically. When you flip to flex-direction: column, they swap.
▶Why do my flex items overflow?
Flex items have implicit min-width: auto — they refuse to shrink below their content size. Long words or text can overflow. Fix: add min-width: 0 on flex items, or overflow: hidden. Common issue with text-heavy items inside a flex: 1 container.
▶Does Flexbox work in all browsers?
Yes, in all modern browsers — Chrome, Firefox, Safari, Edge since 2012. Full support. IE11 has partial support with older syntax (flex-grow, flex-shrink were buggy). For IE11-friendly code, use flex-basis explicitly and avoid the flex: 1 shorthand.
▶How do I make wrapping responsive?
flex-wrap: wrap plus min-width on items. Example: flex: 1 1 300px means grow, shrink, but never below 300px wide. When container is under 3 * 300px = 900px, items wrap to new rows. No media queries needed.
▶Can Flexbox do column layouts?
Yes, with flex-direction: column. Common for mobile sidebars, vertical navigation, and stacked hero sections. Properties like justify-content and align-items swap meaning (now vertical and horizontal respectively).
▶What is gap and when is it supported?
gap sets uniform spacing between flex items without margins. Much simpler than margin hacks. Supported in Chrome 84+, Firefox 63+, Safari 14.1+ (2021). For older Safari, fall back to margins.
Additional resources
- CSS Flexbox Spec (W3C) — Official CSS Flexbox Level 1 specification.
- MDN Flexbox Guide — Comprehensive Flexbox reference.
- A Complete Guide to Flexbox (CSS-Tricks) — The classic visual Flexbox guide.
- Flexbox Froggy — Interactive Flexbox learning game.
- CSS Flexbox Tutorial (Tooleras blog) — Our in-depth Flexbox guide.
Related tools
All CSS ToolsCSS Animation Generator
Build CSS keyframe animations and transitions with live preview and easing curves
CSS Border Radius Generator
Generate CSS border-radius — from simple rounded corners to organic blob shapes
CSS Box Shadow Generator
Create realistic CSS box shadows — single, layered, inset, neumorphism styles
CSS Clip Path Generator
Create custom CSS shapes with clip-path — polygons, circles, ellipses, SVG paths
CSS Formatter
Beautify and indent CSS, SCSS, LESS code — configurable style, production-ready output
CSS Gradient Generator
Create linear, radial, and conic CSS gradients with live preview
Learn more
Explore more tools
200+ free tools that run in your browser.
Browse all tools →