CSS grid-column-end Property

The CSS grid-column-end property specifies the ending grid line of a grid item along the column axis.

It works with grid-column-start to determine which columns an item occupies. You can specify a numbered grid line, a named grid line, or a span that extends across a certain number of columns. When the ending position is not specified, the browser uses the grid placement algorithm to determine it.

grid-column-end Syntax

The grid-column-end property accepts a single grid line position, a span, or an automatic placement value.

Basic Syntax

selector {
  grid-column-end: auto;
}

Numbered Grid Line

.item {
  grid-column-end: 4;
}

Negative Grid Line

.item {
  grid-column-end: -1;
}

Span Multiple Columns

.item {
  grid-column-end: span 2;
}

Named Grid Line

.item {
  grid-column-end: content-end;
}

Numbered Named Line

.item {
  grid-column-end: 2 col;
}

Named Span

.item {
  grid-column-end: span content-end;
}

Automatic Ending Position

.item {
  grid-column-end: auto;
}

CSS-Wide Keywords

.item {
  grid-column-end: initial;
}
.item {
  grid-column-end: inherit;
}
.item {
  grid-column-end: unset;
}
.item {
  grid-column-end: revert;
}
.item {
  grid-column-end: revert-layer;
}

The value identifies the ending grid line or specifies how the ending boundary should be calculated. It does not directly set a width in pixels or percentages.

Property Values

The grid-column-end property supports the following values.

Value Description
auto Allows the grid placement algorithm to determine the ending boundary or use an automatic span.
<integer> References a numbered grid line. Positive numbers count forward, and negative numbers count backward from the explicit grid boundary.
<custom-ident> References a named grid line.
<integer> <custom-ident> Selects a numbered occurrence of a named grid line.
span <integer> Extends the item across a specified number of grid tracks.
span <custom-ident> Extends the item to a matching named grid line.
span <integer> <custom-ident> Spans to a specified occurrence of a matching named grid line.
inherit Inherits the computed value from the parent element.
initial Resets the property to auto.
unset Resets the non-inherited property to auto.
revert Reverts the property according to the cascade origin rules.
revert-layer Reverts the property according to the cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto
Inherited No
Applies to Grid items and absolutely positioned boxes whose containing block is a grid container
Computed value As specified
Animation type Discrete
Percentages Not applicable
Shorthand properties grid-column and grid-area

Grid line numbers cannot be zero. When using span, the track count must be a positive integer. The identifiers auto and span cannot be used as custom grid line names in this property.

How It Works

The grid-column-end property establishes the ending boundary of a grid item along the grid's column axis.

Create a Grid Container

.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

Set the Starting Line

.item {
  grid-column-start: 2;
}

Set the Ending Line

.item {
  grid-column-start: 2;
  grid-column-end: 4;
}

The item starts at line 2 and ends at line 4, occupying the second and third columns.

Equivalent Shorthand

.item {
  grid-column: 2 / 4;
}

Leave the Starting Line Automatic

.item {
  grid-column-end: 4;
}

When the starting line is automatic, the browser resolves the item's starting position using the grid placement algorithm. For a normal one-column item, it occupies the track immediately before line 4.

Important Consideration

The ending grid line determines one boundary of the item's grid area. The item's rendered width also depends on the sizes of the occupied tracks, gaps, alignment, and other layout properties.

Grid Line Numbering

Grid lines identify the boundaries between columns. A grid with four explicitly defined columns has five vertical grid lines.

Four-Column Grid

.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

End at Line Two

.item {
  grid-column-start: 1;
  grid-column-end: 2;
}

End at Line Three

.item {
  grid-column-start: 1;
  grid-column-end: 3;
}

End at Line Four

.item {
  grid-column-start: 1;
  grid-column-end: 4;
}

End at Line Five

.item {
  grid-column-start: 1;
  grid-column-end: 5;
}

Column Span Reference

Start Line End Line Columns Occupied
1 2 1
1 3 2
1 4 3
1 5 4

Important Consideration

The ending line is not the number of columns an item spans. It identifies the grid line where the item stops.

Spanning Columns

The span keyword specifies how many grid columns an item should occupy.

Span Two Columns

.item {
  grid-column-end: span 2;
}

Span Three Columns

.item {
  grid-column-end: span 3;
}

Combine Start Line and Span

.item {
  grid-column-start: 2;
  grid-column-end: span 3;
}

The item begins at line 2 and extends across three columns, ending at line 5.

Equivalent Numeric Ending Line

.item {
  grid-column-start: 2;
  grid-column-end: 5;
}

Automatic Start with Span

.item {
  grid-column-start: auto;
  grid-column-end: span 2;
}

The browser chooses the item's starting position while preserving its two-column span.

Invalid Span Count

.item {
  grid-column-end: span 0;
}

A span count of zero is invalid. Span counts must be positive integers.

Important Consideration

Using span is helpful when an item must occupy a fixed number of columns but its starting position may change.

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;
}

Second-to-Last Line

.item {
  grid-column-end: -2;
}

Span the Entire Explicit Grid

.item {
  grid-column-start: 1;
  grid-column-end: -1;
}

Equivalent Shorthand

.item {
  grid-column: 1 / -1;
}

End Before the Last Column

.item {
  grid-column-start: 1;
  grid-column-end: -2;
}

The item ends at the line immediately before the last explicit column.

Negative Line Reference

In a four-column grid, line -1 corresponds to line 5, line -2 corresponds to line 4, and line -3 corresponds to line 3.

Important Consideration

Negative line numbers reference the explicit grid. They do not automatically count backward from the outermost implicit column.

Named Grid Lines

Named grid lines allow an item's ending boundary to be identified using a descriptive name.

Define Named Lines

.container {
  display: grid;
  grid-template-columns:
    [content-start] 200px
    [main-start] 1fr
    [content-end];
}

End at a Named Line

.item {
  grid-column-start: content-start;
  grid-column-end: content-end;
}

End the Main Content

.main {
  grid-column-start: main-start;
  grid-column-end: content-end;
}

Repeated Named Lines

.container {
  display: grid;
  grid-template-columns:
    [col] 1fr
    [col] 1fr
    [col] 1fr
    [col];
}
.item {
  grid-column-start: col 1;
  grid-column-end: col 3;
}

The integer identifies a particular occurrence of the named grid line.

Named Span

.item {
  grid-column-start: col 1;
  grid-column-end: span col 2;
}

The ending boundary is determined by counting matching named lines forward from the starting position.

Named Areas and Implicit Line Names

.container {
  display: grid;
  grid-template-areas: "sidebar main";
  grid-template-columns: 200px 1fr;
}
.main {
  grid-column-end: main-end;
}

Named grid areas automatically create corresponding -start and -end line names.

Important Consideration

Named lines can improve readability, but the names must be chosen carefully. References to missing names can resolve through implicit named-line behavior and produce unexpected placement.

Automatic Placement

The auto keyword allows the grid placement algorithm to determine the ending boundary of a grid item.

Default Value

.item {
  grid-column-end: auto;
}

Definite Starting Line

.item {
  grid-column-start: 2;
  grid-column-end: auto;
}

For an ordinary grid item without another span requirement, the item occupies one column beginning at line 2.

Automatic Starting Line

.item {
  grid-column-start: auto;
  grid-column-end: 4;
}

The ending boundary is definite, while the starting boundary is resolved automatically.

Both Boundaries Automatic

.item {
  grid-column-start: auto;
  grid-column-end: auto;
}

Auto-Placement Direction

.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-flow: row;
}

Dense Auto-Placement

.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-auto-flow: row dense;
}

Dense placement allows later automatically positioned items to fill available gaps when their spans fit.

Important Consideration

Automatic placement does not mean that the ending line is always the next numbered line. The result depends on the item's other placement values and the grid placement algorithm.

Implicit Grid Columns

Grid placement can generate implicit columns when an item's specified boundaries extend outside the explicit grid.

Define Three Explicit Columns

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-columns: 120px;
}

End Beyond the Explicit Grid

.item {
  grid-column-start: 3;
  grid-column-end: 6;
}

The item starts at line 3 and ends at line 6. Since the explicit grid ends at line 4, additional implicit columns are required.

Size Implicit Columns

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-columns: minmax(100px, auto);
}

Implicit Columns Before the Grid

.item {
  grid-column-start: -6;
  grid-column-end: -4;
}

Negative line references extending beyond the starting boundary of the explicit grid can create implicit columns before it.

Important Consideration

The grid-column-end property determines where an item stops. The grid-auto-columns property determines the sizes of any implicit columns that are generated.

Start and End Lines

The grid-column-start and grid-column-end properties work together to establish a grid item's column boundaries.

Start at Line One

.item {
  grid-column-start: 1;
}

End at Line Four

.item {
  grid-column-end: 4;
}

Combine Both Properties

.item {
  grid-column-start: 1;
  grid-column-end: 4;
}

The item spans three columns.

Matching Start and End Lines

.item {
  grid-column-start: 2;
  grid-column-end: 2;
}

When both boundaries resolve to the same line, the placement rules treat the ending position as automatic, producing a nonzero span.

Reversed Numeric Boundaries

.item {
  grid-column-start: 4;
  grid-column-end: 2;
}

Grid placement normalizes the resolved boundaries so the item occupies the tracks between the two lines.

Important Consideration

For predictable placement, specify distinct starting and ending grid lines in the intended order.

