TapCub is live — analytics, insights and live chat, free on one platform

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.

Generator
100%

Container

flex-direction

flex-wrap

justify-content

align-items

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%.

CSS
/* 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;
}
HTML
<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>
Tailwind classes (container)
flex flex-row flex-nowrap justify-center items-center gap-3 h-[300px]
Runs entirely in your browser. Nothing you type here is uploaded or stored by TapCub.

Share these inputs: the values go after the # in the link, so they never reach a server.

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

Read the layout

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
Flexbox generator illustration: Set container and item properties visually, tap items to edit them and copy the CSS and HTML
Flexbox generator, illustrated

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.

How to use it

From idea to markup

Pick the closest preset, then adjust.

  1. 1

    Set the container

    Choose direction and wrap, then justify and align. Gap handles spacing between items without margins.

  2. 2

    Tune items

    Tap a box and set grow, shrink and basis, or give it its own alignment, order, width or height.

  3. 3

    Narrow the preview

    Drag the width slider to see when items wrap or squeeze.

  4. 4

    Copy CSS and HTML

    Paste both. The second half of the CSS only makes the boxes visible, so replace it with your styles.

Shorthand

What the flex keywords mean

The four common forms, as defined in the specification.

  • Items are 0 1 auto unless you say otherwise
  • A single number such as flex: 1 sets the basis to zero, so all space is shared by ratio
  • order changes visual order only; keyboard and screen reader order follow the HTML
  • gap works in flex containers in all current browsers
flex shorthand keywords
You writeExpands toBehaviour
flex: initial0 1 autocontent size, can shrink
flex: auto1 1 autocontent size, then shares free space
flex: none0 0 autofixed at content size
flex: 11 1 0equal shares regardless of content
Worked example

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.

Sharing 640 px between three items with flex-grow 1 : 2 : 1
StepCalculationResult
Content width640 − 2 × 12 padding616 px
Minus gaps616 − 2 × 12592 px of free space
One share592 ÷ (1 + 2 + 1)148 px
Items148, 2 × 148, 148148 · 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.

Common mistakes

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.

FAQ

Flexbox 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.

Feedback

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.

Rate this tool

Please don’t include passwords or other sensitive information.

Only used to reply to this feedback.

Type, details and email are required.

We only use this to handle your feedback. See the privacy policy.

Feedback received

Thank you! We will read it and reply from hello@tapcub.com if needed.

Need help right now?

Chat with our support team, best for urgent problems; you can leave a message when we are offline.

Chat with support
Changelog

Update history

New features, fixes and data refreshes for this tool, newest first.

  1. · 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

Cite this tool

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.

URL
https://tapcub.com/tools/flexbox-generator
HTML link
<a href="https://tapcub.com/tools/flexbox-generator">Flexbox generator - TapCub</a>

See your data clearly. Find your growth.

Every click, backed by data. Install one line of code and see your first numbers in a minute.

No credit card · Free plans for analytics and chat · Cookieless analytics