CSS Flexbox Generator

Build flexbox layouts visually. Toggle container properties, customize individual items, and see colored boxes rearrange in real-time. Copy the generated CSS or Tailwind classes with one click.

Container Properties

display: flex

Item Properties

Click an item in the preview to select it and customize its individual flex properties.

Preview

Click an item to select it
1
2
3
4
5
.container {
  display: flex;
  gap: 10px;
}
Flexbox Cheat Sheet

flex-direction

row (default): items flow left to right. column: items flow top to bottom. -reverse variants flip the direction.

justify-content

Aligns items along the main axis. flex-start: pack to start. center: center items. space-between: equal space between items. space-around: equal space around items. space-evenly: truly equal spacing.

align-items

Aligns items along the cross axis. stretch (default): fill the container. center: center on the cross axis. baseline: align text baselines.

flex-wrap

nowrap (default): all items on one line, may overflow. wrap: items wrap onto new lines. wrap-reverse: items wrap in reverse order.

align-content

Only applies when wrapping is on. Controls how multiple lines are distributed on the cross axis. Works like justify-content but for wrapped lines.

Item properties

order: controls visual order (lower values come first). flex-grow: how much an item should grow relative to siblings. flex-shrink: how much an item should shrink. flex-basis: initial size before growing/shrinking. align-self: overrides align-items for one item.

100% client-side. Nothing is sent to any server.

What Is CSS Flexbox?

CSS Flexbox (Flexible Box Layout Module) is a CSS layout model designed for distributing space and aligning content within a container. Unlike older layout techniques that relied on floats and clearfixes, Flexbox treats layout as a first-class concern. You set display: flex on a container, and its children become flex items that you can position, align, and size with intuitive properties.

Flexbox operates along a main axis (set by flex-direction) and a cross axis (perpendicular to the main axis). This one-dimensional model makes it ideal for navigation bars, card rows, form layouts, centering content, and any arrangement where items flow in a single direction. Flexbox has 99.5% global browser support and has been widely supported since approximately 2015, making it a safe choice for production CSS.

How to Use This Flexbox Generator

Step 1: Set container properties. Use the controls panel on the left to choose flex-direction, justify-content, align-items, and flex-wrap. The preview updates instantly as you toggle each option.

Step 2: Adjust gap and item count. Slide the gap control to add spacing between items. Add or remove items with the item count slider to match your real layout needs.

Step 3: Customize individual items. Click any colored box in the preview to select it. Set per-item properties like order, flex-grow, flex-shrink, flex-basis, and align-self to see how they affect that specific item.

Step 4: Copy the code. Switch between CSS and Tailwind tabs in the code output, then click Copy to get the generated code. Paste it directly into your project.

Key Features

Live visual preview. Colored boxes rearrange in real-time as you toggle properties. No generate button, no page reload. You see exactly how your flexbox layout behaves as you build it.

Complete property coverage. Every major flexbox container property is supported: flex-direction, justify-content, align-items, flex-wrap, align-content, and gap. Per-item properties include order, flex-grow, flex-shrink, flex-basis, and align-self.

CSS and Tailwind output. Get clean, production-ready code in either vanilla CSS or Tailwind utility classes. The CSS output only includes properties that differ from defaults, keeping your code minimal.

Per-item customization. Click any item to select it and configure its individual flex properties. This helps you understand how flex-grow, flex-shrink, and align-self interact with the container settings.

Built-in cheat sheet. Expand the collapsible reference below the code output for a quick reminder of what each property does, without leaving the tool.

Flexbox Properties Explained

flex-direction sets the main axis. row (default) lays items out left-to-right. column stacks them top-to-bottom. The -reverse variants flip the starting point.

justify-content controls how items are distributed along the main axis. space-between puts equal space between items with no space at the edges. space-evenly distributes space so all gaps, including edges, are identical.

align-items positions items on the cross axis. stretch (default) makes items fill the container height. center vertically centers them. baseline aligns items by their text baselines.

flex-wrap determines whether items wrap onto new lines. When wrapping is enabled, align-content controls how the wrapped lines are distributed on the cross axis.

gap adds consistent spacing between items without margins. It applies between items only, not at the container edges. Introduced in CSS3, gap for flexbox is now supported in all modern browsers.

flex-grow / flex-shrink / flex-basis form the shorthand flex property. Together they control how items expand, contract, and what their initial size is before the flex algorithm distributes space.

Pro Tips

Center Anything
Set justify-content: center and align-items: center on a flex container to perfectly center any element both horizontally and vertically.
Sticky Footer
Use flex-direction: column on the body/wrapper, then flex-grow: 1 on the main content area to push the footer to the bottom.
Equal-Width Items
Set flex: 1 on all items to make them share space equally, regardless of their content width.
Gap Over Margins
Prefer the gap property over margins. It only applies between items, not at the edges, and avoids the collapsing margin problem.

Frequently Asked Questions

What is CSS Flexbox?
CSS Flexbox (Flexible Box Layout) is a one-dimensional layout model that distributes space among items in a container. It handles alignment, spacing, and ordering of elements along a single axis (row or column). Flexbox makes it easy to build responsive navigation bars, card grids, centered content, and complex page layouts without floats or positioning hacks.
When should I use Flexbox vs CSS Grid?
Use Flexbox for one-dimensional layouts — a row of buttons, a navigation bar, centering a single element, or distributing items along one axis. Use CSS Grid for two-dimensional layouts where you need control over both rows and columns simultaneously, like a page layout with header, sidebar, main content, and footer. Many layouts benefit from combining both: Grid for the page structure, Flexbox for component-level alignment.
What browser support does Flexbox have?
Flexbox has 99.5% global browser support as of 2025. Every modern browser — Chrome, Firefox, Safari, Edge, Opera, and all mobile browsers — fully supports the flexbox specification. You no longer need vendor prefixes for any flexbox property. Internet Explorer 11 had partial, buggy support, but IE usage is now negligible.
How does justify-content differ from align-items?
justify-content distributes items along the main axis (horizontal in a row, vertical in a column). align-items aligns items along the cross axis (vertical in a row, horizontal in a column). Think of justify-content as controlling horizontal spacing in a row layout, and align-items as controlling vertical alignment of items within that row.
What does flex-grow do?
flex-grow determines how much a flex item should grow relative to other items when there is extra space in the container. A value of 0 (default) means the item won't grow. A value of 1 means it will take its share of available space. If one item has flex-grow: 2 and another has flex-grow: 1, the first item gets twice as much extra space.
Can I generate Tailwind classes with this tool?
Yes. Switch to the Tailwind tab in the code output panel to see the equivalent Tailwind CSS utility classes for your flexbox layout. The tool translates flex-direction, justify-content, align-items, gap, wrap, and all per-item properties into their corresponding Tailwind classes.

Related Tools

Last updated: March 2026