CSS Flexbox Generator
Start from 6 everyday layouts like navbar or wrapping cards, or set direction, wrap, justify, align and gap yourself, then copy the CSS and HTML.
Reviewed 23 November 2026 · Free · No account needed
How to use
- Pick a common layout such as Center anything, Navbar or Wrapping cards, or start from the defaults.
- Pick the flex-direction and flex-wrap, then choose how items are spaced with justify-content and aligned with align-items.
- Drag the gap and the number of items and watch the preview change as you go.
- Set flex-grow, flex-shrink and flex-basis to size the items, or leave them at the defaults.
- Press Copy CSS or Copy HTML, and turn on Include default values if you want every property written out.
Example
Input: Row, justify space-between, align center, gap 12px
Output: .container { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
How it works
The tool keeps your choices in one object, draws the preview from them with inline styles, and builds the CSS text from the same object. Properties that equal the browser default are left out, so the output stays short, unless you ask for every property.
Container: display: flex plus flex-direction, flex-wrap, justify-content, align-items, align-content and gap. Item: flex: grow shrink basis. justify-content works along the main axis, which is the direction, and align-items works on the cross axis.
Limits and edge cases
- All items share one set of flex-grow, flex-shrink and flex-basis values. Per-item order and align-self are not generated.
- The preview and the HTML show 1 to 24 items. The gap goes up to 100 px, grow and shrink up to 10, and basis up to 600 px.
- Only the container rule and one item rule are written. Media queries and vendor prefixes are not added.
- The align-content line is written only when wrapping is on, because it does nothing on a single line.
- The default item value is 0 1 auto. When you leave it, no .item rule is written at all.
- align-content only matters when items wrap onto more than one line, so it is hidden from the output while flex-wrap is nowrap.
- In a column direction the main axis runs down the page, so justify-content spaces items vertically and align-items works sideways.
- The flex shorthand flex: 1 means 1 1 0%. To get the same effect here, set grow to 1 and basis to 0 px.
Privacy
Everything is generated in this browser tab. Nothing you set is sent to a server or stored.
About this page
Written and reviewed by Toolnexo on 23 November 2026. The limits above describe the published tool, not an idealised version of it. If a result looks wrong or the page is unclear, email [email protected] with the tool URL and what you entered. Corrections are published here.
Guides that use CSS Flexbox Generator
Related tools
Questions about CSS Flexbox Generator
What is the difference between justify-content and align-items?
justify-content places items along the main axis, which is the direction of the row or column. align-items places them on the cross axis, across that direction. In a row, justify-content works left to right and align-items works top to bottom. In a column the two swap.
When does align-content work?
Only when items wrap onto more than one line, because it spaces the lines themselves. With flex-wrap set to nowrap there is a single line, so align-content has no effect, and this tool leaves the line out of the CSS.
How do I make items share the space equally?
Give every item flex-grow 1 and a flex-basis of 0. The shorthand flex: 1 does exactly that, since it stands for 1 1 0%. Set grow to 1 and basis to 0 px here to see it in the preview.
Does gap work in flexbox?
Yes. The gap property works in flex containers in current versions of the major browsers, and it spaces the items without adding margin before the first or after the last item.
Should I use flexbox or grid?
Flexbox lays items out in one direction, a row or a column, and suits toolbars, menus and card rows. Grid lays items out in rows and columns together, and suits whole page layouts and galleries. They work well together.
Is anything uploaded?
No. The CSS and HTML are built in your browser from the options you pick, and nothing is sent anywhere.