CSS Flexbox Generator

A visual interactive playground and code generator to build flexible CSS layouts with real-time feedback.

3
1
2
3
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
flex-wrap: nowrap;

About the CSS Flexbox Generator

Choose a flex direction, how items are spaced along it and how they line up across it, and copy the Flexbox CSS while the preview updates.

Everything you enter is processed in your browser; nothing is uploaded or stored.

How to use it

  1. Pick Flex Direction (row or column).
  2. Choose Justify Content and Align Items, and set the number of items.
  3. Copy the CSS snippet for your container.

The two Flexbox axes

flex-direction sets the main axis: row runs left to right, column top to bottom. justify-content spaces items along the main axis (start, center, space-between …) and align-items positions them on the cross axis (stretch, center, flex-start …).

So centring something in both directions is display: flex; justify-content: center; align-items: center; – one of the most-used snippets in CSS.

Tips

  • Switching to column swaps what justify-content and align-items control.
  • Use gap instead of margins to space flex items.

Frequently asked questions

How do I centre a div with Flexbox?

On the parent: display: flex; justify-content: center; align-items: center;.

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

justify-content works along the main axis; align-items along the cross axis.

When should I use Grid instead?

When you need rows and columns at the same time; Flexbox is for one direction.