Dofactory.com
Dofactory.com
Earn income with your CSS skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

CSS grid-column

The grid-column property sets the start and end of a grid item.

This setting allows an item to stretch over multiple columns.

The end is either a column number, or the number of columns.

Example

#

Item 6 has grid-column set to 2 / 5.
The item starts on column 2 and ends before column 5.

1
2
3
4
5
6
7
8
9
10
<style>
  .grid-container {
    background-color: steelblue;
    padding: 10px;
    display: grid;
    grid-gap: 10px;
    grid-template-columns: auto auto auto auto;
  }

  .grid-container > div {
    background-color: aliceblue;
    text-align: center;
    padding: 15px 5px;
    font-size: 18px;
  }
</style>

<div class="grid-container">
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div style="grid-column: 2 / 5;
              color: white;
              background-color: salmon !important; ">6</div>
  <div>7</div>
  <div>8</div>
  <div>9</div>
  <div>10</div>
</div> 

Using grid-column

The grid-column property is a shorthand property for:

Syntax

grid-column: grid-column-start  [grid-column-end | span n] ;

Note: The end is either specified by a column number, or by the number of column the item spans.


Values

#

Value Description
grid-column-start Sets which column to start displaying the item.
grid-column-end Sets the column at which to stop displaying the item.
span n The number of columns the item spans (covers).

More Examples

Item 1 has a grid-column value of 1 / span 4.
The item starts at column 1 and covers 4 columns.

1
2
3
4
5
6
7
8
9
10
11
12
<style>
  .grid-container {
    background-color: steelblue;
    padding: 10px;
    display: grid;
    grid-gap: 10px;
    grid-template-columns: auto auto auto auto;
  }

  .grid-container > div {
    background-color: aliceblue;
    text-align: center;
    padding: 15px 5px;
    font-size: 18px;
  }
</style>

<div class="grid-container">
  <div style="grid-column: 1 / span 4;
              color: white;
              background-color: salmon; ">1</div>

  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
  <div>7</div>
  <div>8</div>
  <div>9</div>
  <div>10</div>
  <div>11</div>
  <div>12</div>
</div> 

Browser support

This table shows when grid-column support started for each browser.

Chrome
57 Mar 2017
Firefox
52 Mar 2017
IE/Edge
16 Sep 2017
Opera
44 Mar 2017
Safari
10 Sep 2016

You may also like


Last updated on Sep 30, 2023

Earn income with your CSS skills
Sign up and we'll send you the best freelance opportunities straight to your inbox.
We're building the largest freelancing marketplace for people like you.
By adding your name & email you agree to our terms, privacy and cookie policies.

Guides