How to Build Responsive Layouts with Tailwind CSS
Tailwind CSS uses a mobile-first responsive system. This means that un-prefixed classes (like grid-cols-1) apply to all screen sizes, while prefixed classes (like md:grid-cols-3) only apply at the specified breakpoint and above.
The Mobile-First Approach
Start by designing for the smallest screen (mobile). As the screen size increases, you can override those styles using breakpoint prefixes: sm, md, lg, xl, and 2xl.
Common Breakpoints
By default, Tailwind includes these breakpoints:
- sm: 640px
- md: 768px
- lg: 1024px
- xl: 1280px
- 2xl: 1536px
Using the Generator
Use the sliders on the left to define how many columns your grid should have at each stage. Use the device toggles in the preview area to see how your layout adapts. The generator automatically builds the correct Tailwind class string focusing on efficiency (it won't repeat classes if they haven't changed between breakpoints).
Gap and Spacing
We've included a gap control to define the spacing between items. In Tailwind, gap-4 adds 1rem (16px) of space between both rows and columns. You can also use gap-x-* and gap-y-* for independent control.