CSS Flexbox Playground
Interactive CSS Flexbox playground with live visual preview, per-item controls, real-world layout presets (Holy Grail, Card Grid, Navbar, Modal), and one-click CSS export. Learn flex-direction, justify-content, align-items, gap, and more by experimenting in real time.
Your ad blocker is preventing us from showing ads
MiniWebtool is free because of ads. If this tool helped you, please support us by going Premium (ad‑free + faster tools), or allowlist MiniWebtool.com and reload.
- Allow ads for MiniWebtool.com, then reload
- Or upgrade to Premium (ad‑free)
About CSS Flexbox Playground
The CSS Flexbox Playground is an interactive learning environment and code generator for the modern CSS Flexible Box Layout module. Adjust container properties (flex-direction, justify-content, align-items, gap) and per-item properties (flex-grow, flex-shrink, flex-basis, align-self, order) and watch your layout update in real time. When you have something you like, copy ready-to-paste CSS and HTML straight into your project.
What is CSS Flexbox?
CSS Flexbox (Flexible Box Layout) is a one-dimensional layout model designed to distribute space along a single axis (a row or a column) and align items within a container. It replaces older techniques like floats and inline-block hacks for navbars, card rows, centered content, and any UI where elements need to flex naturally to their container. Unlike CSS Grid, which is two-dimensional, Flexbox excels at simpler arrangements where you control alignment in only one direction at a time.
How to Use This Playground
- Pick a preset (optional): Choose Holy Grail, Card Grid, Navbar, Hero, Modal, or Sticky Footer to load a real-world starting point. Each preset is a complete working layout you can study or modify.
- Adjust container properties: Use the segmented controls in the right panel to set
flex-direction,flex-wrap,justify-content,align-items,align-content, andgap. The visual stage updates immediately. - Edit individual items: Click any item in the preview to select it. Override its
order,flex-grow,flex-shrink,flex-basis, andalign-selfindependently of the rest. Items with overrides are marked with a small badge. - Add or remove items: Use Add Item and Remove Selected to change the item count and see how the layout responds.
- Copy the code: The Generated Code section at the bottom always reflects your current layout. Copy CSS, HTML, or both with one click.
Container Properties Reference
The flex container is the parent element with display: flex. These properties control how all of its children behave together.
| Property | Values | Effect |
|---|---|---|
flex-direction |
row · row-reverse · column · column-reverse |
Sets the main axis direction. row arranges items left-to-right (default); column stacks them vertically. |
flex-wrap |
nowrap · wrap · wrap-reverse |
Controls whether items stay on one line or wrap onto multiple lines when space runs out. |
justify-content |
flex-start · center · flex-end · space-between · space-around · space-evenly |
Aligns items along the main axis. Distributes free space to the sides or between items. |
align-items |
stretch · flex-start · center · flex-end · baseline |
Aligns items along the cross axis (perpendicular to the main axis). |
align-content |
stretch · flex-start · center · flex-end · space-between · space-around |
Aligns wrapped lines along the cross axis. Only takes effect when items wrap onto multiple lines. |
gap |
length, e.g. 8px, 1rem |
Sets the gutter between flex items. Replaces the older margin-based spacing pattern. |
Item Properties Reference
These properties go on individual flex items (children of a flex container) and override the container's defaults for just that item.
| Property | Values | Effect |
|---|---|---|
order |
integer (default 0) |
Reorders items visually without changing the HTML. Lower numbers render first; negative values move items to the start. |
flex-grow |
number (default 0) |
Defines how much of the container's free space this item should absorb relative to siblings. 1 on every item splits space equally. |
flex-shrink |
number (default 1) |
Defines how much an item can shrink when there is not enough room. 0 means never shrink — the item keeps its declared size. |
flex-basis |
auto · length · percentage |
Sets the initial size of an item before free space is distributed. Effectively sets the item's "ideal" main-axis size. |
align-self |
auto · same as align-items |
Overrides the container's align-items for a single item. |
What is the Difference Between justify-content and align-items?
justify-content controls alignment along the main axis, while align-items controls alignment along the cross axis. The main axis is whichever direction flex-direction sets — horizontal for row, vertical for column. When you change flex-direction from row to column, the two axes swap, so justify-content becomes vertical and align-items becomes horizontal. This swap is one of the most common sources of confusion when people learn Flexbox; the playground's axis indicators below the preview help make it visible.
How Do I Center an Element with Flexbox?
To center a single element both horizontally and vertically:
display: flex;justify-content: center; /* horizontal */align-items: center; /* vertical */
This is the modern replacement for older centering hacks involving margin: auto, transform: translate(-50%, -50%), or position: absolute. Try it in the playground by selecting the Modal Center preset.
Real-World Layout Presets Explained
Holy Grail Layout
The classic three-column page layout: left sidebar, main content, right sidebar — with a header and footer. Historically very hard to build with floats; Flexbox makes it trivial. The middle column uses flex: 1 so it absorbs all the remaining horizontal space while the side columns stay at their declared widths.
Card Grid
A wrapping row of cards that flow onto new lines as the viewport narrows. Uses flex-wrap: wrap with each card given flex: 1 1 240px, meaning the card grows and shrinks but never gets narrower than 240px.
Navbar
A horizontal navigation bar with a logo on the left and links on the right. The trick is justify-content: space-between with the logo and link group as the two children, plus an internal flex container for the links themselves.
Hero Section
Vertical stack with content centered both horizontally and vertically — perfect for landing-page hero areas. Uses flex-direction: column, justify-content: center, and align-items: center on a tall container.
Modal Center
A modal dialog perfectly centered within its overlay. The same three-line centering recipe shown above, applied to a full-screen overlay container.
Sticky Footer
A footer that sits at the bottom of the viewport when content is short, but pushes down when content is long. Achieved by giving the body display: flex; flex-direction: column; min-height: 100vh and the main content flex: 1.
What is the Difference Between flex-grow, flex-shrink, and flex-basis?
These three properties (combined into the shorthand flex) describe how an item handles space:
flex-basissets the item's ideal size before any free space is distributed. Think of it as the item's "starting point."flex-growsays "if there's leftover space, take this share of it." A value of0means refuse to grow;1means grow proportionally;2means take twice the share of an item with1.flex-shrinksays "if there's not enough space, shrink by this share." Default is1(shrink proportionally);0means refuse to shrink.
The shorthand flex: 1 expands to flex: 1 1 0% — equal grow, equal shrink, zero basis — meaning all items take an equal share of the container regardless of content. flex: auto expands to flex: 1 1 auto, which respects the content size as the basis.
When Should I Use Flexbox vs Grid?
Use Flexbox for one-dimensional layouts where items flow in a single direction — a row of buttons, a navbar, a single column of cards. Flexbox is content-aware and great when you want items to size themselves.
Use CSS Grid for two-dimensional layouts where you need to control both rows and columns simultaneously — full page layouts, image galleries, dashboards. Grid is layout-aware and lets you place items into named tracks.
The two are complementary, not competing. Many real designs combine them: a Grid page layout with Flexbox navbars and card rows inside.
Tips for Mastering Flexbox
- Visualize the axes. Always know which direction is "main" and which is "cross" — the playground's axis pills make this explicit.
- Use
gapinstead of margins. Modern browsers fully supportgapon flex containers and it eliminates the need for awkward margin tricks on the last child. - Reach for
flex: 1. When you want items to share space equally, this shorthand is almost always what you want. min-width: 0on flex items. Items have an implicit minimum width based on their content. If long unbreakable strings (like URLs) make your layout overflow, setmin-width: 0on the item to override this.- Avoid percentage-only widths. Mixing percentage widths with
flex-growcan produce surprising results. Preferflex-basiswith a sensible default.
Browser Support and Compatibility
CSS Flexbox is supported in every modern browser including Chrome, Firefox, Safari, Edge, and all major mobile browsers. The gap property in flex containers reached universal browser support in 2021. Older legacy browsers (IE10/11) require vendor prefixes and have several well-documented bugs; for those audiences, consider flexbugs.
Frequently Asked Questions
Why is my flex item overflowing the container?
Flex items have an implicit min-width: auto based on their content. Long words, code blocks, or pre-formatted text can force an item to be wider than the container. Fix it by setting min-width: 0 on the item (or min-height: 0 for column layouts).
What's the difference between space-between, space-around, and space-evenly?
space-between puts no space at the ends and equal space between items. space-around puts half a gap at each end and full gaps between items. space-evenly puts equal space at the ends and between items. Toggle them in the playground to feel the difference.
Can I animate flex properties?
Yes. flex-grow, flex-shrink, flex-basis, order, and gap can be transitioned. Animating flex-direction, justify-content, and align-items is not supported because they are discrete enumerated properties.
Does the playground work offline?
All Flexbox calculation happens in your browser using native CSS. Once the page is loaded, you can use the playground without an internet connection — there are no API calls or server-side computation.
Is the generated code production-ready?
Yes. The exported CSS uses standard properties supported in every evergreen browser. The HTML uses semantic class names (flex-container, flex-item) you can rename to fit your project's conventions.
Additional Resources
- CSS Flexible Box Layout - MDN
- CSS Flexible Box Layout Module Level 1 - W3C Specification
- CSS Flex Box Layout - Wikipedia
Reference this content, page, or tool as:
"CSS Flexbox Playground" at https://MiniWebtool.com/css-flexbox-playground/ from MiniWebtool, https://MiniWebtool.com/
by miniwebtool team. Updated: Apr 25, 2026
Related MiniWebtools:
Webmaster Tools:
- CPC Calculator
- CPM Calculator
- CSS Compressor
- Favicon Generator New
- Google AdSense Calculator
- Cron Job Generator
- Crontab Expression Generator New
- HTML Compressor
- HTML to Text Converter
- Keyword Density Checker New
- Markdown Table Generator
- Meta Tag Generator
- Smart Quotes Remover
- URL Slug Generator
- Value of A Page View Calculator
- Value of A Visitor Calculator
- Unix Permission Calculator (chmod)
- HTML Entity Encoder/Decoder
- Lorem Ipsum Generator New
- JSON String Escape/Unescape
- cURL to JSON Converter New
- SQL Formatter New
- SVG Optimizer New
- Htaccess Redirect Generator New
- Googlebot Crawl Size Checker New
- Robots.txt Generator New
- XML Sitemap Generator New
- Domain Age Checker New
- Open Graph Checker New
- WHOIS Lookup New
- DNS Lookup New
- Page Speed Checker New
- Domain Trust Checker New
- Redirect Checker New
- Hreflang Tag Generator New
- Broken Link Checker New
- CSS Flexbox Playground New