Skip to content

grid-template-columns

Utilities for specifying the columns in a grid layout.

Quick reference

ClassStyles
grid-cols-<number>grid-template-columns: repeat(<number>, minmax(0, 1fr));
grid-cols-nonegrid-template-columns: none;
grid-cols-subgridgrid-template-columns: subgrid;
grid-cols-[<value>]grid-template-columns: <value>;
grid-cols-(<custom-property>)grid-template-columns: var(<custom-property>);

Source: https://tailwindcss.com/guide/grid-template-columns

Examples

Specifying the grid columns

Use grid-cols-<number> utilities like grid-cols-2 and grid-cols-4 to create grids with n equally sized columns:

html
<!-- [!code classes:grid-cols-4] -->
<div class="grid grid-cols-4 gap-4">
  <div>01</div>
  <!-- ... -->
  <div>09</div>
</div>

Implementing a subgrid

Use the grid-cols-subgrid utility to adopt the column tracks defined by the item's parent:

html
<!-- [!code classes:grid-cols-subgrid] -->
<div class="grid grid-cols-4 gap-4">
  <div>01</div>
  <!-- ... -->
  <div>05</div>
  <div class="col-span-3 grid grid-cols-subgrid gap-4">
    <div class="col-start-2">06</div>
  </div>
</div>

Using a custom value

Use the grid-cols-[&lt;value&gt;] syntax to set the grid template columns based on a completely custom value:

html
<div class="grid grid-cols-[200px_minmax(900px,_1fr)_100px] ...">
  <!-- ... -->
</div>

For CSS variables, you can also use the grid-cols-(&lt;custom-property&gt;) syntax:

html
<div class="grid grid-cols-(--my-columns) ...">
  <!-- ... -->
</div>

This is just a shorthand for grid-cols-[var(&lt;custom-property&gt;)] that adds the var() function for you automatically.

Responsive design

Prefix a grid-template-columns utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

html
<div class="grid grid-cols-1 md:grid-cols-6 ...">
  <!-- ... -->
</div>

Learn more about using variants in the variants documentation.

Released under the MIT License.