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

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

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

ClassMinimum width
w3-grid-auto-xsmall150px
w3-grid-auto-small200px
w3-grid-auto250px
w3-grid-auto-large300px
w3-grid-auto-xlarge350px

Columns expand to fill the available space and can shrink below these widths to fit a narrower container.

Resize the browser window to see the effect.

XSmall Auto Grid

One

Two

Three

Four

Five

Six


Normal Auto Grid

One

Two

Three

Four

Five

Six


XLarge Auto Grid

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:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

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 Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.