Flexbox
Flexbox is a CSS layout system for arranging items in a single row or column, with powerful control over alignment and spacing. You enable it by setting display: flex on a container.
Web
Flexbox shines for one-dimensional layouts like navigation bars, toolbars, and centering content. The container becomes a flex container and its direct children become flex items.
Key properties include justify-content (alignment along the main axis), align-items (alignment along the cross axis), and gap (space between items).
Examples
CSS
.nav {
display: flex;
justify-content: space-between;
align-items: center;
gap: 16px;
}Output:
Lays out children in a row, spreads them apart, and vertically centers them with 16px gaps.Learn it in a lesson
- Flexbox →