How do I use Tailwind to create a responsive grid layout?
Asked on Oct 15, 2025
Answer
To create a responsive grid layout with Tailwind CSS, you can use its grid utilities to define columns and responsive classes to adjust the layout for different screen sizes.
<!-- BEGIN COPY / PASTE -->
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-4">
<div class="bg-blue-500 p-4">Item 1</div>
<div class="bg-blue-500 p-4">Item 2</div>
<div class="bg-blue-500 p-4">Item 3</div>
<div class="bg-blue-500 p-4">Item 4</div>
<div class="bg-blue-500 p-4">Item 5</div>
<div class="bg-blue-500 p-4">Item 6</div>
</div>
<!-- END COPY / PASTE -->Additional Comment:
- The "grid" class initializes a CSS Grid layout.
- "grid-cols-1" sets the default to one column, which is ideal for small screens.
- "sm:grid-cols-2" and "md:grid-cols-3" adjust the number of columns for larger screens.
- "gap-4" adds spacing between grid items.
- Responsive classes like "sm:" and "md:" apply styles at specific breakpoints.
Recommended Links: