<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4">
<!-- cards here -->
</div>The class md:grid-cols-4 sets the grid to 4 columns on medium screens and larger.
Before medium screens, smaller breakpoints apply.
gap-4 adds equal spacing between grid rows and columns.
space-x-4 only adds horizontal spacing between flex items.
<div class="grid grid-cols-3 gap-6 p-4"> <div class="bg-blue-500 text-white p-6 rounded">Card 1</div> <div class="bg-blue-500 text-white p-6 rounded">Card 2</div> <div class="bg-blue-500 text-white p-6 rounded">Card 3</div> <div class="bg-blue-500 text-white p-6 rounded">Card 4</div> </div>
The container uses grid-cols-3 so there are 3 columns.
There are 4 cards, so the last card wraps to the next row.
gap-6 adds spacing between cards.
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-5"> <article class="bg-white p-4 rounded shadow">Card content</article> <article class="bg-white p-4 rounded shadow">Card content</article> <article class="bg-white p-4 rounded shadow">Card content</article> </div>
Adding tabindex="0" makes each card focusable by keyboard.
role="button" is incorrect because the container is not a button.
aria-hidden="true" hides content from screen readers, which is bad here.
alt attribute applies only to images, not article.
repeat(auto-fit, minmax(12rem, 1fr)) creates as many columns as fit in the container.
Each column is at least 12rem wide and can grow to fill available space.
This makes the grid responsive, adjusting columns based on screen width.