Flexbox is a layout system in CSS that helps arrange items inside a container. Two important properties in Flexbox are flex direction and flex wrap. These properties control how items are placed and how they behave when there is not enough space.
Flex direction defines the direction in which items are arranged inside a flex container. By default, items are placed in a row from left to right. This means all elements appear in a horizontal line.
There are four main values of flex direction. Row places items horizontally from left to right. Row reverse places items horizontally from right to left. Column arranges items vertically from top to bottom. Column reverse arranges items vertically from bottom to top.
Example of flex direction in CSS:
.container {
display: flex;
flex-direction: row;
}
Flex wrap controls whether items should stay in one line or move to the next line when space is limited. By default, all items try to fit into one line, even if they overflow.
There are three main values of flex wrap. Nowrap keeps all items in a single line and may cause overflow. Wrap allows items to move to the next line when needed. Wrap reverse also allows wrapping but in reverse order.
Example of flex wrap in CSS:
.container {
display: flex;
flex-wrap: wrap;
}
When flex direction and flex wrap are used together, they give better control over layout behavior. For example, using row with wrap allows items to move into multiple lines while staying horizontal.
Example combining both properties:
.container {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
These properties are very useful for building responsive layouts. They help content adjust automatically to different screen sizes without breaking the design.