CSSNew

Flexbox Generator with Tailwind Classes

Build flex layouts visually, tune container and item properties, and copy CSS or Tailwind classes

100% client-side — your data never leaves your browserNo data stored or uploadedFree for lifetime · No signup
Presets
Live preview (click an item to edit it)

Drag the bottom-right corner of the preview to resize it and watch wrapping and grow/shrink react.

Container
Item 1
flex-basis
CSS
.container {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
HTML
<div class="container">
  <div class="item-1">1</div>
  <div class="item-2">2</div>
  <div class="item-3">3</div>
</div>

Container properties: direction, alignment, wrap and gap

Flexbox lays out children along one axis at a time. flex-direction picks that main axis: row runs left to right, column top to bottom, and the -reverse values flip the order. Everything else is relative to it, which is the part that trips people up: justify-content always distributes items along the main axis and align-items always aligns them on the cross axis. Switch the direction to column in this flexbox generator and watch justify-content start moving items vertically.

justify-content controls leftover space on the main axis: flex-start and flex-end pack items at either end, center groups them in the middle, space-between pushes the first and last item to the edges, space-around gives each item equal space on both sides, and space-evenly makes every gap identical. align-items sets cross-axis alignment for every item; the default stretch makes items fill the container's height in a row, while center is the classic way to centre something vertically.

By default items stay on one line and shrink to fit. flex-wrap: wrap lets them break onto new lines, and only then does align-content matter, because it distributes those lines. gap sets the space between items without margins on the outer edges; separate row-gap and column-gap values are supported. Drag the corner of the preview to resize it and see wrapping happen live.

Item properties: grow, shrink, basis, order and align-self

Click any numbered box in the preview to edit it. flex-basis is the starting size before free space is shared out: auto uses the item's content or width, while a px or percentage value fixes the starting point. flex-grow decides how leftover space is divided, in proportion to each item's grow value, so an item with grow 2 takes twice the extra space of one with grow 1. flex-shrink does the same when there is not enough room; set it to 0 to stop a sidebar or icon from being squeezed. The three are written together as the flex shorthand, and that is what the CSS output uses.

order changes the visual position without changing the HTML, and align-self overrides align-items for one item. Use order with care: screen readers and keyboard focus follow the source order, not the visual one, so reordering important content can confuse people who do not use a mouse.

The presets cover common patterns: a centred box, a navbar with space-between, equal columns using flex: 1 1 0%, a fixed sidebar with a growing main area, wrapping cards, a vertical stack, and pushing the last item to the right by letting one item grow.

CSS and Tailwind output

The CSS tab writes a .container rule and only the .item-n rules that differ from the defaults, plus a matching HTML skeleton. The Tailwind tab maps every setting to real utilities rather than arbitrary values where Tailwind has one: flex-col, flex-wrap, justify-between, items-center, content-center, gap-4, flex-1, flex-none, shrink-0, basis-1/2, order-2 and self-end. Gaps that are not a multiple of 4px fall back to an arbitrary value such as gap-[10px]. For the full property list see the CSS Flexbox and Grid cheat sheet, and for two-dimensional layouts use the CSS Grid Generator.

How to use the Flexbox Generator with Tailwind Classes tool

  1. 1

    Set up the container

    Choose flex-direction, flex-wrap, justify-content, align-items and the row and column gap.

  2. 2

    Add or remove items

    Use the plus and minus buttons to change how many items are in the flex container, up to twelve.

  3. 3

    Tune individual items

    Click an item to set its flex-grow, flex-shrink, flex-basis, order and align-self.

  4. 4

    Copy the code

    Copy the CSS and HTML, or switch to Tailwind classes and copy the HTML with utilities.

Frequently asked questions

What is the difference between justify-content and align-items?

justify-content distributes items along the main axis set by flex-direction, and align-items aligns them on the cross axis. In a row, justify-content is horizontal and align-items is vertical; in a column it is the other way round.

How do I centre a div with flexbox?

Set display: flex; justify-content: center; align-items: center; on the parent, and give it a height. In Tailwind that is flex justify-center items-center. The Centered preset shows it.

What does flex: 1 mean?

flex: 1 is shorthand for flex-grow: 1, flex-shrink: 1 and flex-basis: 0%, so items share the available space equally regardless of their content. Tailwind’s flex-1 class produces the same value.

Why is align-content not doing anything?

align-content only distributes lines of items, so it has no effect unless flex-wrap is set to wrap or wrap-reverse and the items actually wrap onto more than one line.

Should I use flexbox or CSS Grid?

Use flexbox for one-dimensional layouts such as toolbars, navbars and rows of buttons, where content size drives the layout. Use CSS Grid when you need rows and columns aligned together, such as page layouts and card grids.

Related on TechLogHub

Get the next tool before you need it

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.