The grid-column Shorthand

The grid-column shorthand combines grid-column-start and grid-column-end into one declaration.

Separate Longhand Properties

.item {
  grid-column-start: 2;
  grid-column-end: 5;
}

Equivalent Shorthand

.item {
  grid-column: 2 / 5;
}

Shorthand with Span

.item {
  grid-column: 2 / span 3;
}

Full-Width Shorthand

.item {
  grid-column: 1 / -1;
}

Override Only the Ending Line

.item {
  grid-column: 1 / 3;
}
.item.featured {
  grid-column-end: 5;
}

The second rule changes only the ending line, preserving the starting line assigned by the shorthand.

Shorthand Reset Behavior

.item {
  grid-column-start: 2;
  grid-column-end: 5;
  grid-column: 1;
}

The final shorthand sets the starting line to 1 and resets the ending line to auto.

Important Consideration

Use the longhand property when only the ending boundary needs to change. Use the shorthand when both column boundaries should be declared together.

Responsive Layouts

The grid-column-end property can adjust how far an item extends when the number of grid columns changes.

Two-Column Layout

.layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.layout .featured {
  grid-column-start: 1;
  grid-column-end: -1;
}

Four-Column Layout

@media (min-width: 900px) {
  .layout {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .layout .featured {
    grid-column-end: span 2;
  }
}

The featured item spans the entire explicit grid at smaller widths and two columns at larger widths.

Responsive Sidebar Layout

.page-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.page-layout .main {
  grid-column-start: 1;
  grid-column-end: -1;
}
@media (min-width: 768px) {
  .page-layout {
    grid-template-columns: 220px minmax(0, 1fr);
  }
  .page-layout .sidebar {
    grid-column-start: 1;
    grid-column-end: 2;
  }
  .page-layout .main {
    grid-column-start: 2;
    grid-column-end: 3;
  }
}

Use Negative End Lines

.section-heading {
  grid-column-start: 1;
  grid-column-end: -1;
}

Ending at -1 keeps the heading aligned with the final explicit grid line when the number of columns changes.

Important Consideration

When using media queries, verify that the starting and ending lines remain appropriate for each grid configuration.

Overlapping Grid Items

Grid items can overlap when their row and column placement areas intersect.

First Grid Item

.item-one {
  grid-column-start: 1;
  grid-column-end: 3;
  grid-row: 1;
}

Second Grid Item

.item-two {
  grid-column-start: 2;
  grid-column-end: 4;
  grid-row: 1;
}

Both items occupy part of the second column in the same row.

Control Stacking Order

.item-two {
  z-index: 2;
}

Grid items can use z-index to control their stacking order even when they are not positioned elements.

Avoid Accidental Overlap

Check both row and column boundaries when multiple items appear in the same grid area.

Important Consideration

Overlapping items retain their original document order. Visual stacking does not change the order in which assistive technologies or keyboard users encounter the content.

Writing Direction

Grid column line numbering follows the logical inline axis of the grid container.

Left-to-Right Layout

.container {
  display: grid;
  direction: ltr;
  grid-template-columns: repeat(3, 1fr);
}
.item {
  grid-column-start: 1;
  grid-column-end: 3;
}

In a horizontal left-to-right layout, the item extends from the leftmost grid line across the first two columns.

Right-to-Left Layout

.container {
  display: grid;
  direction: rtl;
  grid-template-columns: repeat(3, 1fr);
}
.item {
  grid-column-start: 1;
  grid-column-end: 3;
}

In a horizontal right-to-left layout, line 1 begins on the right, so the same declaration spans the first two columns from the right.

Vertical Writing Mode

.container {
  display: grid;
  writing-mode: vertical-rl;
  grid-template-columns: repeat(3, 1fr);
}

In vertical writing modes, the inline axis is vertical, changing the physical orientation of the grid's column tracks.

Important Consideration

Use logical grid placement rather than assuming that the ending column line always corresponds to the physical right side of an element.

Inheritance

The grid-column-end property is not inherited.

Parent Grid Item

.parent-item {
  grid-column-end: 4;
}

Nested Grid Item

.nested-item {
  grid-column-end: auto;
}

The nested item uses its own initial value unless a different value is specified.

Explicit Inheritance

.nested-item {
  grid-column-end: inherit;
}

The inherit keyword copies the computed value from the parent element.

Reset to Initial Value

.item {
  grid-column-end: initial;
}

Reset with unset

.item {
  grid-column-end: unset;
}

Because the property is not inherited, unset has the same effect as initial.

Important Consideration

Inherited line numbers are interpreted within the receiving item's grid context. They do not automatically refer to the parent's grid lines.

grid-column-end Example

This example creates a four-column grid. The featured item starts at the first grid line and ends at the fourth grid line, occupying three columns. The remaining items use automatic placement.

HTML Example

<div class="grid-column-end-demo">
  <div class="grid-item featured">Featured Item</div>
  <div class="grid-item">Item 2</div>
  <div class="grid-item">Item 3</div>
  <div class="grid-item">Item 4</div>
  <div class="grid-item">Item 5</div>
</div>

CSS Example

.grid-column-end-demo {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.grid-column-end-demo .grid-item {
  padding: 20px 8px;
  background-color: #596579;
  color: #ffffff;
  text-align: center;
  font-weight: bold;
  border-radius: 4px;
}
.grid-column-end-demo .featured {
  grid-column-start: 1;
  grid-column-end: 4;
  background-color: #2456a6;
}
Browser Result
Item 2
Item 3
Item 4
Item 5

The featured item uses grid-column-start: 1 and grid-column-end: 4, so it spans the first three columns.

The second item occupies the fourth column of the first row. The remaining items continue onto the next row through automatic placement.

Changing grid-column-end from 4 to 5 would make the featured item span all four columns.

Common Mistakes

Common problems with grid-column-end involve incorrect line references, invalid spans, and misunderstandings about automatic placement.

Forgetting to Establish a Grid

.item {
  grid-column-end: 4;
}

The declaration does not create a grid container. The parent must establish a grid formatting context for normal grid item placement.

Using Grid Line Zero

.item {
  grid-column-end: 0;
}

Grid line zero is invalid.

Confusing the End Line with the Column Count

.item {
  grid-column-start: 1;
  grid-column-end: 3;
}

The item occupies two columns, not three.

Using an Invalid Span

.item {
  grid-column-end: span -2;
}

Span counts must be positive integers.

Using an Unsupported Length

.item {
  grid-column-end: 200px;
}

The property accepts grid line placement values, not physical length values.

Assuming auto Means the Final Grid Line

The auto value uses automatic placement behavior. It does not automatically mean the last grid line.

Assuming Negative Lines Include Implicit Columns

Negative grid line references count from the explicit grid boundary.

Using Missing Named Lines

References to nonexistent named lines may produce unexpected placement through implicit line resolution.

Ignoring Responsive Changes

Fixed ending line numbers may create implicit columns when the grid template changes.

Accidentally Resetting the Ending Line

.item {
  grid-column-end: 5;
  grid-column: 2;
}

The later shorthand resets grid-column-end to auto.

Confusing Rows and Columns

Use grid-row-end to define an item's ending boundary along the row axis.

Important Considerations

Keep the following points in mind when using grid-column-end:

  • Purpose: Specifies where a grid item ends along the column axis.
  • Initial value: 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 boundaries between columns.
  • Positive numbers: Count forward from the start of the explicit grid.
  • Negative numbers: Count backward from the end of the explicit grid.
  • Line zero: Invalid.
  • Named lines: Can be referenced using custom identifiers.
  • Repeated names: Can be distinguished using integer occurrences.
  • Spanning: The span keyword defines how many tracks an item occupies.
  • Span counts: Must be positive integers.
  • Automatic placement: The auto value delegates ending-boundary resolution to the grid placement algorithm.
  • Starting boundary: Controlled by grid-column-start.
  • Shorthand: grid-column combines the starting and ending boundaries.
  • Grid area: grid-area can define both row and column placement.
  • Implicit columns: Can be created when placement extends beyond the explicit grid.
  • Column sizes: Controlled by grid-template-columns and grid-auto-columns.
  • Responsive design: Check ending lines when the number of columns changes.
  • Overlapping: Items can overlap when their grid areas intersect.
  • Writing direction: Grid column numbering follows the logical inline axis.
  • Accessibility: Visual placement does not change document reading order or keyboard navigation order.
  • Browser testing: Verify numbered lines, spans, named lines, and responsive behavior.

The grid-column-end property provides precise control over the ending boundary of grid items. It is particularly useful when adjusting an item's column span, aligning content with named grid lines, or modifying placement without changing its starting boundary.

Browser Support

The CSS grid-column-end 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, negative line references, named lines, and the span keyword.

Standard Example

.container {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}
.item {
  grid-column-start: 1;
  grid-column-end: 3;
}

Legacy Browser Considerations

Internet Explorer used an older, prefixed CSS Grid implementation with different placement properties. It does not support the modern grid-column-end property.

Browser Compatibility

For current compatibility details, visit Can I Use? and search for grid-column-end.

Specifications

The grid-column-end property is defined in the CSS Grid Layout specification.

CSS Grid Layout Module Level 1: grid-column-end

The specification defines grid line placement, named grid lines, spans, and the relationship between the starting and ending boundaries of grid items.

CSS Grid Layout Module Level 2

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: grid-column-end