CSS
🎯 CSS grid-column-end Property
grid-column-end is a CSS Grid property that specifies where a grid item should end horizontally within a grid layout. It allows you to control the ending column line of an element, making it easier to create precise and responsive grid designs.
By combining grid-column-start and grid-column-end, you can define exactly how many columns an item should occupy.
🔹 grid-column-end Values
1️⃣ auto
The browser automatically determines the ending column based on the grid's placement rules.
.item {
grid-column-end: auto;
}
2️⃣ Column Line Number
You can specify a column line number to determine exactly where the grid item should end.
.item {
grid-column-end: 4;
}
In this example, the element ends at the fourth column line.
3️⃣ span
The span keyword allows an element to stretch across a specified number of columns.
.item {
grid-column-end: span 2;
}
This means the element will span across two columns from its starting position.
4️⃣ initial
Resets the property to its default value.
.item {
grid-column-end: initial;
}
📌 Practical Example
.container {
display: grid;
grid-template-columns: repeat(4, 1fr);
}
.item {
grid-column-start: 2;
grid-column-end: 4;
}
In this example, the grid item starts at column line 2 and ends at column line 4, occupying two columns of space.
🚀 Why Use grid-column-end?
The grid-column-end property is useful when building advanced CSS Grid layouts. It gives you complete control over how wide an element should be and where it should finish within the grid structure.
- Create custom grid item widths
- Control element positioning precisely
- Build responsive layouts more easily
- Combine with grid-column-start for full placement control
-
🧠 Quick Summary
- grid-column-end defines where a grid item ends horizontally.
- auto allows automatic placement.
- Numeric values specify an exact ending column line.
- span extends an element across multiple columns.
- Frequently used in responsive and professional CSS Grid layouts.
