Guide
Explore a real browser Flexbox layout and export the CSS that drives it. Configure the container, select numbered items and change how they grow, shrink, align or appear in visual order. This CSS Flexbox Playground supports one to twelve items and eight editable layout presets. Generation runs locally without sending settings to a processing service.
1Configure the flex container
Choose a direction, wrapping mode and alignment values. Set the container height from 120px to 800px, then use Gap to set both spacing axes or adjust row-gap and column-gap independently.
2Select and customize an item
Select a numbered preview item or its matching selector. Set grow and shrink from 0 to 10, basis to auto, 0–1000px or 0–100%, align-self and an integer order from -10 to 10.
3Try item counts and presets
Use one to twelve items, add an item or remove the selection. Apply a preset to replace the container and items. Resize the browser to inspect wrapping and scroll within the container when content overflows.
4Copy CSS and use the matching HTML
Copy Container CSS, Item CSS or All CSS, and apply the supplied class names to your markup. Exported rules include demo sizing and item minimums so the preview can be reproduced. Reset restores three default items.
Flexbox is a one-dimensional CSS layout model for distributing items along a main axis and aligning them across a cross axis. Setting display: flex makes the container's direct children flex items. Wrapping can produce several lines, but each line distributes its own items independently. This Visual Flexbox Builder uses native browser layout rather than calculated positions.
The selected flex-direction establishes the main axis. In the usual horizontal writing mode, row runs along the inline direction and column along the block direction; the cross axis is perpendicular. Justify-content distributes available main-axis space. Align-items controls how items sit across their line, and align-self can override that alignment for a particular item.
Choose row, row-reverse, column or column-reverse. Reverse changes the visual starting direction without reversing the HTML source. Item numbers in this editor identify stable DOM positions and class names. A negative or positive order can also change visual placement. Keyboard navigation and screen-reader reading order remain tied to the DOM, so use source order that makes sense independently of presentation.
Use justify-content for flex-start, flex-end, center or one of the space distribution values along the main axis. Align-items supports stretch, flex-start, flex-end, center and baseline across the line. For simple two-axis centering, set justify-content and align-items to center. Stretch depends on automatic cross sizing, while baseline alignment depends on the contents' text baselines.
nowrap keeps items on one line even when they must shrink or overflow. wrap permits extra lines, and wrap-reverse reverses the cross-axis stacking of those lines. Align-content distributes lines within the container when wrapping and spare cross-axis space make it relevant; it has no effect on a nowrap container. Use the wrapped presets, enough items and a sufficiently tall container to compare multiple-line spacing. A wrap setting alone does not guarantee that items actually occupy multiple lines.
All three spacing controls support 0px to 100px. Gap sets both axes at once, while subsequent row-gap or column-gap edits override one axis. The export writes those longhands after the shorthand to preserve the result. Row-gap measures spacing between rows and column-gap between columns; their relationship to items versus flex lines changes with flex-direction. Alignment distribution can add space beyond the explicit gap.
Flex-basis is an item's starting main-axis size before free space is distributed. Auto uses intrinsic sizing; pixels and percentages provide explicit starting sizes. Percentage basis needs a definite main size, supplied vertically here by the container height. Grow distributes positive free space by factors. Shrink distributes negative free space using factors weighted by basis size, subject to item minimums. The exported demo items use min-width: 0 and a 64px minimum height, which can constrain shrinking in a column.
Choose Flexbox when the primary relationship is a row or column, such as a navigation bar, aligned controls or a vertical stack. CSS Grid is often a better fit when rows and columns need coordinated tracks. Wrapped flex lines do not automatically share column widths. This tool generates Flexbox rules only and does not create Grid templates.
Responsive Card Row combines wrapping, a 220px basis and grow so cards can fill the available line. Equal Width Columns uses a zero basis with equal grow factors for three columns. Wrapped Tags uses intrinsic item sizes and wrapping. Horizontal Navigation keeps one line and may scroll on narrow containers. The preview follows the actual available width; no separate mobile layout approximation or automatic media query is generated.
Container CSS includes a fixed height, full width, padding, overflow and preview appearance. Item CSS includes shared demo styles and a separate rule for every numbered item. Matching HTML uses those same class names in DOM order. The first three copy buttons export only CSS, so combine the output with your own markup or the supplied example. Removing items discards their settings; remaining numbers stay stable, and new items append after them.
- Centering content along both axes
- Comparing navigation spacing and alignment
- Testing a wrapped card row at different widths
- Understanding how grow, shrink and basis interact
- Inspect actual browser Flexbox behavior with validated container and item controls.
- Keep DOM order intact while testing reverse directions and order values.
- Edit one to twelve items with stable class names.
- Copy separate container rules, all item rules or the complete stylesheet locally.
What is CSS Flexbox?
It is a one-dimensional layout model for arranging direct children along a main axis with cross-axis alignment. Wrapped lines still distribute their items independently.
How do I center an element using Flexbox?
Set display: flex on the parent, then set justify-content: center and align-items: center. The Center Everything preset demonstrates this with one item and a fixed-height container.
What is the difference between justify-content and align-items?
Justify-content distributes items along the main axis. Align-items controls their alignment across the flex line. Flex-direction determines which physical direction each axis follows.
How does flex-direction work?
row and column choose the main axis. row-reverse and column-reverse reverse visual placement along it. They do not change source order, keyboard navigation order or screen-reader reading order.
What does flex-wrap do?
wrap allows more flex lines when items do not fit the main axis. nowrap keeps one line, and wrap-reverse reverses cross-axis line stacking. A wrapped container can still fit all its items on one line.
How do I create equal-width columns?
Set equal flex-grow values and a zero flex-basis for the items, with suitable minimum sizes. The Equal Width Columns preset uses grow 1, shrink 1 and basis 0px for three items.
What is flex-grow?
It is a nonnegative factor that determines an item's share of positive free space. It does not directly set a percentage width. This editor supports factors from 0 to 10.
What is flex-basis?
It sets the starting main-axis size used by the flex sizing algorithm. Choose auto, a pixel value or a percentage. A definite main-axis container size is needed for percentage sizing to resolve as intended.
When should I use Flexbox instead of CSS Grid?
Flexbox is useful for layouts centered on one row or column, such as navigation and aligned controls. Grid can better coordinate two-dimensional rows and columns. Choose based on how the content should align.
Is the CSS Flexbox Generator free?
Yes. The native preview, item controls, presets and all CSS copy actions are free without signup.