🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEcss

css Documentation

LOADING ENGINE...

Grid-column

AI & DATA SCIENCE // grid-column

The grid-column property places a grid item into specific column lines, controlling both which column it starts in and how many columns it spans.

Syntax

grid-column: start-line / end-line;
grid-column: start-line / span number;

Deep Dive Course

Grid lines are numbered starting at 1 along each axis, so grid-column: 1 / 3 places an item starting at line 1 and ending at line 3, spanning across the two columns in between — the alternative span keyword, like grid-column: 2 / span 2, instead starts the item at a specific line and has it span a given number of columns forward from there, rather than requiring you to calculate and specify the exact ending line number directly. A single value, like grid-column: 2, without a slash, places the item in just that one specific column, spanning exactly one column track by default.

1Understanding Grid-column

Grid lines are numbered starting at 1 along each axis, so grid-column: 1 / 3 places an item starting at line 1 and ending at line 3, spanning across the two columns in between — the alternative span keyword, like grid-column: 2 / span 2, instead starts the item at a specific line and has it span a given number of columns forward from there, rather than requiring you to calculate and specify the exact ending line number directly. A single value, like grid-column: 2, without a slash, places the item in just that one specific column, spanning exactly one column track by default.

💡

Use the span keyword, like grid-column: 1 / span 3, when you want an item to cover a specific number of columns starting from a given line, rather than manually calculating and specifying the exact numeric end line, which requires re-counting if the starting position ever changes.

editor.html
.featured-item {
  grid-column: 1 / 3;
}
localhost:3000

2Practical Example

Here is a real-world application of Grid-column showing how it is used in production CSS code.

editor.html
.sidebar {
  grid-column: 1 / span 1;
}

.main {
  grid-column: 2 / span 2;
}
localhost:3000

3Best Practices

Follow these guidelines when working with Grid-column:

1. Use grid-column: start / span number when an item's span, how many columns wide it is, matters more than the exact specific ending line number

2. Number grid lines starting from 1, remembering an item spanning from line 1 to line 3 covers exactly 2 column tracks, the ones between those two lines, not 3

3. Combine grid-column with grid-row for full, explicit two-dimensional placement of a specific grid item into an exact rectangular region

⚠️

Tip: Use the span keyword, like grid-column: 1 / span 3, when you want an item to cover a specific number of columns starting from a given line, rather than manually calculating and specifying the exact numeric end line, which requires re-counting if the starting position ever changes.

editor.html
.featured-item {
  grid-column: 1 / 3;
}
localhost:3000

Examples

Example 01Basic Usage
.featured-item {
  grid-column: 1 / 3;
}
Example 02Advanced Example
.sidebar {
  grid-column: 1 / span 1;
}

.main {
  grid-column: 2 / span 2;
}

Best Practices

  • Use grid-column: start / span number when an item's span, how many columns wide it is, matters more than the exact specific ending line number
  • Number grid lines starting from 1, remembering an item spanning from line 1 to line 3 covers exactly 2 column tracks, the ones between those two lines, not 3
  • Combine grid-column with grid-row for full, explicit two-dimensional placement of a specific grid item into an exact rectangular region

Interview Question

Why does grid-column: 1 / 3 make an item span exactly 2 column tracks, rather than 3, even though the numbers 1 and 3 might suggest 3 columns to someone unfamiliar with how grid lines are numbered?

Hint: Think about what the numbers in grid-column actually refer to — the grid lines themselves, or the column tracks between those lines.

The numbers in a grid-column declaration refer specifically to the grid lines, the numbered boundaries that separate and surround the actual column tracks, not to the column tracks themselves directly — a grid with 3 columns has exactly 4 grid lines total, one before the first column, one between each pair of adjacent columns, and one after the last column, numbered 1 through 4 in sequence. grid-column: 1 / 3 specifies that the item's left edge should align with line 1 and its right edge should align with line 3, and the actual column tracks that fall between those two specific lines are exactly the first and second columns, making the item span across those 2 tracks, not 3, since line 3 marks the boundary between the second and third columns, not a point after the third column entirely. This line-based, rather than track-based, numbering system is a common initial point of confusion for people first learning CSS Grid, but it's precisely what allows grid-column and grid-row to precisely and unambiguously specify exactly where an item's edges fall relative to the grid's actual structural boundaries.

Exercises

MediumPractice using Grid-column in a real scenario.
View Solution
.featured-item {
  grid-column: 1 / 3;
}

Frequently Asked Questions

Why does grid-column: 1 / 3 make an item span exactly 2 column tracks, rather than 3, even though the numbers 1 and 3 might suggest 3 columns to someone unfamiliar with how grid lines are numbered?

The numbers in a grid-column declaration refer specifically to the grid lines, the numbered boundaries that separate and surround the actual column tracks, not to the column tracks themselves directly — a grid with 3 columns has exactly 4 grid lines total, one before the first column, one between each pair of adjacent columns, and one after the last column, numbered 1 through 4 in sequence. grid-column: 1 / 3 specifies that the item's left edge should align with line 1 and its right edge should align with line 3, and the actual column tracks that fall between those two specific lines are exactly the first and second columns, making the item span across those 2 tracks, not 3, since line 3 marks the boundary between the second and third columns, not a point after the third column entirely. This line-based, rather than track-based, numbering system is a common initial point of confusion for people first learning CSS Grid, but it's precisely what allows grid-column and grid-row to precisely and unambiguously specify exactly where an item's edges fall relative to the grid's actual structural boundaries.

Related Functions

Grid-rowGrid-template-columnsGrid-template-areas