Flexbox & Grid

Powerful utilities for creating flexible, responsive layouts using CSS Flexbox and Grid. These modern layout systems make it easier to design complex interfaces that adapt to different screen sizes. In Tailwind v4, Flexbox and Grid utilities are enhanced with better support for logical properties (start/end instead of left/right) and improved interaction with other modern CSS features.

23 utilitiesflexbox-grid
Official Documentation

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.

<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>
1 variant3 examples
rowrow-reversecol+1

Flex Wrap

Controls whether flex items should wrap onto multiple lines or be forced into a single line. This is essential for responsive design, allowing items to adapt to different screen sizes by either wrapping to new lines when space is limited or maintaining a single row or column. Flex wrap works with flex-direction to determine the layout behavior.

<div class="flex flex-wrap gap-4"> <div class="p-4 bg-blue-100 w-32">Item 1</div> <div class="p-4 bg-blue-200 w-32">Item 2</div> <div class="p-4 bg-blue-300 w-32">Item 3</div> <div class="p-4 bg-blue-400 w-32">Item 4</div> <div class="p-4 bg-blue-500 w-32">Item 5</div> </div>
1 variant4 examples
wrapwrap-reversenowrap

Flex

Sets how a flex item grows or shrinks to fit available space. This shorthand combines flex-grow, flex-shrink, and flex-basis into a single declaration, controlling how items resize within their container. Understanding the flex utility is key to creating responsive, flexible layouts where elements adapt properly to different screen sizes and content amounts.

<div class="flex gap-4"> <div class="flex-1 p-4 bg-blue-100">flex-1: Grows and shrinks as needed</div> <div class="flex-1 p-4 bg-blue-200">flex-1: Equal growing with sibling</div> </div>
1 variant4 examples
1autoinitial+1

Flex Grow

Controls the ability of a flex item to grow when there is extra space in the flex container. This utility helps distribute available space proportionally between flex items. Items with higher grow values receive a larger portion of the available space. In Tailwind v4, flex-grow utilities work better with other layout features and responsive variants.

<div class="flex gap-4"> <div class="grow-0 p-4 w-20 bg-blue-100">Not growing</div> <div class="grow p-4 bg-blue-300">Growing to fill available space</div> <div class="grow-0 p-4 w-20 bg-blue-100">Not growing</div> </div>
1 variant4 examples
01

Flex Shrink

Controls the ability of a flex item to shrink when there isn't enough space in the flex container. This is crucial for responsive designs, determining how items behave when space becomes limited. Items with higher shrink values will reduce their size more aggressively when needed. In Tailwind v4, flex-shrink utilities have improved responsive behavior.

<div class="flex w-80 bg-gray-100 overflow-hidden"> <div class="shrink p-4 bg-blue-100 whitespace-nowrap">Can shrink when needed</div> <div class="shrink-0 p-4 bg-blue-300 whitespace-nowrap">Won't ever shrink</div> </div>
1 variant3 examples
01

Order

Controls the order in which flex or grid items appear within their container, regardless of their source order in the HTML. This is powerful for responsive designs, allowing you to rearrange elements based on screen size without changing the HTML structure. In Tailwind v4, order utilities have improved integration with other layout systems and better accessibility considerations.

<div class="flex"> <div class="order-3 p-4 bg-blue-300">First in HTML, third visually</div> <div class="order-1 p-4 bg-blue-100">Second in HTML, first visually</div> <div class="order-2 p-4 bg-blue-200">Third in HTML, second visually</div> </div>
1 variant4 examples
123+12

Grid Template Columns

Defines the columns in a CSS Grid layout. This utility allows you to create complex, two-dimensional layouts with precise control over both rows and columns. Grid Template Columns sets up the horizontal tracks in your grid, defining how many columns you want and how they should size themselves. In Tailwind v4, grid utilities have enhanced support for modern features like subgrid and masonry layouts.

<div class="grid grid-cols-3 gap-4"> <div class="bg-blue-100 p-4">Column 1</div> <div class="bg-blue-200 p-4">Column 2</div> <div class="bg-blue-300 p-4">Column 3</div> </div>
1 variant4 examples
123+10

Grid Column Start / End

