Free tool Flexbox generator with a live, tappable preview
Choose container properties with one tap, select any box to set its grow, shrink, basis and alignment, and narrow the preview to watch items wrap. The preview is built from the same CSS and HTML you copy, so the code behaves the same way on your page.
- Container and item properties
- Tap an item to edit it
- Runs locally
Lay it out, copy the code
The sample centers three boxes and lets the middle one grow. Tap a box in the preview to edit it.
Saved to My tools
Open the free tools page next time and it is right at the top under My tools (stored in this browser only).
You can also press Ctrl+D to bookmark this page in your browser.You can also press ⌘+D to bookmark this page in your browser.You can also tap your browser’s Share button (at the bottom in Safari) and choose Add Bookmark or Add to Home Screen.You can also open the ⋮ menu at the top right and tap ☆ to bookmark it, or choose Add to Home screen.You can also tap ··· at the top right and choose Favorite, or open it in your browser and bookmark it there.
View My toolsContainer
flex-direction
flex-wrap
justify-content
align-items
align-content
align-content appears when wrapping is on: it spaces the lines of items.
Items
A dot marks items with their own settings. The orange outline is only in the preview.
Layout presets
Item 1
auto, content, or a length such as 120px or 50%.
align-self
auto or a length such as 160px or 40%.
auto or a length such as 160px or 40%.
/* Layout */
.container {
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: center;
align-items: center;
gap: 12px;
height: 300px;
}
.item-2 {
flex: 1 1 auto;
}
/* Demo look: delete or replace with your own styles */
.container {
box-sizing: border-box;
padding: 12px;
background-color: #eef2ff;
font-family: system-ui, sans-serif;
}
.item {
box-sizing: border-box;
padding: 14px 20px;
border-radius: 8px;
background-color: #4f46e5;
color: #ffffff;
font-weight: 600;
text-align: center;
}<div class="container">
<div class="item item-1">1</div>
<div class="item item-2">2</div>
<div class="item item-3">3</div>
</div>flex flex-row flex-nowrap justify-center items-center gap-3 h-[300px]Share these inputs: the values go after the # in the link, so they never reach a server.
https://tapcub.com/tools/flexbox-generator
Done here? Try these next
Use this tool often? Save it to My tools.Saved to My tools. Find it any time at the top of the free tools page. You can also press Ctrl+D to bookmark this page in your browser.You can also press ⌘+D to bookmark this page in your browser.You can also tap your browser’s Share button (at the bottom in Safari) and choose Add Bookmark or Add to Home Screen.You can also open the ⋮ menu at the top right and tap ☆ to bookmark it, or choose Add to Home screen.You can also tap ··· at the top right and choose Favorite, or open it in your browser and bookmark it there.
Problem or suggestion?Send feedbackChat with support
Version v1.0Updated Update history
Two axes decide everything
flex-direction picks the main axis. Most properties are named after the axis they work on.
- Every container and item property
- Preview width slider to test wrapping
- CSS, HTML and Tailwind classes

justify-content
Distributes leftover space along the main axis: the horizontal one in a row, the vertical one in a column.
align-items and align-self
Position items across the other axis. stretch, the default, makes items fill the line unless they have an explicit size.
align-content
Only matters when items wrap onto several lines and the container has spare cross-axis space.
flex (grow shrink basis)
Basis is the starting size. Free space is shared by grow; overflow is removed by shrink, weighted by each item’s basis.
gap
Space between neighbouring items and between wrapped lines. It is taken off the free space before grow shares it, as in the worked example below.
The preview width slider
It changes only the preview, not your CSS. Use it to check what happens in a narrower parent: items shrink first, and with wrapping on they move to a new line once their basis no longer fits.
Flex items will not shrink below their content by default. If a long word or a wide child pushes the layout out, set min-width: 0 on that item.
From idea to markup
Pick the closest preset, then adjust.
-
1
Set the container
Choose direction and wrap, then justify and align. Gap handles spacing between items without margins.
-
2
Tune items
Tap a box and set grow, shrink and basis, or give it its own alignment, order, width or height.
-
3
Narrow the preview
Drag the width slider to see when items wrap or squeeze.
-
4
Copy CSS and HTML
Paste both. The second half of the CSS only makes the boxes visible, so replace it with your styles.
What the flex keywords mean
The four common forms, as defined in the specification.
- Items are
0 1 autounless you say otherwise - A single number such as
flex: 1sets the basis to zero, so all space is shared by ratio orderchanges visual order only; keyboard and screen reader order follow the HTMLgapworks in flex containers in all current browsers
| You write | Expands to | Behaviour |
|---|---|---|
flex: initial | 0 1 auto | content size, can shrink |
flex: auto | 1 1 auto | content size, then shares free space |
flex: none | 0 0 auto | fixed at content size |
flex: 1 | 1 1 0 | equal shares regardless of content |
How grow splits the space
A 640 px container with 12 px padding and border-box sizing, three items, a 12 px gap, and flex values of 1, 2 and 1 with a zero basis.
| Step | Calculation | Result |
|---|---|---|
| Content width | 640 − 2 × 12 padding | 616 px |
| Minus gaps | 616 − 2 × 12 | 592 px of free space |
| One share | 592 ÷ (1 + 2 + 1) | 148 px |
| Items | 148, 2 × 148, 148 | 148 · 296 · 148 px |
With flex-basis: auto instead of zero, each item first takes its content width and only the remainder is shared 1 : 2 : 1, so the final widths are no longer in that ratio.
Why a flex layout misbehaves
These come up constantly.
Items overflow
The automatic minimum size stops an item from shrinking below its content. Add min-width: 0 or let text wrap.
Vertical centering does nothing
The container has no extra height. Give it a height or min-height, then use align-items: center.
Unequal “equal” columns
flex: auto shares only the leftover space. Use flex: 1 (basis zero) for equal widths.
Reordering for everyone
order and row-reverse do not change tab order. Change the HTML when the reading order matters.
Check the layout where your visitors are
A layout that wraps nicely at your width may not at theirs.
Screen ranges of real visitors
The audience page groups visitors into nine CSS width ranges, from under 375 to 2560 and up.
Learn moreReal-user performance
LCP, CLS, INP and more from your visitors’ browsers, by page and device type.
Learn morePage-level reports
See which pages visitors land on and leave from after a layout change.
Learn moreFlexbox questions
Still have a question?
Chat with the team behind TapCub — we usually reply within a few hours on business days.
How do I center a div with flexbox?
On the parent: display: flex; justify-content: center; align-items: center; and give the parent a height. The Dead center preset shows it.
What is the difference between justify-content and align-items?
justify-content works along the main axis set by flex-direction; align-items works across it. In a column they swap on screen: justify is vertical, align is horizontal.
What does flex: 1 mean?
It is short for flex-grow: 1; flex-shrink: 1; flex-basis: 0. Items with flex: 1 share the available space equally, ignoring their content widths.
How do I make items wrap onto new lines?
Set flex-wrap: wrap and give items a basis or width, for example flex: 1 1 140px. Items drop to a new line when they no longer fit.
Should I use flexbox or grid?
Flexbox suits one line of items that size themselves, like toolbars and tags. Grid suits layouts where rows and columns must line up. They combine well.
Why does gap work but margins add up?
Gap only appears between items and lines, never at the edges, so you do not need to remove a margin from the last item.
Is anything I set sent to a server?
No. The generator runs in your browser. The share link keeps the settings after the # in the address.
Is this tool working for you?
Rate it, or tell us what went wrong and what you’d like improved. A person reads every message, and frequent requests go into the next update.
Need help right now?
Chat with our support team, best for urgent problems; you can leave a message when we are offline.
Chat with supportUpdate history
New features, fixes and data refreshes for this tool, newest first.
-
· v1.0
LaunchedFirst release.
Missing something or found an error? Tell us — requests that come up often go into the next update. All tool updates
Recommend this tool in an article or on your site
This tool is free to cite and share. Copy the URL or link below into your article, tutorial or resource page; to write a review, embed a tool or partner with us, get in touch.
https://tapcub.com/tools/flexbox-generator<a href="https://tapcub.com/tools/flexbox-generator">Flexbox generator - TapCub</a>Style what you laid out
Add depth and color, or move to a two-dimensional layout.