Row spanning lets a cell in a grid or table stretch across multiple rows. This helps organize content better and saves space.
Row spanning in Tailwind
row-span-{n}Replace {n} with the number of rows to span.
This class works inside a parent with grid display.
<div class="grid grid-cols-2 grid-rows-3 gap-2"> <div class="row-span-2 bg-blue-300">Spans 2 rows</div> <div class="bg-blue-100">Row 1</div> <div class="bg-blue-100">Row 2</div> <div class="bg-blue-100">Row 3</div> </div>
<div class="grid grid-cols-2 grid-rows-4 gap-1"> <div class="row-span-3 bg-green-300">Spans 3 rows</div> <div class="bg-green-100">Row 1</div> <div class="bg-green-100">Row 2</div> <div class="bg-green-100">Row 3</div> </div>
This example shows a grid with 3 rows and 3 columns. The first cell uses row-span-2 to stretch vertically over two rows. The other cells fill the remaining spaces. The colors and center alignment help you see the layout clearly.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Tailwind Row Spanning Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6"> <h1 class="text-xl font-bold mb-4">Row Spanning with Tailwind CSS</h1> <div class="grid grid-rows-3 grid-cols-3 gap-4 border border-gray-300 p-4"> <div class="row-span-2 bg-indigo-400 text-white flex items-center justify-center">Spans 2 rows</div> <div class="bg-indigo-200 flex items-center justify-center">Cell 1</div> <div class="bg-indigo-200 flex items-center justify-center">Cell 2</div> <div class="bg-indigo-200 flex items-center justify-center">Cell 3</div> <div class="bg-indigo-200 flex items-center justify-center">Cell 4</div> <div class="bg-indigo-200 flex items-center justify-center">Cell 5</div> </div> </body> </html>
Row spanning only works inside a grid container.
Make sure the parent has enough rows defined to span across.
Use gap classes to add space between grid items for clarity.
Row spanning lets a grid item cover multiple rows vertically.
Use row-span-{n} inside a grid container to control spanning.
This helps create flexible and organized layouts with Tailwind CSS.
Practice
row-span-3 do inside a grid container?Solution
Step 1: Understand the
This class controls how many rows a grid item covers vertically.row-span-{n}classStep 2: Apply
The number 3 means the item will cover 3 rows in the grid layout.row-span-3meaningFinal Answer:
Makes the grid item span 3 rows vertically. -> Option AQuick Check:
row-span-3 = span 3 rows [OK]
- Confusing row-span with column-span
- Thinking it adds padding or margin
- Assuming it sets fixed height
Solution
Step 1: Recall Tailwind's row spanning syntax
The correct format uses a dash:row-span-{number}.Step 2: Check each option
Onlyrow-span-2matches the correct syntax for spanning 2 rows.Final Answer:
row-span-2 -> Option BQuick Check:
Correct syntax = row-span-2 [OK]
- Using col-span instead of row-span
- Missing dash between words and number
- Reversing order of words
<div class="grid grid-rows-4 grid-cols-2 gap-2"> <div class="row-span-2 bg-blue-500">A</div> <div class="bg-red-500">B</div> <div class="bg-green-500">C</div> <div class="bg-yellow-500">D</div> </div>
How many rows tall will the blue box labeled 'A' appear?
Solution
Step 1: Identify the row-span class on the blue box
The blue box hasrow-span-2, meaning it covers 2 rows vertically.Step 2: Understand grid rows count
The grid has 4 rows total, but the blue box only spans 2 of them.Final Answer:
2 rows tall -> Option DQuick Check:
row-span-2 means 2 rows [OK]
- Assuming it spans all rows
- Confusing rows with columns
- Ignoring the row-span class
<div class="grid grid-rows-3 grid-cols-3"> <div class="row-span3 bg-purple-400">Item</div> </div>
What is the error?
Solution
Step 1: Check the row-span class syntax
The class is written asrow-span3but Tailwind requires a dash:row-span-3.Step 2: Understand the effect of syntax error
Without the dash, Tailwind ignores the class, so no spanning happens.Final Answer:
Missing dash inrow-span3, should berow-span-3. -> Option AQuick Check:
Correct syntax needs dash [OK]
- Forgetting the dash in class names
- Assuming grid-rows count limits spanning
- Confusing row-span with col-span
Solution
Step 1: Set grid container with 3 columns and 4 rows
The container needsgrid-cols-3andgrid-rows-4to match the layout.Step 2: Make the item span 2 rows and 2 columns
Userow-span-2for vertical spanning andcol-span-2for horizontal spanning.Final Answer:
grid grid-cols-3 grid-rows-4; item: row-span-2 col-span-2 -> Option CQuick Check:
Correct grid + row-span-2 + col-span-2 [OK]
- Mixing up grid-cols and grid-rows numbers
- Using wrong span numbers for item
- Forgetting to span columns when needed
Ready to prove it?
Pass the test and this pattern moves unknown
