Definition
The grid-column-end
CSS property is used in grid layouts to specify the ending position of a grid item along the horizontal axis.
The grid-column-end
property accepts a value that represents the grid line at which the grid item should end. Grid lines can be identified using line numbers, names of named grid lines, or the span
keyword to span across multiple grid tracks.
Here’s an example:
.grid-item {
grid-column-end: span 3;
}
In this example, the grid-column-end: span 3;
rule sets the grid item to span across three grid tracks horizontally. This means the grid item will end at the third grid line from its starting position.
The grid-column-end
property works in conjunction with grid-column-start
to define the horizontal range of grid placement for grid items within a grid container. It provides flexibility in specifying the positioning and spanning of grid items in a grid layout.
Syntax
.card {
grid-column-end: span 2;
}
Values
- Line numbers, named lines, or
span
.
Practical Examples
.card {
grid-column-end: span 2;
}
Specify where the item finishes on the column axis.
<div class="grid gap-4 rounded-xl border border-slate-200 bg-white p-4 shadow-sm" style="display:grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap:1rem;">
<div class="rounded-lg bg-slate-100 p-3 text-sm text-slate-700" style="grid-column:1 / span 2;">Span 2 columns</div>
<div class="rounded-lg bg-slate-100 p-3 text-sm text-slate-700">Default</div>
</div>
Tips & Best Practices
- Using
span
keeps layouts flexible when track counts change.
Accessibility & UX Notes
Ensure wide items remain readable.
Browser Support
Supported broadly.
Related
-
grid-column-start
,grid-column