Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Flexbox arranges items along one main axis and aligns them along a perpendicular cross axis. Set display: flex or display: inline-flex on a container; its direct children become flex items. This guide covers the 12 properties in the Flexbox module’s property reference, plus the related gap properties commonly used to space items.
Start with the axes and defaults
Flexbox is a one-dimensional layout model: it lays items out in a row or column, rather than controlling rows and columns as a two-dimensional grid does. The main axis follows flex-direction; the cross axis runs perpendicular to it. These axes are not simply synonyms for horizontal and vertical: writing direction affects what row means.
As an Amazon Associate I earn from qualifying purchases.
Most properties fall into two groups. Container properties set the flow and alignment of the layout; item properties control an individual child’s size, visual order, or alignment.
| Role | Properties | What they control |
|---|---|---|
| Container | flex-direction, flex-wrap, flex-flow, justify-content, align-items, align-content |
Axis, line wrapping, and alignment or distribution of items and lines. |
| Flex item | order, flex-grow, flex-shrink, flex-basis, flex, align-self |
Visual order, size negotiation, and an item’s cross-axis alignment. |
| Related spacing properties | gap, row-gap, column-gap |
Gutters between items or flex lines; these are useful with Flexbox but are not in the Flexbox module’s core property list. |
With only display: flex, the initial behavior is a row with no wrapping. Items do not grow, may shrink, and use an automatic flex basis; they stretch across the cross axis by default. The initial values for justify-content, align-content, and align-items are flex-start, stretch, and stretch respectively. The default flex value is 0 1 auto. See the W3C CSS Flexible Box Layout Module Level 1 and MDN’s basic concepts guide.
Choose the direction and wrapping behavior
flex-direction: choose the main axis
flex-direction sets the main axis and the direction items follow. Its initial value is row, which follows the inline direction of the writing mode—not necessarily left to right.
row: main axis follows the inline direction.row-reverse: reverses the visual flow of a row.column: main axis follows the block direction.column-reverse: reverses the visual flow of a column.
Changing from row to column also changes which dimension is the main axis. As a result, main-axis sizing and justify-content follow the column rather than the row.
flex-wrap: keep items on one line or create more
The initial value, nowrap, keeps items on one line. If they do not fit, they may shrink or overflow; they do not automatically move to another line. Set wrap to create additional lines, or wrap-reverse to reverse how those lines stack along the cross axis.
Recommended Free Tools
flex-flow: set direction and wrapping together
flex-flow is shorthand for flex-direction and flex-wrap. Either component can be omitted; the omitted property takes its initial value.
.cards {
display: flex;
flex-flow: row wrap;
}
That rule makes a row-oriented container whose items can wrap onto additional lines.
Control how flex items size themselves
Flex sizing is a three-part decision: flex-basis supplies an item’s starting main size, flex-grow shares positive free space, and flex-shrink governs how negative free space is handled. The flex shorthand sets all three in that order.
Rank #2
flex-basis: set the starting main size
flex-basis sets the initial main size used in the flex calculation. It accepts content or a size value such as 12rem or 30%. Its initial value is auto: the browser consults the item’s relevant main-size property and, where appropriate, its content sizing. It is not simply another name for width, because the main axis can be a column.
flex-grow: divide positive free space
The initial value is 0, so items do not grow by default. A positive non-negative number lets an item claim a proportional share of available positive space. For example, if two eligible items have grow factors of 1 and 2, they divide the available free space in a 1:2 ratio. That ratio describes the added space, not necessarily their final sizes: their starting bases and sizing constraints still matter.
flex-shrink: handle items that do not fit
The initial value is 1. When items exceed the available main-axis space, shrink factors influence how negative free space is removed. The calculation accounts for item bases and minimum sizes, so a factor twice as large does not guarantee exactly twice as many pixels of shrinkage. Content and minimum sizing can affect the result; equal flex values alone do not guarantee equal final widths.
flex: set grow, shrink, and basis
The longhand order is flex-grow, flex-shrink, then flex-basis. The spec’s initial value is 0 1 auto. These named forms are useful shortcuts:
| Declaration | Expansion | Effect |
|---|---|---|
flex: initial |
0 1 auto |
Does not grow, can shrink, and uses an automatic basis. |
flex: auto |
1 1 auto |
Can grow or shrink from an automatic basis. |
flex: none |
0 0 auto |
Neither grows nor shrinks from an automatic basis. |
flex: 1 |
A one-number shorthand commonly treated as growth with a zero-like basis | Can grow to take available space; do not assume it overrides content and minimum-size constraints. |
When you want equal-looking columns, flex: 1 is a common starting point, but the result still depends on content and minimum sizing. The shorthand’s serialized representation may use a percentage for the basis.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Align items and distribute free space
Alignment property names describe axes: justify-content works along the main axis; align-items and align-self work across the cross axis for items; align-content distributes multiple lines across that cross axis.
Rank #3
justify-content: place items along the main axis
This container property distributes remaining main-axis space after item sizing. Its initial value is flex-start. Common values include:
flex-start: pack items toward the main-start side.flex-end: pack them toward the main-end side.center: group them in the middle.space-between: put free space between items, with no extra space at the ends.space-around: distribute space around each item, leaving half-sized spaces at the ends relative to the gaps between items.space-evenly: distribute equal spaces between items and at both ends.
If items grow enough to consume the available space, justify-content has little or no free space left to distribute. Modern Box Alignment also provides logical alignment forms; choose them when you want alignment expressed relative to writing direction rather than a physical side.
align-items: align items across a line
align-items sets the default cross-axis alignment for items in a flex line. Its initial value is stretch. The Flexbox property table also lists flex-start, flex-end, center, and baseline. Stretching applies when the item’s cross size is automatic and other constraints permit it.
align-self: override alignment for one item
Set align-self on an individual flex item to override its parent’s align-items value. Its initial value, auto, defers to the parent. For example, one item can be centered while its siblings stretch:
.toolbar {
display: flex;
align-items: stretch;
}
.toolbar__action {
align-self: center;
}
align-content: distribute multiple lines
align-content distributes flex lines along the cross axis. It matters when the container has multiple lines and extra cross-axis space; it has no meaningful line-distribution effect for a single line. Its initial value is stretch. Flexbox values include flex-start, flex-end, center, space-between, space-around, and stretch.
For example, a wrapped container needs enough cross-axis room for the lines to be distributed visibly. align-items aligns items within a line; align-content distributes the lines themselves. MDN summarizes the cross-axis relationship: “Flex items can be aligned in the cross axis of the current line of the flex container, similar to justify-content but in the perpendicular direction.” W3C CSS Flexible Box Layout Module Level 1.
Rank #4
Set practical spacing with gap
gap sets gutters between flex items and, in a wrapped layout, between flex lines. Use row-gap and column-gap when you need different spacing by row or column; gap is the shorthand. These properties belong to the broader CSS alignment and spacing family, not the Flexbox module’s 12-property reference list.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware match.nav {
display: flex;
gap: 1rem;
}
A gap belongs between adjacent items or lines, rather than adding space to each item’s outside edge. Margins remain useful when spacing belongs to a particular box or when you need behavior that a uniform gutter cannot express.
Understand visual order and source order
order: change visual placement
order assigns a flex item to an integer ordering group. Its initial value is 0; items with the same value retain their relative order. Items with lower values are placed before those with higher values in the visual layout.
row-reverse, column-reverse, and order change visual placement, not the document’s source order. Keep the DOM order meaningful for assistive technology and sequential navigation; visual reordering can create a mismatch between what sighted users see and the order other users encounter.
Build a small layout, changing one decision at a time
This example starts with three items. Each step changes one property so the effect is easier to identify.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →1. Reveal the default row
.demo {
display: flex;
}
.demo > div {
padding: 1rem;
border: 1px solid;
}
The direct children line up on a single row, do not grow, may shrink, and stretch across the cross axis when sizing permits.
Best Value
2. Add a consistent gutter
.demo {
display: flex;
gap: 1rem;
}
The items now have a gutter between them without attaching margins to each child.
3. Distribute remaining main-axis space
.demo {
display: flex;
gap: 1rem;
justify-content: space-between;
}
With items that do not grow to fill the row, space-between places the remaining space between them.
4. Let the items grow
.demo > div {
flex: 1;
}
The items can now grow to use available space. Because growth consumes free space, justify-content may have little left to distribute.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches5. Allow another line
.demo {
display: flex;
flex-flow: row wrap;
gap: 1rem;
align-content: space-between;
}
If items wrap into multiple lines and the container has extra cross-axis room, align-content distributes those lines. Without multiple lines and available cross-axis space, it will not produce a visible distribution.
6. Align just one item differently
.demo > div:last-child {
align-self: center;
}
The final item uses its own cross-axis alignment rather than the container’s default.
Quick choices for common Flexbox tasks
| Goal | Starting point | What to check |
|---|---|---|
| Center items horizontally in a row | display: flex; justify-content: center; |
In a column, the main axis is vertical instead; writing direction also affects row start and end. |
| Center items across the cross axis | align-items: center; |
This centers items within a line; it does not distribute multiple lines. |
| Center one child across the cross axis | align-self: center; |
Apply it to the flex item, not its parent. |
| Make a row of items wrap | flex-flow: row wrap; |
Check that the container has a constrained main-axis size so wrapping can occur. |
| Space items evenly with a gutter | gap: 1rem; |
Use justify-content separately if you also need to distribute leftover main-axis space. |
Why flex items may not wrap
- The container still has
flex-wrap: nowrap. Setflex-wrap: wrapor useflex-flow: row wrap. - The container has enough main-axis space for the items at their current sizes. Wrapping occurs when items cannot fit on a line under the layout constraints.
- The main axis is not the one you assumed. Check
flex-direction; a column’s main axis is not the row direction. - The children are not direct flex items. Only a flex container’s direct children become flex items.
For property definitions and the complete Flexbox model, consult the MDN Flexbox guide, its basic concepts, and the W3C specification.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




