Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP C C++ C# AWS W3.CSS HOW TO BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS MATH

W3.CSS 6 Grid Helpers

Share

Grid Helper Classes

The w3-grid class creates a basic grid container.

W3.CSS expands CSS Grid with helper classes for:

  • Fixed grid columns
  • Spacing (Gaps)
  • Responsive auto columns
  • Spanning

Fixed Grid Columns

The fixed column helpers create two, three, or four equal-width columns.

ClassDescription
w3-grid-2Creates 2 equal-width columns.
w3-grid-3Creates 3 equal-width columns.
w3-grid-4Creates 4 equal-width columns.

Two Columns

1

2

Three Columns

1

2

3

Four Columns

1

2

3

4

Example

<h3>Two Columns</h3>
<div class="w3-grid-2 w3-gap">
  <div class="w3-container w3-red">One</div>
  <div class="w3-container w3-blue">Two</div>
</div>

<h3>Three Columns</h3>
<div class="w3-grid-3 w3-gap">
  <div class="w3-container w3-red">One</div>
  <div class="w3-container w3-green">Two</div>
  <div class="w3-container w3-blue">Three</div>
</div>

<h3>Four Columns</h3>
<div class="w3-grid-4 w3-gap">
  <div class="w3-container w3-red">One</div>
  <div class="w3-container w3-green">Two</div>
  <div class="w3-container w3-blue">Three</div>
  <div class="w3-container w3-orange">Four</div>
</div>
Try It Yourself »

Note

Fixed Grid helpers displays the same number of columns on smaller screens.


Grid Gaps

The gap helpers work with both Grid and Flexbox.

ClassDescription
w3-gap-smallCreates an 8px gap between rows and columns
w3-gapCreates a 16px gap between rows and columns
w3-gap-largeCreates a 24px gap between rows and columns

Small Gap

1

2

3

Normal Gap

1

2

3

Large Gap

1

2

3

Example

<h3>Small Gap</h3>
<div class="w3-grid-3 w3-gap-small">
  <div class="w3-container w3-red">One</div>
  <div class="w3-container w3-green">Two</div>
  <div class="w3-container w3-blue">Three</div>
</div>

<h3>Normal Gap</h3>
<div class="w3-grid-3 w3-gap">
  <div class="w3-container w3-red">One</div>
  <div class="w3-container w3-green">Two</div>
  <div class="w3-container w3-blue">Three</div>
</div>

<h3>Large Gap</h3>
<div class="w3-grid-3 w3-gap-large">
  <div class="w3-container w3-red">One</div>
  <div class="w3-container w3-green">Two</div>
  <div class="w3-container w3-blue">Three</div>
</div>
Try It Yourself »

Responsive Auto Grid

ClassMin width
w3-grid-auto-xsmall150px
w3-grid-auto-small250px
w3-grid-auto300px
w3-grid-auto-large350px
w3-grid-auto-xlarge400px
w3-grid-auto-xxlarge450px
w3-grid-auto-xxxlarge550px

The auto-grid helpers automatically change the number of columns based on available width.

The calculation is:

Required width =
(number of columns X minimum column width) + (number of gaps X gap size)

For example, w3-grid-auto with a 300px minimum and a 16px gap, produces the following progression at different container widths:

Columns Type Width Required
1 Phone 425px 300px
2 Tablet 768px 616px
3 Laptop 1024px 932px
4 Laptop L 1440px 1248px
6 Desktop 1920px 1880px

The table below shows the number of columns at different screen or container widths, with a 16px gap and enough items to fill all columns.

Columns can shrink below the listed minimum width to fit a narrower container.

Class Width 425px 768px 1024px 1440px 1920px
w3-grid-auto-xsmall 150px 2 4 6 8 11
w3-grid-auto-small 250px 1 2 3 5 7
w3-grid-auto 300px 1 2 3 4 6
w3-grid-auto-large 350px 1 2 2 3 5
w3-grid-auto-xlarge 400px 1 1 2 3 4
w3-grid-auto-xxlarge 450px 1 1 2 3 4
w3-grid-auto-xxxlarge 550px 1 1 1 2 3

