CSS Flexbox Generator
Generate CSS flexbox layout code from direction, justify-content, align-items, wrap, and gap settings, with a live preview of the resulting layout.
CSS Flexbox Generator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: display: flex with direction, justify, align, wrap, gap
Worked example โ CSS code
Formula
display: flex with direction, justify, align, wrap, gap
Generate CSS flexbox layout code with visual configuration.
Worked Examples
Example 1: Centered row
Problem:Row, center justified, center aligned
Solution:display:flex; justify-content:center; align-items:center
Result:CSS code
Frequently Asked Questions
When to use flexbox vs grid?
Flexbox: 1-dimensional layouts (row OR column). Grid: 2-dimensional layouts (rows AND columns). Flexbox for components, Grid for page layouts.
What does justify-content control in flexbox?
justify-content aligns items along the main axis (horizontally in a row, vertically in a column). Options include flex-start, flex-end, center, space-between, space-around, and space-evenly, each producing different spacing patterns.
Why would I use flex-wrap?
flex-wrap: wrap allows flex items to overflow onto a new line instead of shrinking to fit. Use it for responsive card grids, tag lists, or navigation bars that should reflow gracefully on narrow screens without JavaScript.
What does the flex shorthand actually set?
flex is shorthand for flex-grow, flex-shrink and flex-basis. flex: 1 expands to 1 1 0%, so every item carrying it takes an equal share of the container whatever its content. flex: auto is 1 1 auto, which grows from the natural content size and so gives larger items more room. flex: none is 0 0 auto, freezing an item at its content size, and the initial value when you write nothing is 0 1 auto, which shrinks but never grows.
Why does a flex item overflow instead of shrinking?
A flex item has an automatic minimum size: in a row its min-width computes to auto, which resolves to the content minimum, so it refuses to shrink below the widest unbreakable thing inside it. A long URL, a pre block or a wide table therefore pushes past the container rather than compressing. Setting min-width: 0 on the item, or overflow: hidden, releases that floor and lets flex-shrink do its job. In a column container the same trap appears as min-height.
How does flex-direction change what justify-content and align-items do?
justify-content always works along the main axis and align-items along the cross axis; flex-direction decides which is which. In a row the main axis is horizontal, so justify-content moves items left and right. Switch to column and the main axis becomes vertical, so the same justify-content declaration now moves items up and down while align-items handles horizontal placement. That is why a centred row appears to break when the direction changes: the two properties have simply swapped roles.
What is the difference between align-items and align-self?
align-items is set on the flex container and gives every item the same cross-axis alignment. align-self is set on an individual item and overrides that default for it alone, which is how one badge sits at the top of a row while everything else stays centred. Its initial value, auto, means defer to the container. Both are ignored on an item whose cross-axis margin is auto, since an auto margin absorbs the free space before alignment is applied.
How does gap differ from using margins to space flex items?
gap inserts space only between items, never before the first or after the last, so a container no longer needs the old trick of negative margins on the parent cancelling per-item margins. It takes one or two values for row-gap and column-gap, and in a wrapping container it spaces the lines as well as the items. Margins are still right for space around a single item, and an auto margin remains the neatest way to push one item to the far end of the row.
When is the order property worth using?
order changes only the layout and painting sequence of flex items; it does not move them in the document. Keyboard tab order, screen reader reading order and copied text all continue to follow the source, so a visually reordered layout can become impossible to navigate. Reserve it for cosmetic shifts where the reading order stays sensible either way, and reorder the markup itself when the meaning changes. Items sharing an order value fall back to source order.
What does align-items: baseline actually line up?
It aligns the first text baseline of each flex item rather than their boxes, so a 32px heading and a 14px caption sitting side by side share one typographic line even though their heights differ. That makes it the right choice for a row mixing a label, an input and a helper string, where centre alignment leaves the text looking staggered. An item with no baseline of its own has one synthesised from its border box, so a child holding only a background image aligns by its box edge rather than by any text.
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer ยท Editorial policy
Related Calculators
๐งฎCSS Unit Converter
Calculate css unit converter with inputs, formulas, and instant results.
๐งฎTailwind CSS Class Calculator
Convert pixel values to Tailwind CSS spacing, sizing, and font classes.
๐งฎSVG Path Generator
svg path generator. Get instant, accurate results.
๐งฎBandwidth Time Transfer Calculator
Calculate bandwidth time transfer with inputs, formulas, and instant results.
๐งฎDownload Time Calculator
Calculate download time with inputs, formulas, and instant results.
๐งฎThroughput Efficiency Calculator
Calculate throughput efficiency with inputs, formulas, and instant results.
๐งฎBase64 Encode & Decode Calculator
Calculate base64encode decode with inputs, formulas, and instant results.
๐งฎHash Checksum Calculator
Calculate hash checksum with inputs, formulas, and instant results.