Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

How can I place a grid item across several columns?

Quick answer

Give the item a grid-column start line and use span to say how many column tracks it should cover. For example, grid-column: 1 / span 2 starts at line 1 and covers two columns. Other items without explicit placement are still auto-placed, so check the resulting layout for gaps or overlap. [S1] [S2]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I have a three-column CSS grid and want one card to stretch across the first two columns. What do I put on that card?

Geez

Set its grid-column to start at line 1 and span two tracks:

.featured {
  grid-column: 1 / span 2;
}

Here, 1 identifies the starting grid line, and span 2 means the item covers two column tracks from there. [S1]

For a minimal example, assuming you already have a three-column grid container:

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.featured {
  grid-column: 1 / span 2;
}

Apply the featured class to the item you want to span. The declaration controls that item’s column placement; it does not tell every other card where to go.

Follow-up question

Can you explain the line numbers? I find it easier to picture them than read the CSS.

Geez

Think of the three columns as spaces between four vertical lines. The lines mark the boundaries; the column tracks are the spaces between them:

line 1       line 2       line 3       line 4
   | column 1 | column 2 | column 3 |
   |<------ featured item ------->|

With grid-column: 1 / span 2, the item begins at line 1 and spans column 1 plus column 2. Its end is at line 3. The span value counts tracks to cover, not the number of boundary lines to move past. This is line-based placement: a grid item can be given a start and end line, or a span count. [S1]

Follow-up question

What happens to the cards that don’t have a grid-column rule? Do they fill the empty third column?

Geez

They remain auto-placed. In the default behavior described in the Grid guide, items without explicit positions are considered in source order and placed into available space, filling rows before creating implicit rows when needed. [S2]

For example, assuming the featured card comes first in the HTML and three ordinary cards follow, the first ordinary card may fit in the remaining third column. The next one may go onto the next row, depending on the grid and the space already occupied. The exact result depends on the other items’ placement and spans; the spanning rule alone doesn’t promise a particular arrangement for every card.

If an item doesn’t fit in the available spot because of spans, auto-placement can move it to another available space, potentially leaving a hole. [S2] So look at the rendered grid, rather than assuming the remaining cards will pack into a specific pattern.

Follow-up question

How should I check the result if I have several cards and the layout looks wrong?

Geez

First check whether the spanning item starts where you intended and covers the intended number of tracks. Then inspect the other items’ explicit placements: two explicit placements can overlap, and items that have no explicit position follow auto-placement rules. [S1] [S2]

A small test layout is easier to reason about than changing several rules at once. For instance, label cards A–D temporarily and sketch their intended cells. If A spans columns 1–2 on the first row, note that column 3 on that row is the remaining space; then compare the browser’s result with your sketch. If you choose explicit placements for more cards, check each one for unintended overlap. [S1]

Use this checklist while debugging: identify the span, mark the start line, check any other explicit placements, and then observe where the remaining items land. Auto-placement can leave holes when spans affect what fits next. [S2]

A practical checklist

  • Confirm the grid container has the intended column tracks.

  • Choose the spanning item and identify its starting grid line.

  • Set grid-column with a span count for the number of tracks to cover.

  • Check other explicit placements for unintended overlap.

  • Inspect where unplaced items land and whether spans leave holes.

A few more useful answers

Can I specify the ending grid line instead of using `span`?

Yes. Grid placement can use a start and end grid line, or a span count. For example, grid-column: 1 / 3 specifies lines 1 and 3; grid-column: 1 / span 2 specifies a start and the number of tracks to span. [S1]

Will the other items always fill every open spot?

No. Auto-placement puts items into available space under its placement rules, but spanning items can leave holes when later items do not fit. [S2]

Could explicitly positioning another card cause a collision?

It could: explicit placements can overlap. Check the placement of each explicitly positioned item against the others. [S1]

Sources

References used for this guide.

  1. [S1] Grid layout using line-based placement
    developer.mozilla.org · Checked
  2. [S2] Auto-placement in grid layout
    developer.mozilla.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work