CSS Flexbox Generator
Lay out items with CSS flexbox: direction, wrap, justify-content, align-items, align-content, gap and per-item flex values, with HTML and a live preview.
Flexbox arranges items in one direction — a row or a column — and distributes the free space between them. Most layout questions come down to five container properties: flex-direction, flex-wrap, justify-content (main axis), align-items (cross axis) and gap, plus the flex shorthand on items. This generator writes those rules and the matching HTML and lets your own browser lay out the preview, so you see exactly what each value does.
How to use this tool
- Choose the direction and whether items may wrap onto new lines.
- Set justify-content for the main axis and align-items for the cross axis.
- Set the gap and the number of items; optionally give items their own flex values.
- Copy the CSS and HTML.
Formula
display: flex; flex-direction; flex-wrap; justify-content; align-items; [align-content]; gap · item: flex: <grow> <shrink> <basis>
justify-content works along the direction of the row or column; align-items across it. align-content only matters when items wrap onto several lines. flex: 1 is short for 1 1 0%, so items with flex: 1 share the space equally.
Example
Three items with flex-wrap: wrap, justify-content: space-between and align-items: center, where item 1 has flex: 2 1 0% and item 3 flex: 1, give item 1 two shares and item 3 one share of the free space; item 2 keeps its natural width. The default settings give a plain row with gap: 12px.
Frequently asked questions
How do I center something with flexbox?
On the parent: display: flex; justify-content: center; align-items: center;. That centers the child both horizontally and vertically.
Flexbox or grid?
Flexbox is one-dimensional — great for toolbars, nav bars, button groups and lists that wrap. Grid controls rows and columns together, which suits page layouts and card grids with aligned columns.
Why does gap not work?
All current browsers support gap in flexbox (Safari since 14.1). If an old browser must be supported, use margins on the items instead.
Sources
Last updated:
Page address with these inputs: https://kakao.mobile/tools/css-flexbox-generator/
Cite or embed this tool
kakaoCalc. (2026, November 8). CSS Flexbox Generator. https://kakao.mobile/tools/css-flexbox-generator/
“CSS Flexbox Generator.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/css-flexbox-generator/.
Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms