CSS grid-column Property
The CSS grid-column property is a shorthand that specifies where a grid item starts and ends along the column axis of a CSS Grid container.
It combines grid-column-start and grid-column-end into one declaration. You can use numbered grid lines, named lines, or the span keyword to position an item or make it extend across multiple columns.
grid-column Syntax
The grid-column shorthand accepts a starting grid line and an optional ending grid line, separated by a forward slash.
Basic Syntax
selector {
grid-column: start / end;
}
Start and End Lines
.item {
grid-column: 1 / 3;
}
Single Grid Line
.item {
grid-column: 2;
}
Span Multiple Columns
.item {
grid-column: span 2;
}
Start Line with Span
.item {
grid-column: 2 / span 3;
}
End Line with Span
.item {
grid-column: span 2 / 5;
}
Named Grid Lines
.item {
grid-column: content-start / content-end;
}
Automatic Placement
.item {
grid-column: auto;
}
CSS-Wide Keywords
.item {
grid-column: initial;
}
.item {
grid-column: inherit;
}
.item {
grid-column: unset;
}
.item {
grid-column: revert;
}
.item {
grid-column: revert-layer;
}
When the second value is omitted, it generally defaults to auto. If the first value is a custom identifier, that identifier is also used for the omitted ending value.
Property Values
The grid-column property accepts grid line positions, spans, named lines, and automatic placement values.
| Value | Description |
|---|---|
auto |
Allows the grid placement algorithm to determine the item's column position or span. |
<integer> |
References a numbered grid line. Positive numbers count from the start; negative numbers count backward from the end of the explicit grid. |
<custom-ident> |
References a named grid line. |
span <integer> |
Specifies how many grid tracks an item spans. |
span <custom-ident> |
Uses a named grid line to determine the item's span. |
<integer> <custom-ident> |
References a numbered occurrence of a named grid line. |
inherit |
Inherits the computed longhand values from the parent element. |
initial |
Resets both longhand properties to auto. |
unset |
Resets both non-inherited longhand properties to auto. |
revert |
Reverts the longhand values according to the cascade origin rules. |
revert-layer |
Reverts the longhand values according to the cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | auto for both longhands |
| Inherited | No |
| Applies to | Grid items and absolutely positioned boxes whose containing block is a grid container |
| Computed value | As specified for each longhand |
| Animation type | Discrete |
| Percentages | Not applicable |
| Shorthand for | grid-column-start and grid-column-end |
Grid line numbers cannot be zero. A span count must be a positive integer, and both sides of the shorthand cannot specify a span simultaneously.
How It Works
CSS Grid positions items using horizontal and vertical grid lines. The grid-column property identifies the vertical lines that form the item's column boundaries.
Create a Four-Column Grid
.container {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 12px;
}
Understand Grid Lines
A grid containing four explicit columns has five vertical grid lines.
Position an Item
.item {
grid-column: 2 / 4;
}
The item starts at vertical grid line 2 and ends at line 4, spanning two columns.
Leave the Row Automatic
The grid-column property does not specify the item's row. Unless a row position is assigned separately, the grid auto-placement algorithm determines the row.
Use the Longhand Properties
.item {
grid-column-start: 2;
grid-column-end: 4;
}
These two declarations are equivalent to grid-column: 2 / 4.
Important Consideration
The property positions a grid item within the grid. It does not establish a grid container or define the number and sizes of columns.
Grid Line Numbers
Grid lines are numbered from the start of the explicit grid. A grid with three columns has four column lines.
Three-Column Grid
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
}
First Column
.item {
grid-column: 1 / 2;
}
Second Column
.item {
grid-column: 2 / 3;
}
Third Column
.item {
grid-column: 3 / 4;
}
First Two Columns
.item {
grid-column: 1 / 3;
}
Entire Explicit Grid Width
.item {
grid-column: 1 / 4;
}
Column Line Reference
| Declaration | Result |
|---|---|
1 / 2 |
First column |
2 / 3 |
Second column |
3 / 4 |
Third column |
1 / 3 |
First and second columns |
1 / 4 |
All three columns |
Important Consideration
The ending value identifies a grid line, not the number of columns occupied. For example, grid-column: 1 / 3 spans two columns, not three.
Spanning Columns
The span keyword specifies how many grid tracks an item occupies without requiring both boundary lines to be written explicitly.
Span Two Columns
.item {
grid-column: span 2;
}
The browser determines the starting position automatically and makes the item span two columns.
Span Three Columns
.item {
grid-column: span 3;
}
Start at Line Two
.item {
grid-column: 2 / span 2;
}
The item starts at line 2 and extends across two columns, ending at line 4.
End at Line Five
.item {
grid-column: span 2 / 5;
}
The item spans two columns and ends at line 5, so its starting line is 3.
Spanning the Full Width
.full-width {
grid-column: 1 / -1;
}
Invalid Span
.item {
grid-column: span 0;
}
A span count of zero is invalid. Span counts must be positive integers.
Important Consideration
Using span allows the grid auto-placement algorithm to determine the item's location while preserving its requested width in grid tracks.
Negative Line Numbers
Negative grid line numbers count backward from the end of the explicit grid.
Last Explicit Grid Line
.item {
grid-column-end: -1;
}
Full-Width Grid Item
.item {
grid-column: 1 / -1;
}
This common pattern extends an item from the first explicit column line to the last explicit column line.
Last Two Columns
.item {
grid-column: -3 / -1;
}
Second-to-Last Column
.item {
grid-column: -3 / -2;
}
Responsive Full-Width Item
.header {
grid-column: 1 / -1;
}
The item continues to span the entire explicit grid even if the number of columns changes at different viewport widths.
Important Consideration
Negative line numbers are relative to the explicit grid boundaries. They do not automatically include implicit columns created beyond the explicit grid.
Named Grid Lines
Named grid lines provide descriptive references for positioning items without relying entirely on numeric line values.
Define Named Lines
.container {
display: grid;
grid-template-columns:
[content-start] 200px
[main-start] 1fr
[content-end];
}
Position Using Names
.item {
grid-column: content-start / content-end;
}
Position the Main Content
.main {
grid-column: main-start / content-end;
}
Repeated Named Lines
.container {
display: grid;
grid-template-columns:
[col] 1fr
[col] 1fr
[col] 1fr
[col];
}
.item {
grid-column: col 2 / col 4;
}
When a line name occurs multiple times, an integer can select a particular occurrence.
Named Lines with span
.item {
grid-column: col 1 / span col 2;
}
The span counts matching named grid lines from the starting position.
Important Consideration
Named lines are especially useful in complex layouts where descriptive names make grid placement easier to understand and maintain.
Automatic Placement
When grid column boundaries are not fully specified, CSS Grid uses its auto-placement algorithm to determine the remaining position information.
Automatic Column Placement
.item {
grid-column: auto;
}
Specify Only the Starting Line
.item {
grid-column: 2;
}
The item starts at line 2. Its ending boundary is automatic, ordinarily producing a one-column span.
Automatic Start with a Definite End
.item {
grid-column: auto / 4;
}
Automatic Start with a Span
.item {
grid-column: span 2;
}
Use grid-auto-flow
.container {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-flow: row;
}
Dense Placement
.container {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-flow: row dense;
}
Dense packing can place later items into earlier available spaces when their column spans fit.
Important Consideration
Specifying a column position does not automatically specify a row position. The grid placement algorithm resolves any remaining automatic coordinates.
Implicit Grid Columns
Positioning an item beyond the explicitly defined column lines can cause the browser to generate implicit grid columns.
Define Three Columns
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-columns: 150px;
}
Position Beyond the Explicit Grid
.item {
grid-column: 5 / 6;
}
The item is positioned outside the three-column explicit grid, so additional columns are generated.
Control Implicit Column Widths
.container {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-columns: minmax(120px, auto);
}
Implicit Columns Before the Grid
.item {
grid-column: -6 / -5;
}
When negative line references extend beyond the explicit grid's starting boundary, implicit columns can be generated before the explicit grid.
Important Consideration
The grid-column property determines placement, while grid-auto-columns controls the sizes of implicit columns.
grid-column vs. grid-row
The grid-column and grid-row properties control placement along different grid axes.
Column Placement
.item {
grid-column: 1 / 3;
}
The item spans two columns.
Row Placement
.item {
grid-row: 1 / 3;
}
The item spans two rows.
Combined Placement
.item {
grid-column: 2 / 4;
grid-row: 1 / 3;
}
The item occupies two columns and two rows.
Property Comparison
| Property | Controls | Longhand Properties |
|---|---|---|
grid-column |
Column start and end positions | grid-column-start, grid-column-end |
grid-row |
Row start and end positions | grid-row-start, grid-row-end |
Important Consideration
Both properties can be used together to assign a grid item a definite position and size in grid tracks.
The grid-area Shorthand
The grid-area shorthand can specify row and column placement in one declaration.
Separate Placement Properties
.item {
grid-row: 1 / 3;
grid-column: 2 / 4;
}
Equivalent grid-area Declaration
.item {
grid-area: 1 / 2 / 3 / 4;
}
The four values represent row start, column start, row end, and column end, in that order.
Named Grid Area
.container {
display: grid;
grid-template-areas:
"header header"
"sidebar main";
grid-template-columns: 200px 1fr;
}
.main {
grid-area: main;
}
When to Use grid-column
Use grid-column when only column placement needs to be specified or changed.
When to Use grid-area
Use grid-area when assigning both row and column coordinates or positioning an item within a named grid area.
Important Consideration
The grid-area shorthand resets all four placement longhands. Use it carefully when existing row or column positions must be preserved.
Responsive Layouts
The grid-column property can adjust item placement as the grid changes at different viewport widths.
Single-Column Mobile Layout
.layout {
display: grid;
grid-template-columns: 1fr;
gap: 16px;
}
.layout .header,
.layout .footer {
grid-column: 1 / -1;
}
Desktop Layout
@media (min-width: 768px) {
.layout {
grid-template-columns: 220px minmax(0, 1fr);
}
.layout .sidebar {
grid-column: 1;
}
.layout .main {
grid-column: 2;
}
}
Responsive Featured Card
.card-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 16px;
}
.card-grid .featured {
grid-column: 1 / -1;
}
@media (min-width: 900px) {
.card-grid {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.card-grid .featured {
grid-column: span 2;
}
}
Automatic Full-Width Items
.section-heading {
grid-column: 1 / -1;
}
The heading spans all explicit columns regardless of the number defined by the responsive grid template.
Important Consideration
Explicit grid line positions may need adjustment when the number of columns changes. Use span and 1 / -1 where appropriate to reduce unnecessary media-query overrides.
Overlapping Grid Items
Grid items can overlap when they are assigned intersecting row and column positions.
Overlapping Column Positions
.item-one {
grid-column: 1 / 3;
grid-row: 1;
}
.item-two {
grid-column: 2 / 4;
grid-row: 1;
}
Both items occupy part of the second column in the same row.
Control Stacking Order
.item-two {
position: relative;
z-index: 2;
}
Grid Item z-index
Grid items can use z-index to control stacking order even when their position value is static.
Avoid Accidental Overlap
Review both grid-column and grid-row when items appear in unexpected positions.
Important Consideration
Overlapping grid items remain separate elements. Their visual stacking does not change their document order or accessibility relationships.
Writing Direction
Grid column lines follow the grid container's logical inline axis rather than a permanently fixed left-to-right direction.
Left-to-Right Layout
.container {
display: grid;
direction: ltr;
grid-template-columns: repeat(3, 1fr);
}
.item {
grid-column: 1 / 2;
}
In a horizontal left-to-right writing mode, the first column is on the left.
Right-to-Left Layout
.container {
display: grid;
direction: rtl;
grid-template-columns: repeat(3, 1fr);
}
.item {
grid-column: 1 / 2;
}
In a horizontal right-to-left writing mode, the first column is on the right.
Vertical Writing Mode
.container {
display: grid;
writing-mode: vertical-rl;
grid-template-columns: repeat(3, 1fr);
}
With vertical writing modes, the inline axis is vertical, so the physical orientation of grid columns changes.
Important Consideration
Grid line numbering follows the logical direction of the grid. Consider writing modes and text direction when designing multilingual layouts.
Inheritance
The grid-column property is not inherited.
Parent Grid Item
.parent-item {
grid-column: 1 / 3;
}
Nested Grid Item
.nested-item {
grid-column: auto;
}
A nested grid item does not automatically inherit the column placement assigned to its parent.
Explicit Inheritance
.nested-item {
grid-column: inherit;
}
The inherit keyword copies the computed grid-column-start and grid-column-end values from the parent element.
Reset to Initial Values
.item {
grid-column: initial;
}
Important Consideration
Each grid item is positioned within its own grid formatting context. Inherited numeric line values are interpreted within the receiving item's grid, not automatically within the parent's grid.
grid-column Example
This example demonstrates a four-column grid with a full-width header and footer, a sidebar occupying one column, and a main content area spanning three columns.
HTML Example
<div class="grid-column-demo">
<div class="grid-header">Header</div>
<div class="grid-sidebar">Sidebar</div>
<div class="grid-main">Main Content</div>
<div class="grid-footer">Footer</div>
</div>
CSS Example
.grid-column-demo {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 12px;
}
.grid-column-demo > div {
padding: 20px;
color: #ffffff;
text-align: center;
font-weight: bold;
border-radius: 4px;
}
.grid-column-demo .grid-header {
grid-column: 1 / -1;
background-color: #2456a6;
}
.grid-column-demo .grid-sidebar {
grid-column: 1 / 2;
background-color: #187a65;
}
.grid-column-demo .grid-main {
grid-column: 2 / 5;
background-color: #596579;
}
.grid-column-demo .grid-footer {
grid-column: 1 / -1;
background-color: #2456a6;
}
The header and footer use grid-column: 1 / -1 to extend across the entire explicit grid.
The sidebar uses grid-column: 1 / 2, occupying the first column. The main content uses grid-column: 2 / 5, occupying the remaining three columns.
Because the sidebar and main content occupy different columns, the grid auto-placement algorithm can place them in the same row.
Common Mistakes
Common problems with grid-column involve incorrect grid line numbers, invalid span values, or confusion between grid tracks and grid lines.
Forgetting the Grid Container
.item {
grid-column: 1 / 3;
}
The declaration does not establish a grid layout. The parent must establish an appropriate grid formatting context for normal grid item placement.
Using Grid Line Zero
.item {
grid-column: 0 / 2;
}
Grid line numbering begins at 1 or -1. Zero is not a valid grid line number.
Confusing Lines with Columns
.item {
grid-column: 1 / 3;
}
This declaration spans two columns, not three.
Using a Zero Span
.item {
grid-column: span 0;
}
Span counts must be positive integers.
Using Two Spans
.item {
grid-column: span 2 / span 3;
}
Both sides of the shorthand cannot use span simultaneously.
Assuming Negative Lines Include Implicit Columns
Negative grid line references count from the explicit grid boundary, not from the end of every implicit column.
Expecting grid-column to Control Row Placement
Use grid-row when the item's row position must also be specified.
Overlapping Items Accidentally
Items assigned intersecting grid coordinates can overlap. Review both row and column placement declarations.
Ignoring Responsive Column Counts
Fixed line references may extend beyond the intended grid when the number of columns changes.
Using Named Lines That Do Not Exist
Unmatched named line references can cause implicit line creation or unexpected placement. Check the line names declared in the grid template.
Important Considerations
Keep the following points in mind when using grid-column:
- Purpose: Defines the starting and ending column lines of a grid item.
- Shorthand: Combines
grid-column-startandgrid-column-end. - Initial value: Both longhands default to
auto. - Inheritance: The property is not inherited.
- Applies to: Grid items and absolutely positioned boxes whose containing block is a grid container.
- Grid lines: Identify track boundaries, not track numbers.
- Positive lines: Count forward from the start of the explicit grid.
- Negative lines: Count backward from the end of the explicit grid.
- Line zero: Invalid.
- Spanning: The
spankeyword defines the number of tracks occupied. - Span counts: Must be positive integers.
- Named lines: Provide descriptive placement references.
- Automatic placement: Unspecified boundaries are resolved by the grid placement algorithm.
- Implicit columns: Can be generated when placement extends beyond the explicit grid.
- Column sizing: Controlled separately by
grid-template-columnsandgrid-auto-columns. - Row placement: Controlled separately by
grid-row. - Full-width items:
grid-column: 1 / -1spans the explicit grid. - Overlapping items: Multiple items can occupy intersecting grid cells.
- Writing direction: Grid line numbering follows the logical inline axis.
- Responsive layouts: Review explicit line references when column counts change.
- Accessibility: Visual placement does not change the document's reading or keyboard focus order.
- Browser testing: Verify line placement, spans, overflow, and responsive behavior.
The grid-column property provides precise control over horizontal grid placement in common writing modes. It is especially useful for full-width sections, featured cards, sidebars, and layouts where individual items need to occupy specific grid columns.
Browser Support
The CSS grid-column property has Widely available support in modern browsers as part of CSS Grid Layout.
Modern versions of Chrome, Edge, Firefox, Safari, and other major browsers support numbered grid lines, named lines, negative line references, and the span keyword.
Standard Example
.container {
display: grid;
grid-template-columns: repeat(4, 1fr);
}
.item {
grid-column: 1 / 3;
}
Legacy Browser Considerations
Internet Explorer implemented an older, prefixed version of CSS Grid that used different placement properties, including -ms-grid-column and -ms-grid-column-span. It does not support the modern grid-column shorthand.
Browser Compatibility
For current compatibility details, visit Can I Use? and search for grid-column.
Specifications
The grid-column property is defined in the CSS Grid Layout specification.
CSS Grid Layout Module Level 1: grid-column
The specification defines grid placement using numbered and named grid lines, automatic placement, and spans.
CSS Grid Layout Module Level 2
For additional documentation and examples, consult MDN Web Docs.
