📖 Scenario: You are creating a simple photo gallery webpage. The gallery should arrange photos in a grid layout. You want to control how the photos flow and where they are placed inside the grid using Tailwind CSS.
🎯 Goal: Build a responsive photo gallery using Tailwind CSS grid utilities. You will set up the grid container, configure the grid flow direction, and place specific photos in certain grid cells.
📋 What You'll Learn
Use Tailwind CSS grid classes to create a grid container
Control the grid auto-flow direction using Tailwind utilities
Place specific grid items in exact grid cells using Tailwind placement classes
Ensure the gallery is responsive and visually clear
💡 Why This Matters
🌍 Real World
Grid layouts are common in photo galleries, product listings, and dashboards. Knowing how to control flow and placement helps create clean, organized designs.
💼 Career
Front-end developers often use CSS grid and Tailwind CSS to build responsive, accessible layouts quickly and efficiently.
Progress0 / 4 steps
1
Create the HTML structure with a grid container and 6 photo items
Write the HTML code to create a <div> with the class grid to act as the grid container. Inside it, add 6 <div> elements each with the class bg-blue-300 and text content from Photo 1 to Photo 6 respectively.
Tailwind
Hint
Use a <div> with class grid for the container. Then add 6 child <div> elements with class bg-blue-300 and text from Photo 1 to Photo 6.
2
Add grid columns and set auto-flow direction to row
Add the Tailwind classes grid-cols-3 and grid-flow-row to the grid container <div> to create 3 columns and set the grid auto-flow direction to row.
Tailwind
Hint
Add grid-cols-3 and grid-flow-row classes to the container <div> to create 3 columns and flow items by rows.
3
Change grid auto-flow to column and add gap between items
Modify the grid container <div> classes to use grid-flow-col instead of grid-flow-row. Also add the class gap-4 to add space between grid items.
Tailwind
Hint
Replace grid-flow-row with grid-flow-col and add gap-4 to add spacing between photos.
4
Place Photo 1 in first row and second column using Tailwind placement classes
Add the classes col-start-2 and row-start-1 to the Photo 1<div> to place it in the first row and second column of the grid.
Tailwind
Hint
Add col-start-2 and row-start-1 classes to the first photo's <div> to place it in the second column of the first row.
Practice
(1/5)
1. What does the Tailwind class grid-flow-row do in a grid container?
easy
A. It places grid items in rows from left to right, then top to bottom.
B. It places grid items in columns from top to bottom, then left to right.
C. It fills grid gaps by rearranging items densely.
D. It disables grid auto-placement.
Solution
Step 1: Understand grid auto-flow direction
The class grid-flow-row sets the grid to place items in rows first, meaning items fill left to right in each row.
Step 2: Confirm placement order
After filling a row, the next items start on the next row below, continuing left to right again.
Final Answer:
It places grid items in rows from left to right, then top to bottom. -> Option A
Quick Check:
grid-flow-row = row-wise placement [OK]
Hint: Row flow means fill left to right, then next row down [OK]
Common Mistakes:
Confusing row flow with column flow
Thinking dense is automatic without class
Assuming grid items stack vertically by default
2. Which Tailwind class correctly applies grid auto-flow to fill columns first and then rows?
easy
A. grid-flow-row
B. grid-auto-flow-col
C. grid-flow-col
D. grid-auto-columns
Solution
Step 1: Identify correct Tailwind syntax for column flow
The class grid-flow-col sets the grid to fill columns first, placing items top to bottom in each column.
Step 2: Verify other options
Options grid-auto-flow-col and grid-auto-columns are not valid Tailwind classes for this purpose.
Final Answer:
grid-flow-col -> Option C
Quick Check:
grid-flow-col = column-wise placement [OK]
Hint: Use grid-flow-col for column-first placement [OK]
Common Mistakes:
Using incorrect class names like grid-auto-flow-col
A. A spans first two columns in row 1, B fills third column row 1, C and D fill next row
B. A spans first two columns in row 1, B and C fill next row, D fills gap in row 1
C. A spans first two columns in row 1, B fills third column row 1, D fills gap in row 1, C in next row
D. A spans first two columns in row 1, B, C, D all fill next row
Solution
Step 1: Understand grid-flow-row-dense behavior
The grid-flow-row-dense class places items row-wise but tries to fill gaps left by spanning items.
Step 2: Analyze item placement
Item A spans 2 columns in row 1, leaving the 3rd column free. Item B fits in that 3rd column in row 1. Items C and D go to the next row filling columns 1 and 2.
Final Answer:
A spans first two columns in row 1, B fills third column row 1, C and D fill next row -> Option A
Quick Check:
Dense fills gaps left by spanning items [OK]
Hint: Dense fills gaps left by spanning items in row flow [OK]
Common Mistakes:
Ignoring dense and placing items strictly in order
But items stack vertically in a single column instead of forming multiple columns. What is the likely mistake?
medium
A. Using grid-flow-col instead of grid-flow-row
B. Missing grid-cols or grid-rows to define grid size
C. gap-4 is causing layout issues
D. Items need explicit width to stack
Solution
Step 1: Check grid container setup
Using grid-flow-col places items top to bottom in each column, then next column, but without defining the number of columns or rows, the grid defaults to one implicit column.
Step 2: Identify missing grid size
Without grid-cols-3 or similar, the grid does not create multiple columns, so items stack vertically in one column.
Final Answer:
Missing grid-cols or grid-rows to define grid size -> Option B
Quick Check:
Define grid size to control flow layout [OK]
Hint: Always set grid-cols or grid-rows with grid-flow [OK]
Common Mistakes:
Assuming grid-flow-col alone creates columns
Blaming gap for layout issues
Forgetting grid size classes
5. You want a responsive grid that places items in columns on small screens and switches to dense row flow on larger screens. Which Tailwind classes achieve this?
hard
A. grid grid-flow-row sm:grid-flow-row-dense grid-cols-2 sm:grid-cols-4 gap-3
B. grid grid-flow-row-dense sm:grid-flow-col grid-cols-4 sm:grid-cols-2 gap-3
C. grid grid-flow-col-dense sm:grid-flow-row grid-cols-2 sm:grid-cols-4 gap-3
D. grid grid-flow-col sm:grid-flow-row-dense grid-cols-2 sm:grid-cols-4 gap-3
Solution
Step 1: Set default column flow for small screens
The class grid-flow-col sets column flow by default (small screens).
Step 2: Override with dense row flow on larger screens
The class sm:grid-flow-row-dense changes flow to dense row on screens medium and up.
Step 3: Adjust columns for responsiveness
grid-cols-2 for small screens and sm:grid-cols-4 for larger screens set grid size accordingly.
Final Answer:
grid grid-flow-col sm:grid-flow-row-dense grid-cols-2 sm:grid-cols-4 gap-3 -> Option D
Quick Check:
Use responsive prefixes to switch flow and columns [OK]
Hint: Use sm: prefix to change flow and columns on bigger screens [OK]
Common Mistakes:
Mixing flow directions and breakpoints incorrectly
Forgetting to set grid-cols for each breakpoint
Using non-existent classes like grid-flow-col-dense
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.