Main Content
This area grows to fill available space.
Flexbox changed how we build layouts on the web. Before flexbox, creating responsive layouts meant dealing with floats, clearfix hacks, and way too much custom CSS.
With Tailwind CSS, flexbox becomes even more straightforward. You get utility classes that map directly to CSS flexbox properties, so you can build layouts fast without switching between your HTML and CSS files.
Whether you're building a navigation bar, a card grid, or centering content (yes, centering things is finally easy), flexbox utilities in Tailwind have you covered.
Let me show you exactly how to use them.
To use flexbox in Tailwind, start by adding the flex class to your container. This turns on flexbox for all the direct children inside that container.
By default, flex arranges items horizontally in a row. But you can control the direction with these utilities:
flex-row - Items flow left to right (the default)flex-col - Items stack vertically top to bottomflex-row-reverse - Items flow right to leftflex-col-reverse - Items stack bottom to topHere's a simple horizontal layout:
```html
Item 1
Item 2
Item 3
```
And here's the same layout but vertical:
```html
Item 1
Item 2
Item 3
```
The reverse variants are useful when you need to flip the order without changing your HTML. This comes in handy for responsive designs where you want content to appear in different orders on mobile vs desktop.
This is where flexbox really shines. You get two main ways to position items - along the main axis with justify-* utilities, and along the cross axis with items-* utilities.
The main axis is the direction your items flow (horizontal for flex-row, vertical for flex-col). The cross axis is perpendicular to that.
Justify content utilities (main axis positioning):
justify-start - Pack items to the startjustify-center - Center itemsjustify-end - Pack items to the endjustify-between - Space items evenly with no space at edgesjustify-around - Space items with half-size space at edgesjustify-evenly - Space items with equal space everywhereHere's centering done right:
```html
Perfectly Centered
```
Align items utilities (cross axis positioning):
items-start - Align to start of cross axisitems-center - Center along cross axisitems-end - Align to end of cross axisitems-stretch - Stretch to fill container (default)items-baseline - Align text baselinesHere's a practical example showing different alignment options:
The combination of justify-between and items-center creates that classic navbar layout where the logo is on the left, navigation in the middle, and action button on the right - all vertically centered.
Sometimes you want certain flex items to take up more space than others. That's where the flex sizing utilities come in.
Here's what each one does:
flex-1 - Grows and shrinks equally, ignoring initial sizeflex-auto - Grows and shrinks based on content sizeflex-initial - Shrinks but doesn't grow (default behavior)flex-none - Doesn't grow or shrink at allThe most common one you'll use is flex-1. It tells an item to take up all available space.
Here's a classic sidebar layout where the main content area grows to fill space:
```html
Sidebar
Fixed width sidebar
Main Content
This area grows to fill remaining space
```
You can also use multiple flex-1 items to create equal-width columns:
```html
Column 1
Column 2
Column 3
```
Each column automatically takes up an equal share of the available space, no matter the screen size.
By default, flex items try to fit on one line. But sometimes you want them to wrap to multiple lines when space runs out.
That's where flex-wrap comes in:
flex-nowrap - Keep everything on one line (default)flex-wrap - Let items wrap to new linesflex-wrap-reverse - Wrap in reverse orderHere's a tag list that wraps when it needs to:
```html
React
TypeScript
Tailwind CSS
Next.js
Node.js
PostgreSQL
```
Now for spacing. The gap utility is your best friend here. It adds space between flex items without needing margins on each item.
Use gap-* for equal spacing, or gap-x-* and gap-y-* for different horizontal and vertical spacing:
```html
```
The gap utility is way cleaner than adding margins to every item, and it automatically handles edge cases.
Now let's put everything together with some real-world patterns you'll use all the time.
Card grid that adapts to screen size:
```html
Feature One
Description of the first feature goes here.
Feature Two
Description of the second feature goes here.
Feature Three
Description of the third feature goes here.
```
The cards grow to fill space but wrap to new rows when needed. The min-w-64 prevents them from getting too narrow.
Sticky footer layout:
```html
Header
Main Content
This area grows to fill available space.
```
The footer stays at the bottom no matter how much content you have. The main content area uses flex-1 to fill the space.
Profile card with mixed alignment:
```html
Sarah Johnson
Product Designer
```
This combines everything - fixed-size avatar, flexible text area, and a button that stays put.
That's flexbox in Tailwind CSS. With just a handful of utility classes, you can build almost any layout you need. The best part is how readable your code stays - you can see exactly what your layout does just by looking at the class names.
Start with flex, add direction with flex-row or flex-col, position with justify-* and items-*, and control sizing with flex-1. Mix in some gap for spacing and flex-wrap when needed, and you're set.
Go build something awesome!
Get notified when we add new templates, components, and more!
WindyBase is a weekly curated Tailwind CSS template and tool directory built for the modern developer.
© 2025 WindyBase. All rights reserved.