Flexbox Visual Playground
Interactive CSS flexbox playground with live preview, visual guides, and preset layouts for learning and prototyping
Updated
What is the Flexbox Visual Playground?
Master CSS flexbox with an interactive, visual playground that brings layout properties to life. This tool bridges the gap between reading documentation and understanding how flexbox actually works in the browser.
Why Flexbox Matters
Flexbox is the foundation of modern CSS layout. Before flexbox, developers relied on floats, tables, and absolute positioning—hacks that made responsive design painful. Flexbox introduced a one-dimensional layout model that distributes space along a single axis (row or column), solving alignment, distribution, and ordering problems that plagued CSS for decades.
Yet flexbox remains one of the most misunderstood CSS modules. Properties like justify-content and align-items sound interchangeable. The difference between flex-grow, flex-shrink, and flex-basis confuses even experienced developers. This playground eliminates confusion through immediate visual feedback.
What Makes This Playground Different
Unlike static tutorials or code editors, this tool provides:
- Live visual guides showing the main axis and cross axis in real-time
- Gap visualization with measurements as you adjust spacing
- 8 production-ready presets including holy grail, card grids, sidebars, and navbars
- Individual item controls for
flex-grow,flex-shrink,flex-basis,align-self, andorder - Mobile viewport simulation to test responsive behavior
- Generated CSS and HTML ready to copy into your projects
Who Should Use This Tool
- Beginners learning flexbox for the first time
- Frontend developers prototyping layouts before writing production code
- Designers communicating layout requirements to developers
- Teachers demonstrating flexbox concepts in classrooms
- Experienced developers troubleshooting tricky alignment issues
The playground runs entirely in your browser—no setup, no frameworks, no distractions. Start with a preset, manipulate properties, and watch your understanding click into place.
How it works
Container Properties Panel
The left panel controls flex container behavior—the parent element with display: flex.
Direction and Wrapping
| Property | What It Controls |
|---|---|
| Direction | Establishes the main axis (row = horizontal, column = vertical) |
| Wrap | Whether items overflow or wrap to new lines |
When you change direction, visual axis arrows rotate to show the new main and cross axes. This immediate feedback clarifies why justify-content affects horizontal spacing in rows but vertical spacing in columns.
Alignment Controls
| Property | Axis | Behavior |
|---|---|---|
| Justify Content | Main axis | Distributes items along the direction of flex (row = horizontal, column = vertical) |
| Align Items | Cross axis | Aligns items perpendicular to the main axis |
| Align Content | Cross axis | Distributes lines of wrapped content (only applies when wrapping) |
The distinction between align-items (single-line alignment) and align-content (multi-line distribution) is visualized automatically when you enable wrapping and add multiple items.
Gap and Spacing
Enter any CSS length for gap (e.g., 16px, 1rem, 2%). The playground validates your input and shows a live measurement overlay when gap visualization is enabled. Separate row-gap and column-gap values can be set for granular control.
Visual Preview Area
The central preview renders your flex container with real CSS properties applied inline. This is not a simulation—it is actual flexbox behavior.
Visual Guides
Toggle Show axes to display:
- Purple arrow: Main axis direction (items flow this way)
- Cyan arrow: Cross axis direction (alignment happens this way)
Toggle Show gap to highlight the spacing between items with measurements.
Mobile Simulation
Click Mobile to constrain the preview to 375px width. This reveals how wrapping and responsive behavior work on small screens—essential for testing flex-wrap and flex-basis strategies.
Item Selection
Click any flex item to select it. Selected items show a violet border and checkmark. This unlocks the item properties panel.
Item Properties Panel
When an item is selected, you control its flexibility and positioning:
| Property | Purpose | Typical Values |
|---|---|---|
| Flex Grow | How much item expands to fill space | 0 (fixed), 1 (equal share), 2+ (double share) |
| Flex Shrink | How much item contracts when space is tight | 0 (never shrink), 1 (shrink normally) |
| Flex Basis | Starting size before growing/shrinking | auto, 200px, 50%, 20rem |
| Align Self | Override container's align-items |
flex-start, center, stretch, etc. |
| Order | Visual reordering (does not affect DOM) | 0 (default), -1 (first), 1 (later) |
Changes apply immediately. Watch how flex-grow: 1 makes an item fill available space, or how flex-basis: 300px establishes a minimum before wrapping occurs.
Preset Layouts
Eight production-tested patterns provide starting points:
- Holy Grail: Header, footer, nav, main content, sidebar with sticky footer behavior
- Card Grid: Responsive wrapping cards with consistent gaps
- Navbar: Space-between distribution for logo, links, and user actions
- Perfect Center: Single item centered both axes (modal dialogs, empty states)
- Sidebar Layout: Fixed-width sidebar with fluid main content
- Masonry-like: Uneven items with natural wrapping flow
- Split Screen: Two equal panels side-by-side
- Footer Bottom: Sticky footer using
min-height: 100vhandflex-grow: 1content
Each preset loads with optimized item counts and individual flex properties pre-configured.
Code Generation
The Generated Code section provides production-ready output:
- CSS tab: Complete
.containerand.itemstyles with optional comments - HTML tab: Semantic markup structure
- Minify toggle: Compressed output for production
Click Copy to clipboard or select and paste directly into your project.
Custom CSS Import
Paste existing flexbox CSS to populate the playground. The parser extracts:
display,flex-direction,flex-wrapjustify-content,align-items,align-contentgap,row-gap,column-gap
This reverse workflow helps you visualize existing code or debug layouts from other sources.
Examples
Holy Grail Layout
Create the classic header, footer, and three-column layout with fluid center
Responsive Card Grid
Build a wrapping card grid that adapts to container width
Perfect Centering
Center a single element both horizontally and vertically
Sidebar Navigation
Create a fixed sidebar with scrollable main content
Navbar with Spaced Items
Build a navigation bar with logo left, links center, and user menu right
Frequently asked questions
What is flexbox and why should I learn it?
What is flexbox and why should I learn it?
Flexbox (Flexible Box Layout) is a CSS module designed for one-dimensional layout control. Unlike older techniques like floats or absolute positioning, flexbox provides predictable alignment and space distribution between items in a container. It solves common problems like vertical centering, equal-height columns, and responsive reordering that were previously hacky or impossible. Modern web development relies heavily on flexbox—it's essential for navbars, card grids, sidebars, form layouts, and component-level alignment.
What is the difference between justify-content and align-items?
What is the difference between justify-content and align-items?
These properties align items on different axes:
- justify-content works on the main axis (the direction flex items flow: horizontal in
row, vertical incolumn) - align-items works on the cross axis (perpendicular to main: vertical in
row, horizontal incolumn) In a standard row layout,justify-contentmoves items left/center/right, whilealign-itemsmoves them up/center/down. The playground's visual axis arrows update dynamically to reinforce this as you change direction.
When should I use align-content versus align-items?
When should I use align-content versus align-items?
Use align-items for single-line containers (no wrapping) to control cross-axis alignment of items.
Use align-content for multi-line containers (with flex-wrap: wrap or wrap-reverse) to control how the lines of items are distributed. align-content has no effect on single-line flex containers—this is a common source of confusion that the playground visualizes automatically.
What is the difference between flex-grow, flex-shrink, and flex-basis?
What is the difference between flex-grow, flex-shrink, and flex-basis?
These three properties control how flex items resize:
- flex-basis: The starting size before growing or shrinking (e.g.,
200px,50%,auto) - flex-grow: How much the item expands to fill extra space (ratio-based, default
0) - flex-shrink: How much the item contracts when space is tight (ratio-based, default
1) The shorthandflex: 1 1 200pxsets grow, shrink, and basis together. In the playground, manipulate these individually to see howflex-grow: 2gets twice the extra space asflex-grow: 1.
Why doesn't my flex item grow even with flex-grow set?
Why doesn't my flex item grow even with flex-grow set?
Check these common issues:
- No extra space:
flex-growonly applies when the container has surplus space after all items hit theirflex-basisor content size - flex-basis too large: If basis equals or exceeds available space, there's nothing to grow into
- Container constraints: Parent elements may have fixed widths or
overflow: hiddenlimiting space - min-width/min-height: These can prevent shrinking, indirectly affecting growth calculations Use the playground's item selection to inspect computed sizes and test different basis values.
How do I create a sticky footer with flexbox?
How do I create a sticky footer with flexbox?
Set the container to flex-direction: column with min-height: 100vh (full viewport). Give your main content flex-grow: 1 and keep header/footer at flex-grow: 0. The content area expands to push the footer to the bottom when content is short, but allows natural scrolling when content is long. The Footer Bottom preset demonstrates this pattern.
What is the difference between gap and margin for spacing?
What is the difference between gap and margin for spacing?
Gap (gap, row-gap, column-gap) creates spacing only between items, not between items and container edges. Margin affects all sides and collapses in ways that complicate layouts. Gap is cleaner for flexbox grids because:
- No negative margin hacks needed on containers
- Consistent spacing regardless of wrapping
- Doesn't affect item dimensions in calculations
- Handles spacing between rows and columns uniformly The playground visualizes gap with measurement overlays when enabled.
Can I use flexbox for two-dimensional layouts like CSS Grid?
Can I use flexbox for two-dimensional layouts like CSS Grid?
Flexbox is one-dimensional—it controls layout along a single row OR column. For true two-dimensional control (simultaneous rows AND columns), use CSS Grid. However, flexbox excels at:
- Component-level alignment (buttons in a toolbar, items in a card)
- Unknown or dynamic numbers of items (wrapping grids)
- Content-driven sizing (items sized by their content)
- Simple distributions (center, space-between, etc.) Many layouts combine both: Grid for page structure, Flexbox for components inside grid areas.
Why does flex-wrap not work with my items?
Why does flex-wrap not work with my items?
Ensure your container has:
- Explicit
flex-wrap: wrap(default isnowrap) - Constrained width (items won't wrap if the container expands infinitely)
- Items exceeding available space (wrapping only triggers when combined width exceeds container) In the playground, enable Mobile view to force width constraints and test wrapping behavior.
What browsers support flexbox?
What browsers support flexbox?
Flexbox is universally supported in all modern browsers since 2015. The only concerns are:
- IE11 has partial support with bugs (avoid
flex-shrink,flex-basiswithcalc()) - Older Safari needed
-webkit-prefixes (no longer required) The playground generates modern unprefixed CSS suitable for production in 2024+.
How do I center a single element both horizontally and vertically?
How do I center a single element both horizontally and vertically?
The Perfect Center preset demonstrates: set both justify-content: center (main axis) and align-items: center (cross axis). For a row direction, this centers horizontally and vertically. The item needs no special properties—center alignment comes entirely from the container.
Can I reorder flex items without changing HTML?
Can I reorder flex items without changing HTML?
Yes, using the order property. Items default to order: 0. Negative values move items earlier; positive values move them later. This is visual reordering only—screen readers and tab order follow the DOM. Use for responsive layouts (e.g., sidebar first on desktop, last on mobile) but not for accessibility-critical reordering.
Why do my flex items have different heights?
Why do my flex items have different heights?
By default, align-items: stretch makes items fill the container's cross-axis size. To prevent this:
- Set
align-items: flex-start(orcenter,flex-end) on the container - Or set
align-self: [value]on specific items The Holy Grail preset uses stretch for equal-height columns; the Navbar preset usesalign-items: centerfor consistent vertical centering regardless of content.
How do I make a flex item not shrink?
How do I make a flex item not shrink?
Set flex-shrink: 0 on the item. This is common for:
- Fixed-width sidebars that must stay visible
- Icon buttons that shouldn't compress
- Minimum-size guarantees for readability
Combine with
flex-basisfor a fixed starting size that never budges.
What is flex: 1 shorthand?
What is flex: 1 shorthand?
flex: 1 expands to flex: 1 1 0% (grow: 1, shrink: 1, basis: 0%). This makes items:
- Grow equally to fill space
- Shrink equally when tight
- Ignore content size (0% basis) for true proportional distribution
Contrast with
flex: auto(1 1 auto) which respects content size as the starting point before growing.
Can I nest flex containers?
Can I nest flex containers?
Absolutely—nesting flex containers is common and powerful. A page might use:
- Outer flex container for header/main/footer structure
- Inner flex container for navigation items
- Another inner flex for a card's image/content/footer alignment Each container establishes its own independent flex context. The playground previews single containers, but the generated CSS works seamlessly in nested structures.
Related tools
More utilities you might find handy.
Box Model Visualizer
Interactive CSS box model visualizer with real-time editing of margin, border, padding, and content dimensions
CSS Animation Generator
Generate CSS keyframe animation code
CSS Button Generator
Design and generate custom CSS button styles with live preview and instant code export.