grid-column and grid-row Shorthand
You'll learn how to place grid items more efficiently using shorthand properties that combine start and end positions.
The Core Idea
Instead of writing separate grid-column-start and grid-column-end declarations (and the same for rows), CSS Grid provides shorthand properties that let you specify both values in a single line. This makes your code cleaner and faster to write.
The Shorthand Properties
grid-column combines grid-column-start and grid-column-end:
.item {
/* Longhand */
grid-column-start: 1;
grid-column-end: 3;
/* Shorthand - same result */
grid-column: 1 / 3;
}
grid-row works identically for row placement:
.item {
/* Longhand */
grid-row-start: 2;
grid-row-end: 4;
/* Shorthand - same result */
grid-row: 2 / 4;
}
How the Syntax Works
The pattern is: start-line / end-line, separated by a forward slash. Think of it like saying "from line 1 to line 3" in one breath instead of two separate sentences.
.featured-item {
grid-column: 1 / 4; /* Spans columns 1 through 3 */
grid-row: 1 / 2; /* Occupies first row */
}
This item starts at column line 1 and extends to column line 4 (spanning three columns), while occupying the first row.
Why Use Shorthand?
It reduces code repetition and makes grid placement easier to read at a glance. When scanning your CSS, you immediately see both the start and end positions together, understanding the full span of an item.
Key Takeaway: Use grid-column: start / end and grid-row: start / end to efficiently place grid items across tracks in a single declaration.