Flex Direction
Controls the direction in which flex items are placed in the flex container. This is fundamental for responsive layouts where you might want elements to stack vertically on mobile but appear side-by-side on larger screens. The flex direction utility is often your starting point when building a flex-based layout and works alongside other flex utilities like justify-content and align-items.
Flexbox & Grid1 variant3 examples
Basic usage:
<div class="flex flex-row gap-4">
<div class="p-4 bg-blue-100">Item 1</div>
<div class="p-4 bg-blue-200">Item 2</div>
<div class="p-4 bg-blue-300">Item 3</div>
</div>
Examples
<div class="flex flex-row gap-4">
<div class="p-4 bg-blue-100">Item 1</div>
<div class="p-4 bg-blue-200">Item 2</div>
<div class="p-4 bg-blue-300">Item 3</div>
</div>
<div class="flex flex-col gap-4">
<div class="p-4 bg-green-100">Item 1</div>
<div class="p-4 bg-green-200">Item 2</div>
<div class="p-4 bg-green-300">Item 3</div>
</div>
<!-- Responsive layout: column on mobile, row on desktop -->
<div class="flex flex-col md:flex-row gap-6">
<div class="w-full md:w-1/3 p-4 bg-gray-100 rounded-lg">
<h2 class="font-bold text-lg mb-2">Sidebar</h2>
<p>This will be on top on mobile, but to the left on desktop.</p>
</div>
<div class="w-full md:w-2/3 p-4 bg-white rounded-lg shadow">
<h2 class="font-bold text-xl mb-4">Main Content</h2>
<p>This will be below the sidebar on mobile, but to the right on desktop.</p>
</div>
</div>
Live Preview
Try the Flex Direction utility with different values
Variants
row: items arranged horizontally (default), row-reverse: items arranged horizontally in reverse order, col: items arranged vertically, col-reverse: items arranged vertically in reverse order
rowrow-reversecolcol-reverse
Tips & Reference
Related Functions
Flex WrapControls whether flex items should wrap onto multiple lines ...
FlexSets how a flex item grows or shrinks to fit available space...
Flex GrowControls the ability of a flex item to grow when there is ex...
Flex ShrinkControls the ability of a flex item to shrink when there isn...
OrderControls the order in which flex or grid items appear within...
View all Flexbox & Grid utilities