CSS Flexbox Generator
Build flexbox layouts visually. Change direction, alignment, wrapping and gap, tweak each item's grow, shrink, basis and order, and copy clean CSS and HTML.
Selected item
CSS
HTML
How to use CSS Flexbox Generator on KickSolve
Three quick steps, no account needed.
Why choose KickSolve
Built for speed, privacy and clean results.
What you can do with CSS Flexbox Generator
Everything this tool offers.
About CSS Flexbox Generator on KickSolve
What it does and how to get the best results.
How the flexbox generator works
The container settings on the right are applied to a live preview as inline styles, and the same values are written into the CSS you copy. Clicking an item lets you edit its own properties. Only item properties that differ from the defaults are included in the generated CSS, using nth-child selectors, so the code stays short.
Main axis and cross axis
Flexbox always works on two axes. The main axis follows flex-direction and is controlled by justify-content. The cross axis runs the other way and is controlled by align-items, align-self and, for wrapped lines, align-content. Most flexbox confusion comes from forgetting that column direction swaps the two.
Flex item properties
Flex-grow shares leftover space between items. Flex-shrink decides which items give up space first when the container is too small. Flex-basis sets the starting size. Align-self overrides align-items for one item, and order changes the visual position of an item.
Common flexbox layouts
- Center anything: justify-content center and align-items center.
- Navigation bar: justify-content space-between with a gap.
- Responsive card row: flex-wrap wrap with a flex-basis on each card.
- Sticky footer: flex-direction column with flex-grow 1 on the main content.
- Equal height columns: leave align-items on stretch.
Flexbox vs CSS grid
Flexbox lays out items in one direction at a time and is ideal for components. CSS grid lays out rows and columns together and is better for whole page layouts. They work well together, and a grid cell can contain a flex container.
Good to know
- The preview container has a fixed height of 320 pixels so vertical alignment is visible.
- Align-content only affects layouts where items wrap onto more than one line.
- The order property does not change keyboard or screen reader order.
Flexbox properties at a glance
Where each property is used and what it does.
| Property | Applies to | What it does |
|---|---|---|
| flex-direction | Container | Sets the main axis: row or column, normal or reversed |
| justify-content | Container | Aligns and distributes items along the main axis |
| align-items | Container | Aligns items along the cross axis |
| flex-wrap | Container | Allows items to wrap onto new lines |
| align-content | Container | Distributes wrapped lines along the cross axis |
| gap | Container | Sets the space between items |
| flex-grow | Item | How much extra space the item takes |
| flex-shrink | Item | How much the item shrinks when space is short |
| flex-basis | Item | The item's starting size |
| align-self | Item | Overrides align-items for one item |
| order | Item | Changes the visual order of the item |
Frequently asked questions
Quick answers.
What is CSS flexbox?
Flexbox is a CSS layout model that arranges items in a row or a column and controls how they share space, align and wrap. You turn it on with display: flex on a container.
What is the difference between justify-content and align-items?
Justify-content aligns items along the main axis, which is horizontal for a row and vertical for a column. Align-items aligns them along the cross axis, which is the other direction.
How does flex-direction change the layout?
Flex-direction sets the main axis. Row places items left to right, column places them top to bottom, and the reverse values flip the order. It also swaps what justify-content and align-items do visually.
What do flex-grow, flex-shrink and flex-basis do?
Flex-grow decides how much extra space an item takes, flex-shrink decides how much it gives up when space is short, and flex-basis sets its starting size before growing or shrinking.
When does flex-wrap matter?
By default all items stay on one line and shrink to fit. Set flex-wrap to wrap to let items move to a new line, which is how responsive card rows work. Align-content then controls the space between the lines.
How do I center a div with flexbox?
Set display: flex, justify-content: center and align-items: center on the parent. Give the parent a height, and the child will be centered both ways.
Does the gap property work with flexbox?
Yes. Gap works with flexbox in all current browsers and is simpler than adding margins to each item.
What does the order property do?
Order changes the visual order of items without changing the HTML. Screen readers and keyboard focus still follow the HTML order, so use it carefully.
Should I use flexbox or grid?
Use flexbox for one-dimensional layouts such as navigation bars, toolbars and card rows. Use CSS grid when you need to control rows and columns together.
Is anything uploaded or stored?
No. The generator runs in your browser and nothing is sent to a server.
More free tools from KickSolve
Related everyday tools.