Controls how an element spans across columns in a CSS Grid. Using grid-column-start and grid-column-end (or the shorthand grid-column), you can position items precisely within a grid, making them span multiple columns, or place them in specific column tracks. Combined with responsive variants, this provides powerful control over complex layouts at different screen sizes.

<div class="grid grid-cols-4 gap-4"> <div class="bg-blue-100 p-4">1</div> <div class="col-span-2 bg-blue-300 p-4">Spans 2 columns</div> <div class="bg-blue-100 p-4">4</div> </div>
1 variant4 examples
autospan-1span-2+27

Grid Template Rows

Defines the rows in a CSS Grid layout, allowing you to control the vertical tracks in your grid. While grid-template-columns handles the horizontal structure, grid-template-rows governs the height of each row. This is essential for creating well-defined grid layouts where you need control over both dimensions. In Tailwind v4, row utilities have improved compatibility with container queries and logical properties.

<div class="grid grid-rows-3 grid-flow-col gap-4 h-48"> <div class="bg-blue-100 p-4">Row 1, Col 1</div> <div class="bg-blue-200 p-4">Row 2, Col 1</div> <div class="bg-blue-300 p-4">Row 3, Col 1</div> <div class="bg-green-100 p-4">Row 1, Col 2</div> <div class="bg-green-200 p-4">Row 2, Col 2</div> <div class="bg-green-300 p-4">Row 3, Col 2</div> </div>
1 variant4 examples
123+4

Grid Row Start / End

Controls how an element spans across rows in a CSS Grid. Similar to grid-column utilities, grid-row-start and grid-row-end (or the shorthand grid-row) let you position items vertically within a grid. This allows for precise placement and spanning across multiple rows. When combined with responsive variants, you gain powerful control over complex layouts that adapt to different screen sizes.

<div class="grid grid-rows-3 grid-cols-3 gap-4 h-64"> <div class="row-span-2 bg-blue-300 p-4">Spans 2 rows</div> <div class="bg-blue-100 p-4">1 row, 1 column</div> <div class="bg-blue-100 p-4">1 row, 1 column</div> <div class="row-span-3 bg-green-300 p-4">Spans all 3 rows</div> <div class="bg-blue-100 p-4">1 row, 1 column</div> <div class="bg-blue-100 p-4">1 row, 1 column</div> <div class="bg-blue-100 p-4">1 row, 1 column</div> </div>
1 variant4 examples
autospan-1span-2+21

Grid Auto Flow

Controls how the auto-placement algorithm works in CSS Grid, determining how items that aren't explicitly placed are automatically arranged. This utility helps manage the flow direction and density of automatically placed grid items. In Tailwind v4, grid-auto-flow utilities have improved compatibility with other grid features like grid-template-areas.

<div class="grid grid-cols-3 grid-auto-flow-row gap-4"> <div class="bg-blue-100 p-4">1</div> <div class="bg-blue-200 p-4">2</div> <div class="bg-blue-300 p-4">3</div> <div class="col-span-2 bg-blue-400 p-4">4 (spans 2 cols)</div> <div class="bg-blue-500 p-4">5</div> <div class="bg-blue-200 p-4">6</div> </div>
1 variant4 examples
rowcoldense+2

Grid Auto Columns

Sets the size of implicitly created columns in a CSS Grid. While grid-template-columns defines explicit columns, grid-auto-columns controls the sizing of automatically generated columns that aren't explicitly defined. This is particularly useful for grids where the number of columns may vary or when using grid-auto-flow: column to create columns dynamically.

<div class="grid grid-flow-col auto-cols-auto gap-4 p-4 bg-gray-100 rounded-lg"> <div class="bg-blue-100 p-4 rounded">Auto-sized column</div> <div class="bg-blue-200 p-4 rounded">Content determines width</div> <div class="bg-blue-300 p-4 rounded">Another auto-sized column</div> </div>
1 variant4 examples
autominmax+1

Grid Auto Rows

Sets the size of implicitly created rows in a CSS Grid. Similar to grid-auto-columns, this utility controls the sizing of automatically generated rows that aren't explicitly defined with grid-template-rows. This is essential for grids with dynamic content where the number of rows isn't known in advance or when using grid-auto-flow: row.

