display: flex
Defines a flex container and enables a flex context for all its direct children.
container {
display: flex;
}CSS Flexible Box Layout (Flexbox) is a one-dimensional layout model designed for distributing space and aligning items in web applications. Use this quick reference guide and visual preview for every flexbox property.
Open Interactive PlaygroundDefines a flex container and enables a flex context for all its direct children.
container {
display: flex;
}Establishes the main axis, defining the direction flex items are placed in the container.
container {
display: flex;
flex-direction: column;
}Aligns flex items along the main axis of the current line of the flex container.
container {
display: flex;
justify-content: center;
}Distributes flex items evenly along the main axis; first item is on the start line, last on the end line.
container {
display: flex;
justify-content: space-between;
}Defines the default behavior for how flex items are laid out along the cross axis on the current line.
container {
display: flex;
align-items: center;
height: 100px;
}Allows flex items to wrap onto multiple lines from top to bottom when space is insufficient.
container {
display: flex;
flex-wrap: wrap;
}Explicitly controls the space between flex items, establishing row and column gutters.
container {
display: flex;
gap: 16px;
}Defines the ability for a flex item to grow if necessary, dictating how much space it should take.
item {
flex-grow: 1;
}Allows the default alignment along the cross axis to be overridden for individual flex items.
item-2 {
align-self: flex-end;
}Controls the order in which items appear inside the flex container, regardless of source code order.
item-1 {
order: 3;
}display: flex do in CSS?display: flex defines an element as a flex container and enables the Flexbox layout model for all of its direct children, allowing them to be positioned and sized flexibly along a main and cross axis.
justify-content and align-items?justify-content aligns flex items along the main axis (horizontal by default), while align-items aligns them along the cross axis (vertical by default). Common values include flex-start, flex-end, center, space-between, and space-around.
flex-grow work?flex-grow defines how much a flex item will grow relative to the other items inside the same container. A value of 1 means the item can grow to fill available space; a value of 2 means it will grow twice as much as items with flex-grow: 1.
Set flex-wrap: wrap on the flex container. By default, flex-wrap is nowrap, which forces all items onto a single line. With wrap, items will move to the next line when they can no longer fit.
flex-direction property?flex-direction sets the direction of the main axis along which flex items are placed. Values are row (default, left to right), row-reverse, column (top to bottom), and column-reverse.