How to Use the CSS Flexbox Generator: Steps and a Worked Example

By 1 min read

Generate a flexbox container rule from direction, alignment and gap. This guide shows what to enter, a worked example, and the limits to keep in mind. The CSS Flexbox Generator tool is free, needs no account and runs in your browser.

What you need

  • Direction: choose row, column, row-reverse, column-reverse
  • Justify content (main axis): choose center, flex-start, flex-end, space-between, space-around, space-evenly
  • Align items (cross axis): choose center, stretch, flex-start, flex-end, baseline
  • Gap (px), for example 16

Step by step

  1. Open the CSS Flexbox Generator tool.
  2. Choose Direction.
  3. Choose Justify content (main axis).
  4. Choose Align items (cross axis).
  5. Fill in Gap (px).
  6. Read the result, which updates as soon as the inputs change.

Worked example

With these inputs:

  • Direction: row
  • Justify content (main axis): center
  • Align items (cross axis): center
  • Gap (px): 16

the tool returns:

.container {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 16px;
}

A second example

Changing Gap (px) 16 to 32 gives:

.container {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 32px;
}

Comparing two runs like this is a quick way to see how much each input moves the result.

How it works

Choose the direction, how items are spaced along it and how they align across it, then copy the CSS.

Things to keep in mind

Check your inputs, units and any local rules before you rely on the result.

If this is not quite what you need, try CSS Border Radius Generator, CSS Box Shadow Generator or CSS Color Extractor.

More from the blog