Items
.container
1grow·0 shrink·1
2grow·0 shrink·1
3grow·0 shrink·1
/* Container */
.container {
  display: flex;
  gap: 8px;
  padding: 16px;
  min-height: 160px;
}

CSS Flexbox Generator — Visual Flexbox Layout Builder

Updated May 14, 2026
Share & Support

What's included

Features

Container controls — flex-direction, flex-wrap, justify-content, align-items, align-content, gap
Per-item controls — flex-grow, flex-shrink, flex-basis, order, align-self
Add and remove flex items dynamically in the live preview
Live preview updates in real time with every property change
Export as CSS rule block, SCSS nesting, Tailwind utility classes, or React style object; convert to Tailwind with our CSS to Tailwind converter
Tooltip on every property label explaining what the property does
Reset to defaults in one click
100% browser-based — no data sent to a server; for two-dimensional layouts use our CSS Grid Builder

About this tool

Visualize Every Flexbox Property — Then Export CSS, Tailwind, or React Code

Runs in your browser
No install or signup
Free forever

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

  1. 1
    Set container direction and wrappingIn the Container section of the left panel, click the flex-direction chip 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, click flex-wrap: wrap. The live canvas reflects both settings immediately.
  2. 2
    Configure main-axis and cross-axis alignmentClick a justify-content chip to control how items are distributed along the main axis — flex-start packs items to the left in a row, center centers them, space-between spreads them to both edges, space-around adds equal space around each. Then click an align-items chip to control cross-axis alignment — center vertically centers items in a row container, stretch (default) makes items fill the container height.
  3. 3
    Adjust gap, padding, and container heightDrag the gap slider to set spacing between items (0–64px). Drag padding to add internal padding to the container. Drag min-height to control how tall the container is — this matters for testing vertical alignment. All three sliders update the live preview in real time.
  4. 4
    Add 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.
  5. 5
    Configure 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), and order (visual position without changing HTML order). All changes apply to the selected item only.
  6. 6
    Export 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 like flex flex-row justify-between items-center gap-4. React outputs inline style props. Click Copy to copy the output to clipboard.
  7. 7
    Reset 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

Understand what justify-content vs align-items actually does
The interaction between main-axis and cross-axis properties is hard to reason about in code. Toggle justify-content from "center" to "space-between" and align-items from "stretch" to "center" and see the live preview change immediately — building the mental model you can't get from reading MDN.
Build a navbar with logo left and links right
Set flex-direction: row, justify-content: space-between, align-items: center, and gap. The classic navigation bar pattern is ready to export as CSS or Tailwind classes in seconds — no trial and error in DevTools.
Create a responsive card row that wraps without media queries
Set flex-wrap: wrap, flex-basis: 280px on each item, and flex-grow: 1. Cards fill available width and wrap to the next line automatically at narrow viewports — no breakpoints required. Use our CSS Clamp Generator for fluid spacing between the cards.
Center content both horizontally and vertically
Add justify-content: center and align-items: center to a flex container. This builder generates that pattern instantly and shows how it responds when you add items or change the container height.
Get Tailwind flexbox classes without looking them up
Configure the layout visually, switch to the Tailwind export tab, and copy classes like flex flex-row justify-between items-center gap-4. Paste directly into a className prop — no Tailwind docs search needed.
Debug a flex layout that isn't behaving as expected
Reproduce your container and item structure here — add the same number of items, same flex-basis, same wrap settings — and adjust properties until the preview matches what you want. Then compare the generated CSS to what your stylesheet actually has. Preview the result across screen sizes with our Responsive Preview Tool.

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.