XSmall Auto Grid (150px)

One

Two

Three

Four

Five

Six

Resize the browser window to see the effect.

Normal Auto Grid (300px)

One

Two

Three

Four

Five

Six


xLarge Auto Grid (400px)

One

Two

Three

Four

Five

Six

Example

<h3>XSmall Auto Grid</h3>
<div class="w3-grid-auto-xsmall w3-gap">
  <div class="w3-container w3-red">One</div>
  <div class="w3-container w3-green">Two</div>
  <div class="w3-container w3-blue">Three</div>
  <div class="w3-container w3-orange">Four</div>
</div>

<h3>Normal Auto Grid</h3>
<div class="w3-grid-auto w3-gap">
  <div class="w3-container w3-red">One</div>
  <div class="w3-container w3-green">Two</div>
  <div class="w3-container w3-blue">Three</div>
  <div class="w3-container w3-orange">Four</div>
</div>

<h3>XLarge Auto Grid</h3>
<div class="w3-grid-auto-xlarge w3-gap">
  <div class="w3-container w3-red">One</div>
  <div class="w3-container w3-green">Two</div>
  <div class="w3-container w3-blue">Three</div>
  <div class="w3-container w3-orange">Four</div>
</div>
Try It Yourself »

Grid Spanning

The span helpers make grid items cover two columns, three columns or full width.

ClassDescription
w3-grid-span-2Grid item spans 2 columns.
w3-grid-span-3Grid item spans 3 columns.
w3-grid-span-allGrid item spans all columns.

Span 2

3

4

Span 3

4

Span All

Example

<div class="w3-grid-4 w3-gap">
  <div class="w3-container w3-blue w3-grid-span-2">Span 2</div>
  <div class="w3-container w3-blue">One</div>
  <div class="w3-container w3-blue">Two</div>

  <div class="w3-container w3-blue w3-grid-span-3">Span 3</div>
  <div class="w3-container w3-blue">Three</div>

  <div class="w3-container w3-blue w3-grid-span-all">Span All</div>
</div>
Try It Yourself »

Grid Areas

Named grid areas can be used for more advanced page layouts.

The first column is 150px wide, and the second column uses the remaining space:

Header

Header 2

This is the right column.

Both columns have equal width.

Footer

Example

<style>
.myPage {
grid-template-columns:1fr 1fr;
grid-template-areas:
  "myHeader myHeader"
  "myLeft myRight"
  "myFooter myFooter";
}
</style>

<body class="myPage w3-grid">

<div class="w3-container w3-blue" style="grid-area:myHeader">
  <h2>Header</h2>
</div>

<div class="w3-container w3-light-grey" style="grid-area:myLeft">
  <h3>Header 1</h3>
  <p>This is the left column.</p>
</div>

<div class="w3-container w3-pale-blue" style="grid-area:myRight">
  <h2>Header 2</h2>
  <p>This is the right column.</p>
</div>

<div class="w3-container w3-dark-grey" style="grid-area:myFooter">
  <p>Footer</p>
</div>
Try it Yourself »

"myHeader myHeader" means the first row has two columns, and header occupies both.

"myLeft myRight" means the second row has myLeft in the first column and myRight in the second.

"myFooter myFooter" means the third row has two columns, and footer occupies both.


Grid RTL

CSS Grid follows the document direction naturally.

Example

<div class="w3-grid-3 w3-gap w3-rtl">
  <div class="w3-container">&#1608;&#1575;&#1581;&#1583;</div>
  <div class="w3-container">&#1575;&#1579;&#1606;&#1575;&#1606;</div>
  <div class="w3-container">&#1579;&#1604;&#1575;&#1579;&#1577;</div>
</div>
Try It Yourself »

Free account

Track your progress

XP earned 0 Day streak 0 Spaces 0 League —

New

Learn in Adventure Mode W3Schools Adventure App

Coding fundamentals as bite-sized lessons and challenges.

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by W3Schools. All Rights Reserved. W3Schools is Powered by W3.CSS.