What You'll Learn
You'll learn how to place grid items precisely by telling them which vertical grid lines to start and end at, giving you full control over column positioning.
The Core Idea
In CSS Grid, every vertical line between columns has a number (starting from 1 on the left). The grid-column-start and grid-column-end properties let you specify exactly where a grid item should begin and finish horizontally.
Think of it like reserving seats in a theater row: "I want seats starting at position 2 and ending before position 5" — that gives you seats 2, 3, and 4.
How It Works
By default, grid items occupy one cell each. But you can override this:
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 10px;
}
.item-wide {
grid-column-start: 1;
grid-column-end: 3;
/* This item spans from line 1 to line 3 (occupies 2 columns) */
}
.item-offset {
grid-column-start: 2;
grid-column-end: 5;
/* Spans from line 2 to line 5 (occupies 3 columns) */
}
Important details:
- Line numbers start at 1, not 0
grid-column-endis the line after the last column you want to occupy- If an item starts at line 1 and ends at line 3, it spans 2 columns (columns 1 and 2)
- You can use negative numbers to count from the right edge
.full-width {
grid-column-start: 1;
grid-column-end: -1;
/* Spans from the first line to the last line (full width) */
}
Key Takeaway: grid-column-start and grid-column-end control which vertical grid lines an item spans between, letting you create items that occupy multiple columns or start at specific positions in your grid layout.