CSS Flexbox Generator
Build Flexbox layouts visually and copy the generated CSS
Controls
Live Preview
Generated CSS
.flex-container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: center;
align-items: center;
align-content: stretch;
gap: 16px;
}What is Flexbox?
CSS Flexbox (Flexible Box Layout Module) is a layout model introduced in CSS3 that provides a more efficient way to lay out, align, and distribute space among items in a container, even when their size is unknown or dynamic. Unlike traditional layout methods using floats and positioning, Flexbox is direction-agnostic and designed for one-dimensional layouts.
Flexbox works along two axes: the main axis (defined by flex-direction) and the cross axis (perpendicular to it). Properties like justify-content control distribution along the main axis, while align-items and align-content control the cross axis. This tool lets you experiment with all these properties visually and copy the resulting CSS.
Flexbox Properties Reference
| Property | Values | Description |
|---|---|---|
| display | flex | inline-flex | Enables flex context for the container |
| flex-direction | row | row-reverse | column | column-reverse | Defines the main axis direction |
| flex-wrap | nowrap | wrap | wrap-reverse | Controls whether items wrap to new lines |
| justify-content | flex-start | center | flex-end | space-between | space-around | space-evenly | Aligns items along the main axis |
| align-items | flex-start | center | flex-end | stretch | baseline | Aligns items along the cross axis |
| align-content | flex-start | center | flex-end | space-between | space-around | stretch | Distributes space between wrapped lines |
| gap | <length> | Sets spacing between flex items |
Flexbox vs. CSS Grid
Flexbox
- One-dimensional (row or column)
- Content-driven sizing
- Best for component layouts
- Items can grow and shrink dynamically
- Great for centering and distributing space
CSS Grid
- Two-dimensional (rows and columns)
- Container-driven sizing
- Best for page-level layouts
- Explicit row and column tracks
- Great for complex grid structures
Common Flexbox Patterns
Centering
display: flex; justify-content: center; align-items: center;
Navbar Layout
display: flex; justify-content: space-between; align-items: center;
Equal Width Cards
display: flex; flex-wrap: wrap; gap: 16px; /* children: flex: 1 1 300px; */
Sticky Footer
display: flex; flex-direction: column; min-height: 100vh; /* footer: margin-top: auto; */