Flexbox is a CSS layout model that allows items inside a container to be arranged in flexible, responsive ways.
display: flex
This property turns an element into a flex container, making its children flex items.
.container { display: flex; }
flex-direction
This property defines the direction of the flex items inside the container. It can be row (default), row-reverse, column, or column-reverse.
.container { display: flex; flex-direction: row; /* Items placed in a row */ }
justify-content
This property aligns flex items along the main axis (horizontal by default). Values include: flex-start, flex-end, center, space-between, space-around, space-evenly.
.container { display: flex; justify-content: center; /* Centers items along the horizontal axis */ }
align-items
This property aligns flex items along the cross axis (vertical by default). It can take values like flex-start, flex-end, center, stretch, and baseline.
.container { display: flex; align-items: center; /* Centers items vertically */ }
flex-wrap
This property controls whether flex items should wrap onto multiple lines if needed. Values: nowrap, wrap, wrap-reverse.
.container { display: flex; flex-wrap: wrap; /* Items will wrap when necessary */ }
flex-grow
This property defines how much a flex item should grow relative to the other items. A value of 0 means it won’t grow.
.item { flex-grow: 1; /* Item will grow to fill available space */ }
flex-shrink
This property defines how much a flex item should shrink if the container becomes smaller. A value of 0 means it won’t shrink.
.item { flex-shrink: 0; /* Item will not shrink */ }
Flexbox is a powerful layout system in CSS that allows you to align and distribute space between items in a container with ease. By using various flex properties, you can create responsive layouts with minimal effort.