CSS Flexbox Generator
Generate flexbox CSS from selector, direction, wrap, alignment, gap, child sizing, preview, property ledger, HTML scaffold, and JSON outputs.Flexbox CSS ready
{{ cssCode }}
| Scope | Property | Value | Implementation note | Copy |
|---|---|---|---|---|
| {{ row.scope }} | {{ row.property }} |
{{ row.value }} |
{{ row.note }} |
{{ htmlScaffold }}
Introduction
CSS flexbox arranges direct child elements along one main axis at a time. That main axis can run across a row or down a column, and the cross axis runs perpendicular to it. The same five items can therefore become a navigation bar, a vertical stack, a centered control group, or a wrapped chip list by changing a small set of container declarations.
Flexbox matters most when the available space changes. A button group may need to stay centered on a wide screen, wrap into two rows on a narrow card, and keep consistent spacing between adjacent items without adding margins to every child. The layout remains source-order based unless reverse direction or separate ordering rules are introduced, so the visual result should still be checked against reading order and keyboard flow.
Common flexbox mistakes come from reading alignment words as horizontal or vertical. justify-content follows the main axis, so it is horizontal in a normal row and vertical in a column. align-items follows the cross axis for each line, while align-content only becomes visible when wrapping creates multiple flex lines.
A flex rule is also not a full component design. It does not set typography, color, breakpoints, item order, or accessibility behavior. Use it to shape the container and item sizing relationship, then test the copied CSS where the final content, writing mode, and responsive constraints are known.
Technical Details:
A flex container creates a flex formatting context for its direct children. The container-level properties decide the direction of flow, whether items can form more than one line, how remaining space is distributed, and how items align against the perpendicular axis.
The axis relationship is the core rule. flex-direction: row and row-reverse use the inline direction as the main axis. column and column-reverse use the block direction. Reverse values change the visual flow, so they should be reviewed carefully when source order matters for reading or keyboard navigation.
Rule Core:
| Property | Role | Values Generated Here |
|---|---|---|
display |
Creates a block-level or inline flex container. | flex, inline-flex |
flex-direction |
Sets the main axis and visual flow direction. | row, row-reverse, column, column-reverse |
flex-wrap |
Controls whether items stay on one line or form extra flex lines. | nowrap, wrap, wrap-reverse |
justify-content |
Distributes the item group along the main axis. | flex-start, flex-end, center, space-between, space-around, space-evenly |
align-items |
Aligns items on the cross axis within each flex line. | stretch, flex-start, flex-end, center, baseline |
align-content |
Distributes multiple flex lines on the cross axis. | stretch, flex-start, flex-end, center, space-between, space-around, space-evenly |
gap |
Adds space between adjacent flex items and flex lines without outer margins. | Number from 0 to 999 with px, rem, em, or % |
Child sizing uses the flex shorthand. The three generated values are grow factor, shrink factor, and basis. Grow controls how items claim positive available space relative to siblings. Shrink controls how much they may contract when the container is tight. Basis gives the initial main-axis size before grow and shrink are resolved.
| Part | Accepted Here | Layout Effect |
|---|---|---|
flex-grow |
Rounded number from 0 to 12 |
0 keeps the item from claiming extra main-axis space; larger numbers share that space in proportion. |
flex-shrink |
Rounded number from 0 to 12 |
0 resists shrinking; positive values allow the item to contract when space is tight. |
flex-basis |
auto, content, intrinsic-size keywords, 0, or lengths such as 16rem and 240px |
Sets the starting main-axis size used before grow and shrink are applied. |
min-width: 0 |
Optional child declaration | Allows long row-based child content to shrink inside the flex item instead of forcing overflow from its intrinsic width. |
The generated property ledger is a useful audit because it ties each declaration to a short implementation note. For example, align-content is flagged as having no visible effect under nowrap, and min-width: 0 appears only when the child sizing rule is enabled.
Everyday Use & Decision Guide:
For a first pass, set CSS selector to the real container selector, keep Display mode at flex, choose Direction, then adjust Justify content and Align items while watching Flex Preview. A row layout with wrap, space-between, center, and a modest Gap is a practical starting point for toolbars, card actions, tag rows, and button groups.
Use inline-flex only when the container itself should behave like inline content, such as a compact badge or icon-label pair inside a sentence. For full-width blocks, panels, navigation bars, and form rows, flex is usually easier to reason about because the container participates as a block.
- Choose
rowfor left-to-right or right-to-left inline flow, andcolumnfor vertical stacks. - Use reverse direction only when the visual order intentionally differs from source order.
- Switch from
nowraptowrapwhen narrow screens should create another line instead of squeezing all items together. - Open Advanced and change
Align contentonly when wrapping creates multiple lines. - Enable
Include child sizing rulewhen every direct item should share the sameflexvalues. - Turn on
Set min-width: 0for row layouts with long labels, URLs, or code text inside child items.
The Property Ledger is the quickest place to catch a wrong mental model. If it says justify-content follows a vertical main axis, the chosen Direction is column-based. If align-content says it has no visible effect, wrapping is not creating multiple lines for the current setup.
Before copying from Flex CSS, compare the summary line with Flex Preview and HTML Scaffold. The preview uses sample items, so replace those dimensions mentally with the real text, images, or controls that will sit inside the container.
Step-by-Step Guide:
- Enter
CSS selector. A simple class selector such as.toolbarwill also produce matching wrapper markup inHTML Scaffold; an unsupported selector shape falls back to a generic scaffold wrapper. - Choose
Display modeandDirection. Confirm the summary badge reports the expected horizontal or vertical main axis. - Set
Wrap,Justify content,Align items, andGap. CheckFlex Previewto see whether items group, spread, center, or wrap as intended. - Open Advanced when line spacing or child sizing matters. Set
Align contentfor wrapped lines, then enableInclude child sizing ruleif direct items need a sharedflexshorthand. - If child sizing is enabled, review
Child selector suffix,Flex grow,Flex shrink,Flex basis, andSet min-width: 0. If an unsupported basis appears asautoinFlex CSS, replace it with a supported keyword or a length such as12rem. - Adjust
Preview itemsfrom2to12so the preview and scaffold approximate the number of children in the target component. - Review
Property Ledgerfor per-property notes, then copy the final rule fromFlex CSSafter the preview, scaffold, and JSON payload agree with the intended layout.
Interpreting Results:
The headline summary combines Direction and Justify content, because those two controls decide the main-axis flow and distribution. The summary line then reports display mode, wrapping, gap, and whether the output is a container rule only or includes child sizing.
Flex CSS is the declaration set to paste into a stylesheet. Property Ledger is the review view for meaning, especially when a value is valid but visually inactive. HTML Scaffold is a starter wrapper and sample children, not a replacement for the final markup structure.
A clean preview does not prove the CSS will behave the same in production content. The sample items use fixed labels and generated sizes, while real children may contain long words, images, form controls, or nested blocks. Use Set min-width: 0 and the child flex shorthand only when those rules match the target component.
Treat reverse direction as a stop-and-check result. It can produce the visual sequence you want, but it does not rewrite the source order. Verify reading order, keyboard navigation, and any screen-reader-dependent flow before publishing a reversed row or column.
Worked Examples:
A card action row can use .card-actions, Display mode set to flex, Direction set to row, Wrap set to wrap, Justify content set to flex-end, Align items set to center, and a Gap of 12px. Flex CSS should show a container rule only unless child sizing is enabled.
A responsive tag list can keep row and wrap, use Justify content set to flex-start, Align items set to baseline, and Gap set to 0.5rem. In Property Ledger, gap explains that spacing is added between adjacent items instead of as outer-edge margins.
A vertical sidebar group can use .sidebar-stack, Direction set to column, Justify content set to center, and Align items set to stretch. The summary badge should report a vertical main axis, so justify-content now moves the group up or down rather than left or right.
A troubleshooting case often starts with a long label forcing a child wider than expected. Enable Include child sizing rule, keep Flex shrink at 1, set Flex basis to auto or a supported length, turn on Set min-width: 0, and confirm Property Ledger includes the child min-width row.
FAQ:
Why did align-content not change the preview?
align-content affects spacing between flex lines. If Wrap is nowrap, or if the current items fit on one line, the property can be present in Flex CSS without changing the visible preview.
What is the difference between justify-content and align-items?
justify-content follows the main axis chosen by Direction. align-items works on the cross axis for each line. Change Direction from row to column and those visual directions swap.
Why does my flex basis become auto?
Flex basis accepts keywords such as auto, content, min-content, max-content, fit-content, 0, or a supported length unit. Other text is normalized to auto in the generated CSS.
Should I use row-reverse or column-reverse?
Use reverse values only when the visual order is intentionally different from source order. The generated CSS can reverse the flow, but it does not rewrite the underlying markup sequence used by readers and keyboards.
Does the layout data have to be sent to a server?
No server request is needed to build the CSS. The preview, property ledger, scaffold, JSON payload, copy actions, and downloads are generated in the browser page.
Glossary:
- Flex container
- The element with
display: flexordisplay: inline-flex. - Flex item
- A direct child of a flex container.
- Main axis
- The direction set by
flex-direction;justify-contentdistributes items along it. - Cross axis
- The perpendicular axis used by
align-itemsand multi-linealign-content. - Flex line
- A row or column of flex items; wrapping can create more than one line.
- Flex basis
- The initial main-axis item size used before grow and shrink are resolved.
References:
- CSS Flexible Box Layout Module Level 1, W3C.
- Basic concepts of flexbox, MDN Web Docs.
- Box alignment in flexbox, MDN Web Docs, 2025-11-20.
- flex CSS property, MDN Web Docs.