Flexbox CSS ready
{{ summaryPrimary }}
{{ summaryLine }}
{{ badge.label }}
CSS Flexbox Generator inputs
Container selector for the generated flex rule.
Choose whether the container behaves as block flex or inline flex.
Sets the main axis used by justify-content.
Let items wrap instead of forcing one cramped line.
Main-axis alignment and spacing.
Cross-axis alignment for items inside each line.
Spacing between adjacent flex items.
Cross-axis spacing for multiple flex lines.
Adds a separate selector for direct flex items.
Suffix appended after the container selector.
Extra-space share for each child item.
Tight-space shrink factor for each child item.
Use auto, 0, or a CSS length such as 16rem or 240px.
Allows long child content to shrink inside flex rows.
Number of sample items used in the preview and scaffold.
{{ cssCode }}
{{ item.label }}
Scope Property Value Implementation note Copy
{{ row.scope }} {{ row.property }} {{ row.value }} {{ row.note }}
{{ htmlScaffold }}

        
Customize
Advanced
:

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.

Flexbox container with a main axis, cross axis, and wrapped item rows

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:

Flexbox container properties and their layout roles
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.

Generated child sizing rule parts
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 row for left-to-right or right-to-left inline flow, and column for vertical stacks.
  • Use reverse direction only when the visual order intentionally differs from source order.
  • Switch from nowrap to wrap when narrow screens should create another line instead of squeezing all items together.
  • Open Advanced and change Align content only when wrapping creates multiple lines.
  • Enable Include child sizing rule when every direct item should share the same flex values.
  • Turn on Set min-width: 0 for 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:

  1. Enter CSS selector. A simple class selector such as .toolbar will also produce matching wrapper markup in HTML Scaffold; an unsupported selector shape falls back to a generic scaffold wrapper.
  2. Choose Display mode and Direction. Confirm the summary badge reports the expected horizontal or vertical main axis.
  3. Set Wrap, Justify content, Align items, and Gap. Check Flex Preview to see whether items group, spread, center, or wrap as intended.
  4. Open Advanced when line spacing or child sizing matters. Set Align content for wrapped lines, then enable Include child sizing rule if direct items need a shared flex shorthand.
  5. If child sizing is enabled, review Child selector suffix, Flex grow, Flex shrink, Flex basis, and Set min-width: 0. If an unsupported basis appears as auto in Flex CSS, replace it with a supported keyword or a length such as 12rem.
  6. Adjust Preview items from 2 to 12 so the preview and scaffold approximate the number of children in the target component.
  7. Review Property Ledger for per-property notes, then copy the final rule from Flex CSS after 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: flex or display: inline-flex.
Flex item
A direct child of a flex container.
Main axis
The direction set by flex-direction; justify-content distributes items along it.
Cross axis
The perpendicular axis used by align-items and multi-line align-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: