Free tools • Fresh ideas

CSS Flexbox Generator

Try direction, wrapping, spacing and alignment with three items.

Processing takes place in your browser.

How to use the CSS Flexbox Generator

Justify distributes items along the main axis, which changes with direction. Align acts across it. Avoid reverse directions to fix reading order because keyboard and assistive technology still follow the document order.

Build a toolbar with one layout rule

Start with a parent holding a title, a filter group and a primary action. Apply the generated declarations to that parent. Its direct children become flex items. If your buttons are nested in the filter group, they continue to lay out according to the rules on that group. Create a second flex container there only if those buttons also need alignment. The preview uses simple items so you can see the space the parent allocates before using the code with your own content.

Keep direction set to row for a typical horizontal toolbar. Put a modest gap between items before choosing how to distribute the rest of the space. Select start alignment to keep items together, or use space-between if the left and right groups should occupy opposite ends of the row. When the available width shrinks, distribution leaves less spare room. The gap still supplies separation. Compare the preview with a resized copy of your actual toolbar because your labels and controls determine when things fit.

Understand the two axes

Justify content distributes along the main axis. Align items controls the cross axis. When you switch to column, that main axis runs in the block direction. Centering on both axes can be useful when containing a small status panel, but the parent also needs enough size to offer spare space. If a vertically centred item stays at the top, inspect the parent's computed height. A container that is only as tall as its children has no extra vertical space to distribute.

Try changing direction while keeping justification and alignment constant. Notice how the relationship changes without editing the item markup. In a page with a different writing direction, start and end follow the layout direction, which makes them more flexible than positioning content by left and right. Keep the HTML order meaningful because keyboard focus follows document order in ordinary flows. Reversing item order visually can make focus jump around the screen.

Make wrapping deliberate

Enable wrapping on controls that may extend beyond a small screen. A second row can be preferable to a partially visible item, especially when visitors zoom or when labels are translated. Test an item with unusually long text. A flex item can have a minimum size based on its contents, so allowing the child to shrink or wrap may be necessary after adjusting the parent. Inspect the overflowing child before setting a global overflow rule, which could hide an important part of a control.

Flexboxing wraps one line at a time. Items on different rows can have different widths because each row distributes its own free space. Use CSS Grid for a set of cards that must line up in columns across rows. For a navigation strip or a collection of filter buttons, independently flowing rows are often fine. Check a width where only one item wraps, since that is where large gaps and awkward alignment are easy to spot.

Paste and verify the result

Copy or download the generated rule, replace the example selector with a meaningful selector from your project and keep the declarations grouped. Avoid applying the rule to a broad selector such as every section. Use the browser’s layout inspector to highlight the container and check which children participate. Try a long label, a narrow screen and a keyboard pass. If it looks different from the preview, check inherited sizing and existing child rules such as flex basis, margins or fixed widths.

Save your source stylesheet and rerun the same layout checks after adjusting a gap or alignment value. That gives you a repeatable way to decide which setting belongs in the shared component. A compact header may need different item alignment from a full-width filter panel even when both use the same tool.

Related tools

Related guides

Browse learning guides