/* Container */ .container { display: flex; gap: 8px; padding: 16px; min-height: 160px; }
CSS Flexbox Generator — Visual Flexbox Layout Builder
What's included
Features
About this tool
Visualize Every Flexbox Property — Then Export CSS, Tailwind, or React Code
You know you need justify-content: space-between for the navbar, but you can't remember if align-items or align-content controls the vertical position, or what flex-grow: 1 actually does when one sibling has flex-grow: 2. Stop guessing — adjust each property with the visual chip controls and see the result in the live canvas immediately. The mental model builds itself from watching the items move rather than reading abstract property descriptions.
The tool covers the full flex model in two layers. Container properties — flex-direction (row or column), flex-wrap (nowrap, wrap, wrap-reverse), justify-content (six options from flex-start to space-evenly), align-items (five options from stretch to baseline), align-content (six options for multi-line containers), gap, padding, and min-height — control the overall layout. Add up to as many items as you need using the + button in the toolbar, then click any item to select it and adjust its per-item properties: flex-grow (0–6), flex-shrink (0–6), flex-basis (auto, 0, or fixed sizes), align-self (overrides the container for just this item), and order (visual reordering without touching HTML). Each property has a live label showing the current value.
When the layout looks right, switch to the export panel and copy the code in your preferred format: plain CSS with a .container rule and per-item rules only for items with non-default properties, SCSS with nested item selectors, Tailwind HTML with utility classes like flex flex-row justify-between items-center gap-4 — ready to paste into JSX without looking up a single class name, or a React inline style object. The resizable code panel lets you expand it to read longer outputs without scrolling. Everything runs 100% in your browser with no data uploaded.
Step by step
How to Use
- 1Set container direction and wrappingIn the Container section of the left panel, click the
flex-directionchip buttons to choose row (horizontal — the default) or column (vertical). If you want items to wrap onto a second line when the container is too narrow, clickflex-wrap: wrap. The live canvas reflects both settings immediately. - 2Configure main-axis and cross-axis alignmentClick a
justify-contentchip to control how items are distributed along the main axis —flex-startpacks items to the left in a row,centercenters them,space-betweenspreads them to both edges,space-aroundadds equal space around each. Then click analign-itemschip to control cross-axis alignment —centervertically centers items in a row container,stretch(default) makes items fill the container height. - 3Adjust gap, padding, and container heightDrag the
gapslider to set spacing between items (0–64px). Dragpaddingto add internal padding to the container. Dragmin-heightto control how tall the container is — this matters for testing vertical alignment. All three sliders update the live preview in real time. - 4Add or remove flex itemsUse the − and + buttons in the toolbar above the preview to remove or add flex items. The canvas reflows immediately with each addition. Items are color-coded so you can distinguish them at a glance. Click any item to select it — a selection ring highlights the chosen item and the left panel switches to show that item's individual properties.
- 5Configure per-item flex propertiesWith an item selected, the Item Properties panel shows
flex-grow(how much the item expands),flex-shrink(how much it compresses),flex-basis(its starting size — choose from auto, 0, 60px, 100px, 150px, 200px),align-self(overrides the container's align-items for this item only), andorder(visual position without changing HTML order). All changes apply to the selected item only. - 6Export in your preferred formatClick the CSS, SCSS, HTML, Tailwind, or React tab in the code panel at the bottom of the page. CSS outputs a clean
.container { display: flex; ... }rule and per-item rules only for items with non-default properties. Tailwind outputs an HTML snippet with utility classes likeflex flex-row justify-between items-center gap-4. React outputs inline style props. Click Copy to copy the output to clipboard. - 7Reset and repeatClick the ↺ Reset button in the toolbar to restore all container and item properties to their defaults. This is useful when you want to start fresh after exploring a layout. The canvas, code panel, and all controls return to the initial state with three default items and a row direction.
Real-world uses
Common Use Cases
flex flex-row justify-between items-center gap-4. Paste directly into a className prop — no Tailwind docs search needed.Got questions?
Frequently Asked Questions
justify-content aligns flex items along the main axis — horizontally for flex-direction: row, vertically for flex-direction: column. align-items aligns items along the cross axis (perpendicular to the main axis) — vertically for a row container, horizontally for a column container. A common mistake: adding justify-content: center to try to vertically center items in a row container. That's what align-items: center does.
flex-grow controls how much a flex item expands into available space relative to its siblings. flex-grow: 1 on one item and flex-grow: 2 on another means the second takes twice as much of the remaining space. flex-grow: 0 (default) means the item does not grow beyond its natural size. The most common use case: a navigation bar where one item has flex-grow: 1 to push everything else to the edges.
By default, flex-wrap is "nowrap" — items stay on one line and shrink or overflow rather than wrapping. Set flex-wrap: wrap to allow items to move to a new line when the container is too narrow. You usually also need a flex-basis on each item (e.g. 280px) to define the target size before wrapping kicks in. Without flex-basis, items won't have a reference size to trigger wrapping.
Set display: flex, justify-content: center, and align-items: center on the container, and make sure the container has an explicit height (or min-height). This is the standard CSS centering pattern — it works for a single item or multiple items.
Flexbox is for one-dimensional layouts — navbars, button groups, card rows, centering content. Grid is for two-dimensional layouts where you control rows and columns simultaneously. Most UIs use both: Grid for the overall page structure and Flexbox inside individual components.
Configure the layout using the visual controls, then click the Tailwind tab in the export panel. It generates the equivalent utility classes — for example flex flex-row justify-between items-center gap-4 — and per-item classes like grow, shrink-0, or self-end. Copy and paste directly into a className attribute.
flex-shrink: 0 prevents a flex item from shrinking below its natural size when the container is too small. The default is 1, meaning all items shrink equally. Setting flex-shrink: 0 is useful for fixed-size elements like logos, avatars, or icons that should never compress regardless of how narrow the container gets.
align-items is set on the flex container and applies to all flex children simultaneously. align-self is set on an individual flex item and overrides the container's align-items value for that specific item only. For example, a container might have align-items: center to center most items vertically, while one item has align-self: flex-end to sit at the bottom of the row. This is useful for hero sections where the text content is centered but a decorative image needs to align to the bottom edge.
gap (formerly grid-gap) adds space between flex items — it applies to the space between items only, not the outer edges of the container. gap: 16px sets equal spacing in both directions. gap: 12px 24px sets row gap (cross-axis) and column gap (main-axis) separately. Gap is now universally supported in all modern browsers and is preferred over using margin on each child because it doesn't require negative margin hacks for the first or last item. Combine with flex-wrap: wrap for responsive card grids where the spacing stays consistent as cards wrap to new rows.
Set the navbar container to display: flex; justify-content: space-between; align-items: center. The logo on the left and the link group on the right will sit at opposite ends of the row automatically. For a nav with a logo in the center, use a three-part structure with CSS grid (1fr auto 1fr) instead of Flexbox. If you want one item to push all others to the right side, give that item margin-right: auto — this causes it to consume all remaining space and push subsequent items to the far right edge.
Yes, and this is a common and recommended pattern. Use CSS Grid for the outer page structure — the header, sidebar, main content, and footer positions. Inside each grid cell, use Flexbox for the component-level layout — centering the content inside a card, distributing links in a navbar, or stacking form fields vertically. The two systems are fully composable: a grid item can be a flex container, and a flex item can be a grid container. Grid controls the large-scale layout; Flexbox handles the small-scale arrangement within each component.