<div class="grid grid-cols-3 auto-rows-auto gap-4 p-4 bg-gray-100 rounded-lg"> <div class="bg-blue-100 p-4 rounded">Auto-sized row</div> <div class="bg-blue-200 p-8 rounded">Taller content</div> <div class="bg-blue-300 p-4 rounded">Auto-sized row</div> <div class="bg-blue-100 p-4 rounded">Next row</div> <div class="bg-blue-200 p-4 rounded">Next row</div> <div class="bg-blue-300 p-4 rounded">Next row</div> </div>
1 variant4 examples
autominmax+1

Gap

Controls the spacing between rows and columns in grid and flexbox layouts. This utility provides a clean, consistent way to create gutters between elements without using margins that might cause layout issues. In Tailwind v4, gap utilities work with all layout modes and have improved compatibility with other spacing utilities.

<div class="grid grid-cols-3 gap-4"> <div class="bg-blue-100 p-4 rounded">Item 1</div> <div class="bg-blue-100 p-4 rounded">Item 2</div> <div class="bg-blue-100 p-4 rounded">Item 3</div> <div class="bg-blue-100 p-4 rounded">Item 4</div> <div class="bg-blue-100 p-4 rounded">Item 5</div> <div class="bg-blue-100 p-4 rounded">Item 6</div> </div>
1 variant4 examples
00.51+28

Justify Content

Controls how items are positioned along the main axis of a flex or grid container. For a flex row, this is horizontal alignment; for a flex column, this is vertical alignment. This utility is fundamental for distributing space and aligning items within containers. In Tailwind v4, justify utilities have improved compatibility with logical properties for better RTL support.

<div class="flex justify-start bg-gray-100 p-4 rounded-lg"> <div class="bg-blue-100 p-4 rounded">Start</div> <div class="bg-blue-200 p-4 rounded">Center</div> <div class="bg-blue-300 p-4 rounded">End</div> </div>
1 variant7 examples
normalstartend+5

Justify Items

Controls alignment of grid items along their inline (row) axis within their grid areas. While justify-content controls the alignment of the entire grid container's contents, justify-items controls individual grid items within their cells. This is particularly useful for grid layouts where you want consistent alignment of items within their allocated spaces.

<div class="grid grid-cols-3 justify-items-start gap-4 bg-gray-100 p-4 rounded-lg"> <div class="bg-blue-100 p-4 rounded">Start aligned</div> <div class="bg-blue-200 p-4 rounded">Start aligned</div> <div class="bg-blue-300 p-4 rounded">Start aligned</div> <div class="bg-blue-100 p-4 rounded">Start aligned</div> <div class="bg-blue-200 p-4 rounded">Start aligned</div> <div class="bg-blue-300 p-4 rounded">Start aligned</div> </div>
1 variant5 examples
autostartend+2

Justify Self

Controls the alignment of an individual grid item along the inline (row) axis within its grid cell. While justify-items applies to all items in a grid, justify-self lets you override that behavior for specific items. This gives you precise control over the horizontal positioning of individual elements in a grid layout.

<div class="grid grid-cols-3 gap-4 bg-gray-100 p-4 rounded-lg"> <div class="justify-self-start bg-blue-100 p-4 rounded">Start</div> <div class="justify-self-center bg-blue-200 p-4 rounded">Center</div> <div class="justify-self-end bg-blue-300 p-4 rounded">End</div> <div class="justify-self-stretch bg-blue-400 p-4 rounded">Stretch</div> <div class="bg-blue-500 p-4 rounded text-white">Default</div> <div class="bg-blue-600 p-4 rounded text-white">Default</div> </div>
1 variant3 examples
autostartend+2

Align Content

Controls how rows of content are positioned in a multi-line flex container or a grid container along the cross axis. In a flex column layout, this controls horizontal alignment; in a flex row layout, this controls vertical alignment. This is particularly useful when there are multiple rows of content with extra space in the container. In Tailwind v4, align utilities have improved compatibility with logical properties for better RTL support.

<div class="flex flex-wrap content-start h-64 bg-gray-100 p-4 rounded-lg"> <div class="w-1/3 p-2"><div class="bg-blue-100 p-4 rounded">1</div></div> <div class="w-1/3 p-2"><div class="bg-blue-200 p-4 rounded">2</div></div> <div class="w-1/3 p-2"><div class="bg-blue-300 p-4 rounded">3</div></div> <div class="w-1/3 p-2"><div class="bg-blue-400 p-4 rounded">4</div></div> <div class="w-1/3 p-2"><div class="bg-blue-500 p-4 rounded text-white">5</div></div> </div>
1 variant7 examples
normalstartend+5

