Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

CSS Flexbox Generator & Playground

Try every flexbox property on live boxes, see the result and get the code with a pass.

Free preview, no sign-upIncluded in your pass Pro tool Pro pass: ₹179 / $5.99 for 30 days On this device: nothing is sent
+3 +1 more details No uploadWorks offline once opened Design

Free preview: the live layout and the first lines of its CSS and HTML (up to 20); copy and downloads need a pass. Locked until you unlock it: download and copy.

Pro pass ₹179 for 30 days or ₹79 for 1 week, one‑time. Pro pass $5.99 for 30 days or $2.99 for 1 week, one‑time. How to unlock

Try before you buy.

  • Free preview: the live layout and the first lines of its CSS and HTML (up to 20); copy and downloads need a pass.
  • Locked until you unlock it: download and copy.
  • Unlock: Pro pass, ₹179 for 30 days or ₹79 for 1 week, a one-time payment unless you choose automatic renewal. Unlock: Pro pass, $5.99 for 30 days or $2.99 for 1 week, a one-time payment unless you choose automatic renewal.

Ways to unlock shows how to get the full result.

See passes (opens in a new tab)

Printing this result is locked in the free preview.

Preview

100%

Container

flex-direction
flex-wrap
justify-content
align-items
Positions several lines; it needs flex-wrap.
px
px

Items

auto, content, 0, px or %
Empty = auto (stretches)

Why this size?

    Code

     

    Next steps Done. What next?

    Start over

    A Pro pass unlocks the full result. See passes

    All design & CSS tools

    About the CSS Flexbox Generator & Playground

    Build a flexbox layout by changing it and watching it change. The container has every flex property — flex-direction, flex-wrap, justify-content, align-items, align-content and the row and column gaps — plus a width and height to try, and each live item has its own flex-grow, flex-shrink, flex-basis, order, align-self, auto margins, label length and cross size. Select an item in the preview to edit it, or change all of them at once.

    Every setting is explained in plain English next to the controls, and Why this size? shows the arithmetic the browser does for the selected item’s line: the size each item starts from, how much space is left over (or how much is missing), and how much each item grows or shrinks — using the algorithm from the flexbox specification, checked against what your browser actually drew. Start from presets such as perfect centring, a navigation bar, equal columns, sidebar and content, wrapping cards and tags, a sticky footer or a media object, and get the container and item CSS, the HTML or the Tailwind classes.

    Without a pass, the free preview shows the live layout with its explanations and the first lines of its CSS and HTML (up to 20); the rest of the code, copying it and downloading it need a Pro pass.

    How to use it

    1. Pick a preset, or start with the simple row.
    2. Under Container, choose the direction, wrapping, justify-content, align-items and align-content, and set the gaps. The explanations update as you go.
    3. Under Items, select an item (in the preview or by number) and set flex-grow, flex-shrink, flex-basis, order, align-self or an auto margin; tick Change all items at once to edit them together. Add or remove items with the buttons.
    4. Change the container width and height to see wrapping, shrinking and alignment react, and read Why this size?.
    5. With a Pro pass, copy or download the CSS, the HTML or the Tailwind version; the free preview shows their first lines.

    Examples

    Perfect centring
    Input
    Preset: Perfect centring
    Result
    .flex-container {
      display: flex;
      justify-content: center;
      align-items: center;
      gap: 12px;
      min-height: 220px;
    }
    Navigation bar with the links pushed right
    Input
    Preset: Navigation bar (item 2 has margin-left: auto)
    Result
    .flex-container > :nth-child(2) {
      margin-left: auto;
    }
    
    <div class="flex items-center gap-4 min-h-[72px]">
      <div>Item 1</div>
      <div class="ml-auto">2</div>
      …

    An auto margin takes all the spare space on its side, so everything after it moves to the end.

    How the space left over is shared
    Input
    Three items of 100px with flex-grow 1, 1 and 2 in a 600px container
    Result
    300px of space left over → +75px, +75px, +150px → 175px, 175px and 250px

    The same split the tool shows under Why this size? (with flex-shrink, the shortfall is shared by flex-shrink × starting size instead).

    Common uses

    • Building navigation bars, toolbars, button groups, card rows and form layouts.
    • Learning what justify-content, align-items and align-content do — and why align-content seems to do nothing on one line.
    • Debugging why an item will not shrink (its content sets a minimum) or why flex: 1 items are not equal (their flex-basis differs).
    • Converting a flex layout to Tailwind classes or back.

    The two axes

    A flex container lays its items out along the main axis — horizontal for flex-direction: row, vertical for column — and aligns them along the cross axis at right angles to it. justify-content works on the main axis, align-items and align-self on the cross axis, and align-content positions whole lines when items wrap onto several, so it has no effect with flex-wrap: nowrap. The -reverse directions and order change only what you see: screen readers and the Tab key still follow the HTML order, so keep it meaningful (CSS Flexbox).

    grow, shrink and basis

    Each item starts from its flex-basis (its content size for auto). When the line has room left, the space left over is shared out in proportion to flex-grow; when it is too full, the shortfall is taken in proportion to flex-shrink multiplied by the starting size (without padding and border), so wider items give up more. By default an item will not shrink below its content (its minimum size is auto); set min-width: 0 to let long text shrink and wrap or scroll. Common shorthands: flex: 1 = 1 1 0 (equal shares from zero, so equal widths), flex: auto = 1 1 auto (shares on top of the content size), flex: none = 0 0 auto (fixed).

    Auto margins and gap

    gap puts space between items and between lines, never at the outer edges, and is supported for flexbox in all current browsers. An auto margin absorbs the spare space on its side after the items have flexed, which is the simplest way to push one item to the end — such as the last links of a navigation bar — or to centre a single item with auto margins on both sides.

    Limitations

    • Items are the tool’s own boxes with a short, medium or long label; real content (images, inputs) can have other minimum sizes.
    • Why this size? explains rows; in a column the same rules apply to heights, and an auto-height column has no spare space to grow into.
    • Width and height properties of items are not edited here, except a fixed size on the cross axis; use flex-basis for the main size.

    Privacy

    On this device: nothing is sent

    Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.

    How to check that nothing is uploaded

    Frequently asked questions

    What do I get without a pass?

    Without a pass, CSS Flexbox Generator & Playground shows the live layout and the first lines of its CSS and HTML (up to 20); copy and downloads need a pass. Until you unlock it, the result can’t be downloaded or copied. A Pro, Premium or Ultimate pass, a one-time payment unless you choose automatic renewal, unlocks the full result. The pricing page lists the passes and their prices.

    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 (for example min-height: 100vh). The Perfect centring preset shows it; in Tailwind it is flex items-center justify-center.

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

    justify-content distributes items along the main axis (left to right in a row), align-items places them across it (top to bottom in a row). Change flex-direction to column and the two swap directions.

    Why are my flex: 1 items not the same width?

    Usually because one item cannot shrink below its content (its minimum size), or because the shorthand you used kept flex-basis: auto, so each item adds its share of the space left over to a different content width. flex: 1 (basis 0) gives equal widths unless content forces an item wider; add min-width: 0 to allow it to shrink.

    When should I use flexbox instead of grid?

    Flexbox is one-dimensional: it handles a row or a column whose items size themselves, which suits navigation bars, toolbars and wrapping tags. Grid is two-dimensional, for layouts where rows and columns must line up; see the CSS grid generator.

    Is anything uploaded?

    No. The layout is built and measured in your browser, and the page works offline once loaded.

    Learn more

    Lessons on MySmartCoPilot Learn that use this tool:

    Quick answers and tool search

    Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.