Tailwind CSS

Fewer Grid Columns on Small Devices


To achieve fewer grid columns on small devices in Tailwind CSS, you can utilize the responsive grid classes.

 

Mobile-First Approach:

Tailwind follows a mobile-first approach. This means by default, the styles defined for smaller screens (like sm breakpoint) apply, and you can progressively enhance them for larger screens using responsive classes.
Use responsive prefixes like md (medium), lg (large) etc., with grid column classes to define the desired number of columns on larger devices.

 

Example:

<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5">
 <!-- Your grid items here -->
</div>

 

Example:

  • grid-cols-1 sets the number of columns to 1 by default.
  • sm:grid-cols-2 sets the number of columns to 2 on small screens and larger.
  • md:grid-cols-3 sets the number of columns to 3 on medium screens and larger.
  • lg:grid-cols-4 sets the number of columns to 4 on large screens and larger.