CSS Flexbox Generator

Visually build responsive CSS Flexbox & Tailwind layouts with live drag-and-drop reordering, interactive resizing, axis visualization, and instant code export.

display Container Type

Defines a flex container: flex is block-level (full width), inline-flex shrinks to fit content inline.

flex-direction Main Axis Flow

Establishes the main axis direction in which flex children are placed.

flex-wrap Line Wrapping

Controls whether items are forced onto one single line or allowed to wrap onto multiple lines.

justify-content Main Axis Alignment

Distributes free space along the main axis.

align-items Cross Axis Alignment

Aligns flex items along the perpendicular cross axis.

align-content Multi-Line Cross Spacing

Packs wrapped lines within the container when there is extra cross-axis space.

⚠️ Note: align-content only takes effect when flex-wrap is set to wrap or wrap-reverse and items span multiple lines.
gap (row & column)
gap:
column-gap:

Select a flex child below (or click any box in the live preview) to customize its individual flex rules:

Item Label Inner Content
Text:
flex-grow Expand Factor

How much of the remaining free space this item claims relative to siblings (0 = do not grow).

flex-grow:
flex-shrink Compress Factor

How much this item shrinks when space is tight (0 = prevent shrinking, 1 = default shrink).

flex-shrink:
⚠️ Note: When flex-wrap: wrap is active, items usually wrap onto a new line rather than shrinking.
flex-basis Initial Main Size

Starting size before free space is distributed (e.g., auto, 0, 150px, 30%).

align-self Override Cross Align
order & dimensions Visual Order / Size
order:
width (px):
height (px):

💡 Tip: Leave width/height at 0 for auto, or drag the bottom-right corner of any item directly in the canvas!

Live Drag & Drop Canvas (Drag items to reorder • Drag corner to resize • Click to inspect)
🧲 Drag or Click to Drop into Container: 📦 Flex Box 🃏 Fluid Card (grow:1) 🔗 Nav Pill 🚀 CTA Button 📑 Sidebar
Main Axis → (justify-content: flex-start)
Cross Axis ↓ (align-items: stretch)
Why it looks like this
Items flow horizontally from left to right (flex-direction: row), packed toward the start of the main axis (justify-content: flex-start) and stretched across the full cross-axis height (align-items: stretch).
🎨 CSS Stylesheet
📄 HTML Markup
📚 CSS Flexbox Complete Property Reference & Cheat Sheet Click to Expand ▾

flex-direction (Main Axis)

rowLeft → Right (default)
row-reverseRight ← Left
columnTop ↓ Bottom
column-reverseBottom ↑ Top

justify-content (Main Axis)

flex-startPack items to start edge
centerCenter group along main axis
space-betweenEqual space between items
space-aroundHalf-size space on outer edges
space-evenlyIdentical gaps everywhere

align-items (Cross Axis)

stretchFill cross-axis size (default)
flex-startAlign to cross-start edge
flex-endAlign to cross-end edge
centerCenter on cross axis
baselineAlign text baselines

Child Item Sizing (flex)

flex-growShare of leftover free space
flex-shrinkShrink rate when overflowing
flex-basisInitial size before growing
flex: 1Shorthand for 1 1 0%
orderVisual sort order (default 0)
Copied to clipboard!

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:

  1. 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.
  2. 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 the gap spacing.
  3. 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.
  4. Customize Individual Child Items: Click any box in the preview to set its flex-grow, flex-shrink, flex-basis, align-self, or order.
  5. 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-direction is row (default), the Main Axis runs horizontally (left to right).
    • When flex-direction is column, the Main Axis runs vertically (top to bottom).
    • Rule to remember: justify-content always controls spacing along the Main Axis.
  • Cross Axis (Perpendicular Flow): The direction across your main flow.
    • When flex-direction is row, the Cross Axis runs vertically (top to bottom).
    • When flex-direction is column, the Cross Axis runs horizontally (left to right).
    • Rule to remember: align-items and align-content always control alignment along the Cross Axis.

💡 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 row and column.

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 PropertyTailwind Class EquivalentWhat It Does (Simple Explanation)Common Values
displayflex / inline-flexTurns an element into a flex container so its direct children become flex items.flex (full width block), inline-flex (shrinks to content)
flex-directionflex-row, flex-colSets the direction items flow (the Main Axis).row, row-reverse, column, column-reverse
flex-wrapflex-nowrap, flex-wrapDecides if items stay on one line or wrap onto new lines when space runs out.nowrap (default), wrap, wrap-reverse
justify-contentjustify-start, justify-center, justify-betweenAligns and spaces items along the Main Axis.flex-start, flex-end, center, space-between, space-around, space-evenly
align-itemsitems-stretch, items-center, items-startAligns items along the Cross Axis inside each line.stretch (default), flex-start, flex-end, center, baseline
align-contentcontent-start, content-between, content-centerSpaces 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
gapgap-4, gap-x-4, gap-y-4Adds clean space between flex items without needing margins on edge items.px, rem, % (e.g., gap: 16px;)

2. Flex Item Properties (Child Elements)

CSS PropertyTailwind Class EquivalentWhat It Does (Simple Explanation)Default Value
flex-growgrow, grow-0Controls 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-shrinkshrink, shrink-0Controls 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-basisbasis-auto, basis-1/3Sets the starting size of an item before growing or shrinking happens.auto
flex (Shorthand)flex-1, flex-auto, flex-noneCombines flex-grow, flex-shrink, and flex-basis into one line (e.g., flex: 1 1 0%).0 1 auto
align-selfself-auto, self-start, self-centerOverrides the parent’s align-items value for one specific item.auto
orderorder-1, order-first, order-lastChanges 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?

FeatureCSS Flexbox (display: flex)CSS Grid (display: grid)
DimensionsOne-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 ApproachContent-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 CasesNavbars, 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-content doing nothing? align-content only works when your container has multiple lines of items. If flex-wrap is set to nowrap (the default), all items stay on a single line, so align-content has no effect. Use align-items instead, or turn on flex-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 to flex-wrap: wrap.
  • Why is justify-content: center or space-between not moving my items? If your child items have flex-grow: 1 (or flex: 1), they expand to eat up 100% of the available space in the row. When there is no leftover free space, justify-content has nothing left to distribute. Set flex-grow: 0 on the items to see justify-content work.
  • Why is my item not centering vertically with align-items: center? Make sure the parent .flex-container has a height taller than the items inside it (for example, min-height: 300px or height: 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.

Related Tools