X Xerobit

Flexbox Generator

Visual CSS Flexbox playground. Adjust direction, wrap, justify-content, align-items, align-content, and gap. See the layout live, copy the CSS.

Live preview
CSS output
 

Flexbox in 60 seconds

Flexbox arranges items along one main axis. The container (set display: flex) decides how items are laid out; each item can override with its own properties.

How to use the Flexbox Generator

Getting a working flexbox layout takes three steps:

  1. Set direction. Choose flex-direction: row lays items out horizontally (the default), column stacks them vertically. Add -reverse to flip the order.
  2. Configure alignment. Use justify-content to space items along the main axis and align-items to align them on the cross axis. Toggle flex-wrap if items should wrap onto a new line instead of overflowing.
  3. Copy the CSS. Click the copy button. The generator outputs only the container properties — paste into your stylesheet and you're done.

Flexbox properties cheat sheet

Every flexbox container and item property, with the values you'll actually use:

PropertyValuesWhat it does
flex-directionrow, row-reverse, column, column-reverseMain axis direction
flex-wrapnowrap, wrap, wrap-reverseWhether items wrap to next line
justify-contentflex-start, flex-end, center, space-between, space-around, space-evenlyAlign along main axis
align-itemsflex-start, flex-end, center, stretch, baselineAlign along cross axis
align-contentflex-start, flex-end, center, space-between, space-around, stretchAlign wrapped rows
gapany length valueSpace between flex items
flex-grownumber (default 0)How much item grows to fill space
flex-shrinknumber (default 1)How much item shrinks when space is tight
flex-basisauto, lengthInitial size before grow/shrink

Flexbox centering — the most common use case

Centering an element used to require negative margins or absolute positioning tricks. With flexbox, it's two properties on the parent:

/* Perfect center (horizontal + vertical) */
display: flex;
justify-content: center;
align-items: center;

/* Center in full viewport */
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;

The key point: the parent holds the flex properties. You do not add anything to the child element to center it — the container handles all alignment.

Flexbox vs CSS Grid

Both are modern layout systems, but they solve different problems:

In practice you'll use both. Use Grid for the top-level page shell, then Flexbox inside each component. Try the CSS Grid Generator for two-dimensional layouts.

Frequently asked questions

Why isn't flexbox centering my element?

The parent element needs display: flex. The child is centered by the parent's justify-content and align-items settings — not by anything on the child itself. If centering isn't working, check that you've added display: flex to the container, not the item you're trying to center. Also make sure the container has enough height for vertical centering to be visible.

What does flex: 1 mean?

flex: 1 is shorthand for flex-grow: 1; flex-shrink: 1; flex-basis: 0%. It tells the item to grow and fill all available space equally with its siblings. If three flex items all have flex: 1, they each take up one third of the container. It's one of the most useful single-line flexbox patterns for equal-width columns.

When should I use flex-wrap: wrap?

Use flex-wrap: wrap when items should flow onto a new line instead of overflowing the container or shrinking below their natural width. It's essential for responsive card grids and tag lists where you want items to reflow on smaller screens. Without it, all flex items stay on one line and can overflow or compress to fit.

Common flexbox patterns

These layouts come up constantly in real projects. Each one is a few lines of CSS:

Sticky footer

Make the main content push the footer to the bottom of the viewport even when there isn't enough content to fill the page. Set display: flex; flex-direction: column; min-height: 100vh on the body or page wrapper, then add flex: 1 to the main content area. The footer stays at the bottom without absolute positioning.

Equal-height cards

Flexbox makes all sibling items stretch to the same height by default — align-items: stretch is the initial value. Put a row of cards in a flex container and they'll automatically match the tallest card's height. No JavaScript, no extra markup, no fixed height values needed.

Responsive navbar

A typical navbar uses display: flex; justify-content: space-between; align-items: center to push the logo to the left and the navigation links to the right. On smaller screens, switch to flex-direction: column inside a media query to stack items vertically for a mobile menu layout.

When to nest flexbox and grid

For a header / sidebar / main / footer layout, use CSS Grid for the outer page shell and Flexbox inside each section for component-level alignment. The CSS Grid Generator handles the outer layout; this flexbox generator handles alignment within each panel. Mixing them is not just acceptable — it's the recommended approach.

Flexbox browser support

Flexbox is supported in every modern browser and has been baseline-supported since 2015. You can use it without any vendor prefixes or fallbacks in production. The gap property on flex containers (not just on grid containers) arrived slightly later — it's supported in all current browsers as of 2021, so it's also safe to use. If you need to support Internet Explorer 11, gap on flex requires a polyfill or margin-based workaround, but IE11 usage is below 0.3% globally for most products and declining.

Related tools

Related articles

Further reading

Pillar

Part of Frontend & Design.


Written by Mian Ali Khalid. Last updated 2026-05-12.