What Is Flexbox?
CSS Flexbox is a layout model designed for distributing space and aligning items within a container — even when their sizes are unknown or dynamic. Before Flexbox, centering elements and creating equal-height columns required hacks with floats, tables, or absolute positioning. Flexbox solved all of that with a clean, intuitive property system.
This playground lets you experiment with the main Flexbox properties in real time: flex-direction, justify-content, align-items, flex-wrap, gap, and individual item properties like flex-grow, flex-shrink, flex-basis, order and align-self. See exactly how each property affects your layout without writing a line of code.
Key Flexbox Properties
flex-direction controls the main axis (row or column). justify-content distributes items along the main axis (flex-start, center, flex-end, space-between, space-around, space-evenly). align-items aligns items on the cross axis (stretch, flex-start, center, flex-end, baseline). flex-wrap determines whether items wrap to new lines or stay in one row.
Tips for Using Flexbox
- → Use gap instead of margins. The gap property adds consistent spacing between flex items without affecting the outer edges — cleaner than margin hacks.
- → flex: 1 makes items fill space equally. Apply flex: 1 to all children to share the free space equally; an item whose content is wider than its share stays wider unless it also has min-width: 0.
- → Use min-width: 0 to prevent overflow. Flex items won't shrink below their content size by default. Adding min-width: 0 allows them to shrink properly.
- → Combine with Grid. Use Flexbox for component-level layouts (navbars, cards, buttons) and CSS Grid for page-level layouts.
How to Use This Flexbox Playground
- Set the flex container properties — Configure flex-direction, justify-content, align-items, flex-wrap, and gap on the parent container.
- Add and remove flex items — Add child elements and see how they distribute within the container based on your settings.
- Adjust individual item properties — Set flex-grow, flex-shrink, flex-basis, and align-self on individual items to control their sizing behavior.
- Experiment with layouts — Load a layout pattern (centered content, sidebar + main, equal columns, holy grail, wrapping cards) from the Layout patterns buttons and adjust it.
- Copy the CSS — Copy the CSS for the container and every item, and the matching HTML; pasted into a page, it lays out like the preview.
Worked example: the four default items, measured
The playground starts with items 80, 100, 70 and 90 px wide and a 10 px gap. On October 12, 2026 we rebuilt that row in Chromium and read back each item's width.
| Container and settings | Item widths (px) | Why |
|---|---|---|
| 600 px, flex-grow 0 | 80 · 100 · 70 · 90 | 230 px of free space stays empty |
| 600 px, flex-grow 1 on each | 137.5 · 157.5 · 127.5 · 147.5 | Free space is split equally (+57.5 each), so items keep their size differences |
| 600 px, flex-grow 1 · 2 · 1 · 0 | 137.5 · 215 · 127.5 · 90 | Shares 1 : 2 : 1 of 230 px |
| 250 px, flex-shrink 1 on each | 51.8 · 64.7 · 45.3 · 58.2 | The 120 px shortfall is taken in proportion to each item's width |
| 250 px, flex-shrink 0 · 1 · 1 · 1 | 80 · 53.8 · 37.7 · 48.5 | Item 1 is protected; the others shrink more |
- flex-grow adds space, it does not set widths. Equal grow values give equal extra space, not equal items. For equal columns use flex: 1 1 0 (basis 0), so all the space is shared.
- "stretch" needs auto heights. The default items have fixed heights, so align-items: stretch looks the same as flex-start: in Chromium they stayed 80, 60, 100 and 70 px tall. With height auto they all stretched to the 300 px container. Turn on the auto-height option on an item to see stretch work.
- Shrink is weighted by size. A wide item gives up more pixels than a narrow one with the same flex-shrink, and nothing shrinks below its min-content width (long words, images) unless you set min-width: 0.
- order changes the picture, not the reading order. Screen readers and the Tab key still follow the HTML order (Flexbox spec, WCAG 1.3.2 and 2.4.3); reorder the markup when the sequence matters.
- align-content only does something with flex-wrap: wrap and more than one line; on a single line it has no effect.
Sources
Checked on .
Frequently Asked Questions
📖 Learn More
Related Article CSS Flexbox vs Grid: When to Use Which → Related Article How to Use CSS Flexbox →Built by Derek Giordano · Part of Ultimate Design Tools