CSS Flexbox Generator

CSS Flexbox layouts arrange items in rows or columns with flexible sizing. Set display: flex on container. Key properties: flex-direction (row/column), justify-content (alignment along main axis), align-items (alignment along cross axis), gap (spacing). flex: 1 makes items grow equally. flex-wrap allows wrapping. Common patterns: centered content (justify-content: center; align-items: center), space-between navigation, responsive card grids.

Create CSS Flexbox layouts visually with a live preview. Configure flex-direction, justify-content, align-items, flex-wrap, and gap. Add child items with individual flex-grow, flex-shrink, flex-basis, order, and align-self. Includes presets for centered content, navigation bar, card layout, holy grail, and sidebar layouts. Copy generated CSS code instantly.

Works OfflineDark ModeNo Ads

Presets

Container Properties

8px

Live Preview

Item 1
Item 2
Item 3

Click an item to select it and edit its properties below.

Child Items

Generated CSS

.container {
  display: flex;
  gap: 8px;
}

How to Use

  1. Enter your value in the input field
  2. Click the Calculate/Convert button
  3. Copy the result to your clipboard

Frequently Asked Questions

What is CSS Flexbox?
CSS Flexbox (Flexible Box Layout) is a one-dimensional layout system that distributes space among items in a container along a single axis (row or column). It excels at aligning items, distributing space, and handling dynamic content sizes. Unlike CSS Grid which is two-dimensional, Flexbox focuses on one direction at a time, making it ideal for navigation bars, card rows, centering content, and component-level layouts.
What is the difference between Flexbox and CSS Grid?
Flexbox is one-dimensional — it lays out items along a single axis (row or column). CSS Grid is two-dimensional — it handles rows and columns simultaneously. Use Flexbox for component-level layouts like navigation bars, button groups, and centering. Use Grid for page-level layouts like dashboards and complex multi-area designs. They work great together — Grid for the overall page structure and Flexbox for individual components within grid areas.
What does flex-grow do?
flex-grow determines how much a flex item should grow relative to other items when extra space is available. A value of 0 (default) means the item will not grow. If one item has flex-grow: 1 and another has flex-grow: 2, the second item takes twice as much of the available space. flex-grow only distributes leftover space after items reach their base size (flex-basis).
What is the difference between justify-content and align-items?
justify-content controls alignment along the main axis (horizontal in row direction, vertical in column direction). align-items controls alignment along the cross axis (perpendicular to the main axis). For a row layout: justify-content handles horizontal spacing, align-items handles vertical alignment. Common values include flex-start, flex-end, center, space-between, and stretch.
How do I center an element with Flexbox?
To center an element both horizontally and vertically with Flexbox, set the parent container to display: flex; justify-content: center; align-items: center. This works regardless of the child element size. For horizontal-only centering in a row, use justify-content: center. For vertical-only centering, use align-items: center.
What does flex-basis do?
flex-basis sets the initial size of a flex item before flex-grow and flex-shrink are applied. It defaults to "auto", which uses the item's content size or explicit width/height. You can set it to a specific value like 200px, 50%, or 0. When flex-basis is 0, the item's space is determined entirely by flex-grow. The shorthand "flex: 1" is equivalent to "flex-grow: 1; flex-shrink: 1; flex-basis: 0%".
How do I make a responsive layout with Flexbox?
Use flex-wrap: wrap so items wrap to new lines when the container is too narrow. Set flex-basis to a minimum width (e.g., 250px) so items maintain a readable size. Combine with flex-grow: 1 to let items fill available space. Media queries can change flex-direction from row to column on mobile. The gap property adds consistent spacing between items without margin hacks.

Related Tools