CSS Flexbox Generator

Experiment with CSS flexbox properties visually. Change direction, justification, alignment, wrapping, and gap - see the layout update in real time with colored preview boxes. Copy the generated CSS and use it directly in your projects.

FAQ

You can adjust flex-direction (row, row-reverse, column, column-reverse), justify-content (start, end, center, space-between, space-around, space-evenly), align-items (stretch, start, end, center, baseline), flex-wrap (nowrap, wrap, wrap-reverse), and gap.

The preview resizes with the iframe. Try the "wrap" option and different widths to see how items reflow. The generated CSS is the container's styles - you'll need to add child item styles (flex-grow, etc.) separately.

Flexbox is for one-dimensional layouts — either a row OR a column. Use it for navigation bars, card rows, centering content, and distributing space along a single axis. Grid is for two-dimensional layouts with rows AND columns — use it for page layouts, image galleries, and complex component arrangements.

justify-content controls alignment along the main axis (horizontal by default, or vertical if flex-direction is column). align-items controls alignment along the cross axis (vertical by default). Think: justify = main axis, align = cross axis.

Flex items have an implicit min-width of auto, which prevents them from shrinking below their content size. Override this with min-width: 0 or min-height: 0 on the flex item. Also check that flex-shrink is not set to 0 on the item.

flex-basis is the flexbox-specific way to set the initial main size before growing or shrinking. width is a CSS property that doesn't interact with flex-grow/shrink in the same way. Prefer flex-basis in flex contexts for predictable behavior across browsers.

Yes. The generated CSS is standard, valid CSS. Copy it directly into your stylesheet. It produces a .container class selector, but you can rename it to match your project's class naming conventions.