CSS Flexbox Builder
Adjust flex container properties on a live set of boxes and copy the resulting CSS.
About the CSS Flexbox Builder
Every control here maps directly onto a real CSS flex container, so the numbered boxes above rearrange exactly as the same rules would behave in a browser. Switch direction to column to see how justify-content and align-items swap axes, or add more items and turn on wrap to watch a new row form once the container runs out of space.
Why justify-content and align-items seem to "swap" when you change direction
This is the single most common point of confusion in flexbox, and dragging the direction dropdown here is the fastest way to internalize it. Flexbox always has a main axis and a cross axis, and justify-content only ever controls spacing along the main axis, while align-items only ever controls spacing along the cross axis. When flex-direction is row, the main axis runs horizontally, so justify-content moves items left-to-right and align-items moves them top-to-bottom. Switch to column and the main axis rotates to vertical, so now justify-content controls the vertical spacing and align-items controls horizontal centering instead. Nothing about the two properties actually changed, only which physical direction "main" and "cross" point in did.
Why gap is safe to use here without a vendor prefix or fallback
The gap property (formerly known as grid-gap) was originally exclusive to CSS Grid, and for years using gap inside a flex container simply did nothing in most browsers. That changed around 2020-2021, when Chrome, Firefox, and Safari all shipped flexbox support for gap within a short window of each other, it's now safe to use in any reasonably current browser without needing the older workaround of adding margin to each child and negative margin to the container to fake spacing between items.
A real limitation: no align-content control
This builder covers direction, justify-content, align-items, wrap, and gap, but it doesn't expose align-content, a separate property that only becomes visible once flex-wrap is set to wrap and the container has multiple lines of items with leftover space along the cross axis. Where align-items positions items within their own line, align-content controls how the lines themselves are spaced or packed relative to each other, similar to justify-content but for the wrapped rows as a group. If your layout wraps into several rows and you need to control the gap between those rows specifically, you'll need to add that property by hand to the copied CSS.
This builder covers the container, not the individual items
Everything here configures container-level flex properties. Item-level properties, flex-grow, flex-shrink, flex-basis (or the flex shorthand combining all three), order, and align-self, are set on the individual children rather than the container, and this tool's uniform colored boxes don't demonstrate them. In a real layout, those item-level properties are what let one specific child grow to fill remaining space, shrink before its siblings do, or override the container's align-items for just that one element.
A subtle accessibility gotcha with row-reverse and column-reverse
Setting direction to row-reverse or column-reverse visually reverses the order items appear on screen, but it does not change the underlying HTML source order, and that distinction matters for keyboard and screen reader users. Tab order and screen reader reading order both follow the DOM's actual markup sequence, not the CSS-driven visual order, so a reversed flex layout can visually show item 5 first while a keyboard user still tabs to item 1 first. If visual and logical order genuinely need to match, reorder the actual HTML elements rather than relying on a reverse direction value, especially on any layout with interactive elements like links, buttons, or form fields.
Frequently Asked Questions
Why does justify-content control vertical spacing when I switch to flex-direction: column?
justify-content always controls the main axis, and align-items always controls the cross axis. In row direction the main axis is horizontal, so justify-content moves items left-right. In column direction the main axis rotates to vertical, so justify-content now controls vertical spacing instead, the properties didn't change, only which direction counts as "main" did.
Do I need a fallback for the gap property in flexbox?
Not for any reasonably current browser. Flexbox gap support shipped in Chrome, Firefox, and Safari within a short window around 2020-2021, after which it became safe to use without the older margin-based spacing workaround.
Why isn't there an align-content control in this builder?
align-content only has a visible effect when flex-wrap is set to wrap and the container has multiple lines with extra cross-axis space, it controls spacing between those wrapped lines as a group, separate from align-items which positions items within a single line. This builder doesn't include it, so add it manually if your layout wraps into multiple rows.
Can this tool set properties like flex-grow or order on individual items?
No, this builder only covers container-level properties like justify-content and align-items. Item-level properties (flex-grow, flex-shrink, flex-basis, order, align-self) are applied to individual children and aren't demonstrated here since all the preview boxes are styled identically.
Does row-reverse change the order screen readers and keyboard navigation use?
No. row-reverse and column-reverse only change the visual display order, the underlying HTML source order stays the same, and that source order is what tab navigation and screen readers actually follow. If logical order needs to match the visual order, reorder the HTML elements themselves instead.
What's the quickest way to perfectly center items both horizontally and vertically?
Set justify-content: center and align-items: center together on the flex container. That combination centers items along both the main and cross axes simultaneously, which is one of the most common reasons developers reach for flexbox in the first place.