Flexbox
In one line
Flexbox is a CSS layout module designed for arranging elements in one dimension (row or column) with powerful alignment capabilities.
In simple words
Flexbox (Flexible Box Layout) is a CSS layout system that makes it easy to arrange elements in a single row or column. It solves problems that were hard with floats and inline-block: centering, equal spacing, distributing space, and reordering items.
To use Flexbox, you set display: flex on a container. Its children become "flex items" that can be aligned, stretched, or spaced evenly. The container has a "main axis" (the direction of the items) and a "cross axis" (perpendicular to it).
Key properties include justify-content (alignment on the main axis), align-items (alignment on the cross axis), flex-direction (row or column), and flex-wrap (whether items wrap to the next line). Flexbox is the go-to tool for nav bars, card rows, and any 1D layout.
Example
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
/* Items spread out with equal space between, vertically centered */A flex container with items evenly spaced and vertically centered — a common layout pattern.
Related terms
Related Resources
Related Lessons
- CSS Flexbox
Learn flexbox layout.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.