1. css
  2. /properties
  3. /flex-direction

flex-direction

Definition

The flex-direction property in CSS defines the direction of the main axis of a flex container and the direction in which flex items are laid out.

Examples

Set the flex-direction property to row (the default value):

.flex-container {
  flex-direction: row;
}

Set the flex-direction property to row-reverse:

.flex-container {
  flex-direction: row-reverse;
}

Set the flex-direction property to column:

.flex-container {
  flex-direction: column;
}

Values

ValueDescription
rowThe flex items are arranged in a row from left to right. (Default)
row-reverseThe flex items are arranged in a row from right to left.
columnThe flex items are arranged in a column from top to bottom.
column-reverseThe flex items are arranged in a column from bottom to top.
inheritUse the value of the parent element.

Best Practices

  • Consider the direction of the main axis and the cross axis when setting the flex-direction property.
  • Use flex-direction in conjunction with other flexbox properties such as flex-wrap, justify-content, and align-items to control the layout of flex items.
  • Consider using CSS frameworks like Bootstrap or Foundation to manage the layout of your site, which often include built-in styles for flexbox.
  • Make sure to provide a meaningful fallback for browsers that do not support the flex-direction property.
  • Keep in mind that the value of flex-direction affects the layout of flex items along the main axis of the flex container.

Browser Compatibility

ChromeFirefoxSafariInternet ExplorerMicrosoft EdgeOpera
YesYesYesYesYesYes