The flex-wrap property in CSS is used to control the wrapping behavior of flex items within a flex container. It determines whether the flex items should wrap onto multiple lines or stay on a single line. The flex-wrap property accepts three possible values: nowrap, wrap, and wrap-reverse.
1. nowrap (default): This value ensures that all flex items are placed on a single line, even if it causes overflow. The flex items will shrink or grow as necessary to fit within the container's width. This means that if the container's width is not enough to accommodate all the flex items, they will be compressed or truncated. The nowrap value prevents flex items from wrapping onto multiple lines.
Example:
css
.container {
display: flex;
flex-wrap: nowrap;
}
2. wrap: This value allows flex items to wrap onto multiple lines if necessary. If the flex items exceed the container's width, they will wrap onto the next line. The wrapping behavior is determined by the flex-direction property. By default, the flex items will wrap from left to right.
Example:
css
.container {
display: flex;
flex-wrap: wrap;
}
3. wrap-reverse: This value is similar to wrap, but it reverses the wrapping direction. The flex items will wrap onto multiple lines, but the wrapping will start from the last line to the first line. This means that the flex items will be stacked in reverse order.
Example:
css
.container {
display: flex;
flex-wrap: wrap-reverse;
}
It's important to note that the flex-wrap property only has an effect when there is insufficient space to accommodate all the flex items on a single line. If there is enough space, the flex items will remain on a single line regardless of the flex-wrap value.
The flex-wrap property in CSS allows for controlling the wrapping behavior of flex items within a flex container. The nowrap value keeps all items on a single line, wrap value allows items to wrap onto multiple lines, and wrap-reverse value wraps items onto multiple lines in reverse order.
Other recent questions and answers regarding Examination review:
- How can we control the spacing between flex items using the justify-content property?
- What are the possible values for the flex-direction property and how do they affect the arrangement of flex items?
- How can we make a container section a flexbox in CSS?
- What are the differences between CSS grid and flexbox in terms of responsive design and browser support?

