Skip to content

Grid Item Not Placing Correctly

Quick summary

Your grid item is in the wrong cell or spanning incorrectly because grid-column or grid-row values are wrong.

Why this happens

  • Incorrect grid-column or grid-row values (off-by-one with grid lines)

  • Implicit grid tracks are created when items are placed outside the defined grid

  • Grid areas are named inconsistently

  • Auto-placement conflicts with explicit placement

Minimal example

✗ Broken code
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.item {
  /* Wrong: thinks this is cell 3, but it is line 3 */
  grid-column: 3;
}
✓ Fixed code
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.item {
  /* Place in the second column (between lines 2 and 3) */
  grid-column: 2;
  /* Or span both columns */
  grid-column: 1 / 3;
}

Grid lines are 1-indexed. With 2 columns, there are 3 lines (1, 2, 3). grid-column: 2 places the item between lines 2 and 3 (the second column). grid-column: 1 / 3 spans both columns.

How to diagnose

  • Enable grid overlay in DevTools to visualize the grid lines and cells

  • Check the grid-column and grid-row values — remember they refer to lines, not cells

  • Verify grid-template-areas matches the area names used

How to fix

  • Adjust grid-column/grid-row values — lines are 1-indexed and the end is exclusive

  • Use grid-area shorthand for simpler placement

  • Define grid-template-areas for a visual layout map

  • Add grid-auto-flow: dense to fill gaps automatically

How to prevent

  • Use DevTools grid overlay to verify placement during development

  • Prefer grid-template-areas for complex layouts — it is more readable

  • Remember: grid-column: 1 / 3 spans from line 1 to line 3 (2 cells)

Related Resources

Related Glossary

Related Lessons

← Back to language