Align Items

Controls how flex or grid items are aligned along the cross axis of their container. In a flex row layout, this governs vertical alignment; in a flex column layout, this controls horizontal alignment. This utility is essential for controlling how items align in relation to each other within a row or column. In Tailwind v4, align utilities have improved compatibility with logical properties for better RTL support.

<div class="flex items-start h-32 bg-gray-100 p-4 rounded-lg"> <div class="bg-blue-100 p-4 rounded">Short</div> <div class="bg-blue-200 p-8 rounded">Medium</div> <div class="bg-blue-300 p-12 rounded">Tall</div> </div>
1 variant7 examples
startendcenter+2

Align Self

Controls how an individual flex or grid item is aligned along the cross axis, overriding the container's align-items setting. This utility allows for precise control over the alignment of specific items within a flex or grid container, letting you create exceptions to the overall alignment pattern. In Tailwind v4, align-self utilities have improved compatibility with logical properties for better RTL support.

<div class="flex items-center h-32 bg-gray-100 p-4 rounded-lg"> <div class="self-start bg-blue-100 p-4 rounded">Start</div> <div class="bg-blue-200 p-4 rounded">Center (from container)</div> <div class="self-end bg-blue-300 p-4 rounded">End</div> <div class="self-stretch bg-blue-400 p-4 rounded">Stretch</div> <div class="self-baseline bg-blue-500 p-4 text-lg text-white rounded">Baseline</div> </div>
1 variant4 examples
autostartend+3

Place Content

A shorthand utility that sets both align-content and justify-content properties at once. This makes it quicker to center or distribute space for content in both dimensions within a flex or grid container. In Tailwind v4, place utilities have improved compatibility with logical properties for better RTL support and work seamlessly with other layout features.

<div class="grid grid-cols-3 place-content-center h-64 bg-gray-100 p-4 rounded-lg gap-4"> <div class="bg-blue-100 p-4 rounded">1</div> <div class="bg-blue-200 p-4 rounded">2</div> <div class="bg-blue-300 p-4 rounded">3</div> <div class="bg-blue-400 p-4 rounded">4</div> </div>
1 variant6 examples
startendcenter+4

Place Items

A shorthand utility that sets both align-items and justify-items properties at once. This allows for quick positioning of all grid or flex items within their individual areas or cells. Place-items is particularly useful in grid layouts where you want consistent alignment behavior in both dimensions. In Tailwind v4, place utilities work seamlessly with other layout properties and have improved RTL support.

<div class="grid grid-cols-3 place-items-center gap-4 h-64 bg-gray-100 p-4 rounded-lg"> <div class="bg-blue-100 p-4 rounded">1</div> <div class="bg-blue-200 p-4 rounded">2</div> <div class="bg-blue-300 p-4 rounded">3</div> <div class="bg-blue-400 p-4 rounded">4</div> <div class="bg-blue-500 p-4 rounded text-white">5</div> <div class="bg-blue-600 p-4 rounded text-white">6</div> </div>
1 variant6 examples
startendcenter+1

Place Self

A shorthand utility that sets both align-self and justify-self properties at once. This allows for positioning an individual grid or flex item within its grid area or flex line, overriding the container's place-items settings. Place-self is perfect for creating exceptions to the overall alignment pattern without needing separate utilities for each axis. In Tailwind v4, place-self utilities have better RTL language support and improved compatibility with other layout properties.

<div class="grid grid-cols-3 gap-4 place-items-start h-64 bg-gray-100 p-4 rounded-lg"> <div class="bg-blue-100 p-4 rounded">Start (default)</div> <div class="place-self-center bg-blue-300 p-4 rounded">Centered</div> <div class="place-self-end bg-blue-500 p-4 rounded text-white">End</div> <div class="place-self-stretch bg-blue-200 p-4 rounded">Stretch</div> <div class="bg-blue-400 p-4 rounded">Start (default)</div> <div class="bg-blue-600 p-4 rounded text-white">Start (default)</div> </div>
1 variant3 examples
autostartend+2