CSS Flexbox Generator
Visually build responsive CSS Flexbox & Tailwind layouts with live drag-and-drop reordering, interactive resizing, axis visualization, and instant code export.
Defines a flex container: flex is block-level (full width), inline-flex shrinks to fit content inline.
Establishes the main axis direction in which flex children are placed.
Controls whether items are forced onto one single line or allowed to wrap onto multiple lines.
Distributes free space along the main axis.
Aligns flex items along the perpendicular cross axis.
Packs wrapped lines within the container when there is extra cross-axis space.
align-content only takes effect when flex-wrap is set to wrap or wrap-reverse and items span multiple lines.
📚 CSS Flexbox Complete Property Reference & Cheat Sheet Click to Expand ▾
flex-direction (Main Axis)
rowLeft → Right (default)row-reverseRight ← LeftcolumnTop ↓ Bottomcolumn-reverseBottom ↑ Topjustify-content (Main Axis)
flex-startPack items to start edgecenterCenter group along main axisspace-betweenEqual space between itemsspace-aroundHalf-size space on outer edgesspace-evenlyIdentical gaps everywherealign-items (Cross Axis)
stretchFill cross-axis size (default)flex-startAlign to cross-start edgeflex-endAlign to cross-end edgecenterCenter on cross axisbaselineAlign text baselinesChild Item Sizing (flex)
flex-growShare of leftover free spaceflex-shrinkShrink rate when overflowingflex-basisInitial size before growingflex: 1Shorthand for 1 1 0%orderVisual sort order (default 0)What Is a CSS Flexbox Generator?
A CSS Flexbox Generator is a free online visual tool that lets you build responsive CSS Flexible Box (display: flex) layouts without writing code by hand. You can drag and drop flex items, adjust alignment, direction, wrapping, and spacing in real time, and copy clean CSS, HTML, or Tailwind CSS code instantly.
Instead of guessing how justify-content, align-items, or flex-grow will behave in a browser, our interactive playground shows you the exact result live on screen—along with plain-English explanations for every setting.
How to Use This Drag-and-Drop CSS Flexbox Generator
Building a responsive flex layout takes less than a minute:
- Pick a Layout Preset or Start Fresh: Choose a ready-made template (like Responsive Navbar, Perfect Center Hero, 3-Column Pricing Cards, or Sidebar + Main) from the top bar, or start with the default 4-box playground.
- Set Your Container Properties: Choose how items flow (
flex-direction), whether they wrap onto new lines (flex-wrap), how they align along the main axis (justify-content) and cross axis (align-items), and set thegapspacing. - Drag, Drop, and Resize Flex Items:
- Reorder: Drag any item inside the live canvas and drop it into a new position.
- Add Elements: Drag components (Flex Box, Fluid Card, Nav Pill, CTA Button, Sidebar) from the palette directly into the container.
- Resize: Drag the bottom-right corner of any item to test custom widths and heights.
- Customize Individual Child Items: Click any box in the preview to set its
flex-grow,flex-shrink,flex-basis,align-self, ororder. - Copy or Download Your Code: Switch between Vanilla CSS + HTML and Tailwind CSS in the top bar, then click Copy or Download in the dual code editors below.
Understanding the Two Axes of CSS Flexbox
Every CSS Flexbox layout works along two invisible lines called the Main Axis and the Cross Axis. Understanding these two axes makes Flexbox easy:
- Main Axis (Primary Flow): The direction your items travel.
- When
flex-directionisrow(default), the Main Axis runs horizontally (left to right). - When
flex-directioniscolumn, the Main Axis runs vertically (top to bottom). - Rule to remember:
justify-contentalways controls spacing along the Main Axis.
- When
- Cross Axis (Perpendicular Flow): The direction across your main flow.
- When
flex-directionisrow, the Cross Axis runs vertically (top to bottom). - When
flex-directioniscolumn, the Cross Axis runs horizontally (left to right). - Rule to remember:
align-itemsandalign-contentalways control alignment along the Cross Axis.
- When
💡 Pro Tip: Click the 🧭 Axis Overlay button in our tool above to see live Main Axis and Cross Axis arrows on the canvas as you switch between
rowandcolumn.
Complete CSS Flexbox Property Reference (Parent vs. Child
Flexbox properties are divided into two groups: Parent Container Properties (applied to the wrapper) and Child Item Properties (applied to individual items inside the wrapper).
1. Flex Container Properties (Parent Element)
| CSS Property | Tailwind Class Equivalent | What It Does (Simple Explanation) | Common Values |
|---|---|---|---|
display | flex / inline-flex | Turns an element into a flex container so its direct children become flex items. | flex (full width block), inline-flex (shrinks to content) |
flex-direction | flex-row, flex-col | Sets the direction items flow (the Main Axis). | row, row-reverse, column, column-reverse |
flex-wrap | flex-nowrap, flex-wrap | Decides if items stay on one line or wrap onto new lines when space runs out. | nowrap (default), wrap, wrap-reverse |
justify-content | justify-start, justify-center, justify-between | Aligns and spaces items along the Main Axis. | flex-start, flex-end, center, space-between, space-around, space-evenly |
align-items | items-stretch, items-center, items-start | Aligns items along the Cross Axis inside each line. | stretch (default), flex-start, flex-end, center, baseline |
align-content | content-start, content-between, content-center | Spaces multiple wrapped rows along the Cross Axis. (Only works when flex-wrap: wrap is active). | stretch, flex-start, flex-end, center, space-between, space-around |
gap | gap-4, gap-x-4, gap-y-4 | Adds clean space between flex items without needing margins on edge items. | px, rem, % (e.g., gap: 16px;) |
2. Flex Item Properties (Child Elements)
| CSS Property | Tailwind Class Equivalent | What It Does (Simple Explanation) | Default Value |
|---|---|---|---|
flex-grow | grow, grow-0 | Controls how much extra free space an item takes compared to its siblings. 0 means it won’t expand; 1 means it shares leftover space equally. | 0 |
flex-shrink | shrink, shrink-0 | Controls how much an item shrinks when the container is too small. Set to 0 to prevent an item (like a button or logo) from squishing. | 1 |
flex-basis | basis-auto, basis-1/3 | Sets the starting size of an item before growing or shrinking happens. | auto |
flex (Shorthand) | flex-1, flex-auto, flex-none | Combines flex-grow, flex-shrink, and flex-basis into one line (e.g., flex: 1 1 0%). | 0 1 auto |
align-self | self-auto, self-start, self-center | Overrides the parent’s align-items value for one specific item. | auto |
order | order-1, order-first, order-last | Changes the visual order of an item without changing the HTML source order. Lower numbers appear first. | 0 |
4 Most Common CSS Flexbox Layout Patterns (Copy-Paste Examples)
1. How to Center a Div Horizontally and Vertically
The most popular use of Flexbox is centering an element right in the middle of a section:
css.flex-container { display: flex; justify-content: center; /* Centers horizontally (main axis) */ align-items: center; /* Centers vertically (cross axis) */ min-height: 300px;}
- Tailwind CSS:
<div class="flex justify-center items-center min-h-[300px]">
2. Responsive Navigation Bar (Logo Left, Links Center, Button Right)
Use justify-content: space-between and align-items: center to align a website header cleanly in one row:
css.navbar { display: flex; justify-content: space-between; align-items: center; gap: 16px;}
- Tailwind CSS:
<nav class="flex justify-between items-center gap-4">
3. Equal-Width Responsive Cards (3 Columns)
Give each card flex: 1 1 250px inside a wrapping container so they sit side by side on desktop and stack automatically on mobile phones:
css.card-row { display: flex; flex-wrap: wrap; gap: 20px;}.card { flex: 1 1 250px;}
- Tailwind CSS:
<div class="flex flex-wrap gap-5"><div class="flex-1 basis-[250px]">...</div></div>
4. Fixed Sidebar + Fluid Main Content
Keep a sidebar at a fixed 240px width while the main content area stretches to fill the rest of the screen:
css.layout { display: flex; gap: 24px;}.sidebar { flex: 0 0 240px; /* Never grows, never shrinks, stays 240px */}.main-content { flex: 1 1 0%; /* Grows to fill all remaining width */}
CSS Flexbox vs. CSS Grid: Which One Should You Use?
| Feature | CSS Flexbox (display: flex) | CSS Grid (display: grid) |
|---|---|---|
| Dimensions | One-Dimensional (1D) — lays out items in a single row OR a single column at a time. | Two-Dimensional (2D) — controls both rows AND columns at the same time. |
| Sizing Approach | Content-First — items size themselves based on their content and free space. | Layout-First — you define strict column tracks and place items into cells. |
| Best Use Cases | Navbars, button groups, centering elements, toolbars, tags, and flexible rows of cards. | Full-page templates, photo galleries, dashboards, and complex multi-row/column grids. |
| Can You Combine Them? | Yes! Use CSS Grid for the outer page structure and Flexbox for UI components inside each grid cell. | Yes! Grid items can also be Flex containers (display: flex). |
Troubleshooting: Why Is My Flexbox Property Not Working?
- Why is
align-contentdoing nothing?align-contentonly works when your container has multiple lines of items. Ifflex-wrapis set tonowrap(the default), all items stay on a single line, soalign-contenthas no effect. Usealign-itemsinstead, or turn onflex-wrap: wrap. - Why are my flex items not wrapping onto a new line? By default, Flexbox uses
flex-wrap: nowrap, which forces all items onto one line and shrinks them to fit. Change the container toflex-wrap: wrap. - Why is
justify-content: centerorspace-betweennot moving my items? If your child items haveflex-grow: 1(orflex: 1), they expand to eat up 100% of the available space in the row. When there is no leftover free space,justify-contenthas nothing left to distribute. Setflex-grow: 0on the items to seejustify-contentwork. - Why is my item not centering vertically with
align-items: center? Make sure the parent.flex-containerhas a height taller than the items inside it (for example,min-height: 300pxorheight: 100vh). Without extra vertical height, the container shrinks tightly around the items.
FAQ CSS Flexbox Generator
What is the difference between justify-content and align-items?
justify-content aligns flex items along the main axis (horizontally in a row, vertically in a column). align-items aligns flex items along the cross axis (vertically in a row, horizontally in a column).
What is the difference between flex-grow, flex-shrink, and flex-basis?
flex-basis sets the starting size of an item before extra space is shared. flex-grow controls how much of the leftover space the item takes when the container is large. flex-shrink controls how much the item contracts when the container is too small. You can write all three together using the flex shorthand: flex: 1 1 auto; (grow, shrink, basis).
What is the difference between display: flex and display: inline-flex?
Both turn an element into a flex container. display: flex makes the container a block-level element that takes up 100% of the available width on its own line. display: inline-flex makes the container only as wide as its children so it can sit inline next to text or other buttons.
What is the difference between align-items and align-self?
align-items is placed on the parent flex container and aligns all child items at once. align-self is placed on a single child item to override the parent’s alignment for just that one element.
Can I generate Tailwind CSS classes with this Flexbox tool?
Yes. Click the 🌊 Output: Vanilla + HTML / Tailwind CSS toggle button in the top action bar to convert your entire visual layout—including direction, wrapping, alignment, gaps, and child grow/shrink rules—into ready-to-use Tailwind CSS utility classes.