CSS Reference ยท Grid
The grid-column-end property
Reference for the CSS grid-column-end property: set the grid line where an item stops, with line numbers, names, span and negative values, plus examples.
The grid-column-end property sets the vertical grid line on which a grid item ends. The item covers every column between its start line (grid-column-start) and this end line, and the end line itself is not part of the item. A start of 2 and an end of 4 therefore covers columns 2 and 3.
A handy trick is the end value -1, which means "the last line of the explicit grid" and lets an item stretch across all remaining columns.
.banner { grid-column-start: 1; grid-column-end: -1; }
Try it
Syntax
grid-column-end: auto; grid-column-end: <integer>; grid-column-end: <custom-ident>; grid-column-end: <integer> <custom-ident>; grid-column-end: span <integer>; grid-column-end: span <custom-ident>; grid-column-end: span <integer> <custom-ident>;
- Initial value:
auto - Applies to: grid items and absolutely positioned boxes whose containing block is a grid container
- Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
No end preference. The item spans one column from its start line (or is auto-placed). |
<integer> |
End on that line number. Negative values count from the last line of the explicit grid, so -1 is the final line. |
<custom-ident> |
End on the first line with that name. An area name such as main resolves to the line main-end. |
<integer> <custom-ident> |
End on the nth line with that name. |
span <integer> |
Cover that many columns, counting from the start line. grid-column-end: span 2 with a start of 3 ends on line 5. |
span <custom-ident> |
Span until the next line with that name. |
Usage notes
- The end line is exclusive.
grid-column: 1 / 3covers two columns, not three. -1only knows the explicit grid. If implicit columns were created bygrid-auto-flow: columnor by placing items beyond the template,-1still points at the last explicit line.- Order does not matter. If the end line comes before the start line the browser swaps them; if they are the same line, the item spans one track.
- Prefer
spanfor components.grid-column-end: span 2keeps working if the item is moved to another column, whereas fixed line numbers break. - Pairing. In practice use the
grid-rowstyle shorthandgrid-column: 1 / -1orgrid-column: 2 / span 3instead of two separate declarations. - Responsive layouts. Change the end line inside a media query to make a feature card wider on large screens only.
Browser support
Supported in all current browsers.
Related
grid-column-start- the start linegrid-row-end- the same for rowsgrid-template-columns- defines the lines- Lesson: Placing Grid Items