Build a Tailwind grid that changes across breakpoints
Admin ·
Give a repeating list of cards one layout for small screens and more columns as space opens up. A featured card can take two tracks on larger screens while fitting the single track on a phone.
Check the same cards at three widths
Choose Responsive cards. At 390 px, the preview has one column. Change Preview width to 767 px and it still has one column. At 768 px, md begins and the list has two columns.
At 1,024 px, lg begins and the preview has four equal columns. With three 16 px column gaps, each column is 244 px wide. The featured first card spans two columns and their gap, so it is 504 px wide.
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-x-[16px] gap-y-[12px]">
<div class="col-span-1 md:col-span-2 lg:col-span-2">Item 1</div>
</div>Tailwind CSS grid template columnsTailwind CSS responsive design and default breakpointsTailwind CSS row and column gapsTailwind CSS grid column span
Check the featured card's width after changing its span
Change First item span to 3. At 768 px the card still occupies both available columns. At 1,024 px it occupies three columns and two gaps, or 764 px. The markup changes to lg:col-span-3 while keeping md:col-span-2.
Choose Image gallery if all items should have equal widths. That preset uses one track per item and two, three and six columns across the same width ranges.
Tailwind CSS grid column spanTailwind CSS responsive design and default breakpoints
Verify the markup in your Tailwind build
Download tailwind-grid.html and place the markup in a source file scanned by Tailwind CSS v4. Replace the example items with your cards and open the page at 767, 768 and 1,024 px. Check the layout and keep the two gap classes to preserve the 16 px horizontal and 12 px vertical spacing.
If the classes have no effect, check that Tailwind CSS is loaded and the build scanned the source file. If the layout changes at different widths, compare your project’s breakpoint theme with the default md and lg values.
Tailwind CSS source detectionTailwind CSS responsive design and default breakpointsTailwind CSS row and column gaps
Common questions
Why do the gap classes have square brackets?
Tailwind uses square brackets for explicit values such as gap-x-[16px]. Your chosen gap stays in pixels regardless of the theme's spacing scale.
Can I keep a different set of breakpoint values in my project?
The HTML uses md and lg names. Your Tailwind theme determines their actual widths when you build the project.