Flexbox Generator: CSS, Tailwind & React Code
Build flex layouts with a live preview and 11 presets, set grow, shrink and order per item, then copy the code as CSS, Tailwind classes or React styles.
Updated November 2026
Reviewed by Rafael Duarte
Requires flex-wrap: wrap
flex
gap-4 Click an item in the preview to edit its properties.
How to use the CSS flexbox generator
From a preset to CSS, Tailwind or React code in under a minute
1. Pick a preset
Under Preset Layouts, click Navbar, Card Grid, Sidebar or one of the other presets (11 in all). It sets up the container, and the live preview and the code update right away.
2. Adjust the container and items
Tune flex-direction, justify-content, align-items — or click an item in the preview to edit its grow, shrink, and order.
3. Copy the code
Switch between the Tailwind, CSS and React tabs and click Copy. The download button always saves the CSS as flexbox.css, whichever tab is open.
What this flexbox generator does
Three code formats, plus a warning that explains itself
Tailwind, CSS and React tabs
Three tabs built from the same layout: Tailwind classes, plain CSS and a React style object. Each one covers the container plus every item you edited, so you never translate classes by hand.
11 ready-made layout presets
Navbar, Centered, Card Grid, Sidebar, Holy Grail, Footer, Form Row, Stack, Icon+Label, Pill Btns and App Shell. Presets configure the container only; you set grow, shrink and order on the items afterwards.
align-content warning
While flex-wrap is nowrap, the align-content buttons are disabled with the note "Requires flex-wrap: wrap". If a value you already picked stops applying, a warning explains why.
Per-item editing
Use 1 to 8 items and click any box in the preview to edit its flex-grow, flex-shrink, flex-basis, align-self and order. Only the items you change make it into the code, as .item-1, .item-2 and so on.
Mobile, tablet and desktop preview
Switch the preview between 375px, 768px and full width to see how the layout behaves before you copy anything.
Copy or download
Copy the code from the active tab to your clipboard, or download the CSS as a .css file.
Examples
Presets and edits, with the code they produce
When you'll reach for this
The most common scenarios developers use this generator for
Navbars
flex plus justify-content: space-between and align-items: center — logo on the left, nav links on the right, in one line.
Centering an element
The fastest way to center a div on both axes without margin hacks or absolute positioning.
Card grid rows
flex-wrap: wrap plus gap — cards reflow onto the next line automatically as the viewport shrinks.
Sidebar layouts
Apply the Sidebar preset, click the content item and set flex-grow to 1 so it fills the remaining space. The preset itself only configures the container.
Handing off React components
Grab the React tab when you need the layout as a style object for a component's style prop instead of a stylesheet.
Common mistakes
The flexbox gotchas that trip up most developers
Confusing justify-content with align-items
justify-content controls the main axis; align-items controls the cross (perpendicular) axis. Which one is 'horizontal' flips when you switch flex-direction to column.
Setting align-content without flex-wrap: wrap
align-content only has an effect once items have actually wrapped onto multiple lines — the tool flags this automatically when it applies to your layout.
Expecting order to change DOM order
order only changes the visual position of an item. Tab order still follows the source DOM, which matters for keyboard navigation and accessibility.
Why use this flexbox generator
It writes the same layout as Tailwind classes, plain CSS and a React style object in three tabs, so switching formats never means translating property by property.
The align-content warning explains why the property does nothing without flex-wrap, which cuts out the usual trial and error with that one.
Beyond the code, it simulates the layout at 375px, 768px and full width and lets you edit up to 8 items one by one right in the preview. For a page-level layout in rows and columns, the CSS grid generator is the better fit, and CSS Grid vs Flexbox explains when to reach for each.
Flexbox vs. CSS Grid
When to reach for each one
Frequently asked questions
justify-content controls the main axis — horizontal when flex-direction is row, vertical when it's column. align-items controls the cross axis, perpendicular to that. To center an element on both axes, set both properties to center.
align-content only has an effect when flex-wrap is set to wrap or wrap-reverse and there are actually enough items to wrap onto multiple lines. On a single line, use align-items instead — that's the property that governs cross-axis alignment when there's only one row.
It's shorthand for flex: 1 1 0% — the item can grow, can shrink, and starts from a zero basis. When several items share flex: 1, they split the available space evenly, ignoring their content width.
On the parent container, set display: flex; justify-content: center; align-items: center. The container needs a defined height (or needs to fill its own parent) for vertical centering to actually be visible.
order reorders items visually without touching the HTML. Every item defaults to order: 0, and lower values are placed first. It only affects visual position — tab order and screen-reader order still follow the DOM, which is worth checking for accessibility.
By default, flex items have min-width: auto (or min-height: auto in column layouts), which prevents them from shrinking past their content's natural size even with flex-shrink set. Add min-width: 0 (or min-height: 0) to the item to let it shrink further, which is especially common when text or images overflow a flex child.
Each property maps to a class: display:flex → flex, flex-direction:column → flex-col, flex-wrap:wrap → flex-wrap, justify-content:space-between → justify-between, align-items:center → items-center and gap:16px → gap-4. Build the layout here and copy the Tailwind tab. Gaps outside the default scale become arbitrary values (28px comes out as gap-[28px]), and on items flex-grow:1 becomes grow and flex-shrink:0 becomes shrink-0.
Yes. Press Shift+Enter while focus isn't on a slider, dropdown or other form field, and the code in the active tab (Tailwind, CSS or React) goes straight to your clipboard.
References
Related Tools
- Color Contrast Checker: WCAG AA/AAA & Color Blindness Design Check if text and background pass WCAG 2.2 AA and AAA, get the nearest passing text color and preview 4 types of color blindness. Free, in your browser.
- HEX to RGB Converter with HSL & CMYK Values Design Paste a HEX code and copy its RGB, HSL and CMYK values instantly, with 4 harmony colors, a contrast check against white and CSS palette export.
- Color Scheme Generator: Complementary, Triadic & Analogous Design Pick a base color and get 5 harmonious colors: analogous, monochromatic, complementary, triadic or tetradic. Preview them on a site, export CSS or JSON.
- Color Palette from Image: Extract HEX, RGB & HSL Codes Design Upload a photo or logo and extract 3 to 12 dominant colors as HEX, RGB and HSL. Export CSS variables, Tailwind, JSON or PNG. Nothing leaves your browser.
- CSS Box Shadow Generator: Tailwind, Neumorphism & Glass Design Create CSS box shadows with a live preview and ready-made presets, or switch to neumorphism and glassmorphism. Copy as CSS, a Tailwind class or a variable.