← Back to Learning Path Level 2 • Lesson 5 of 6
Level 2 progress 0% complete

Lesson 5: Avoiding Common Mistakes

Learn to recognize and fix the most common Grid errors.

Common Grid Mistakes

Even experienced developers make these mistakes. Learning to spot and fix them will save you hours of debugging.

Mistake 1: Forgetting display: grid

The most common mistake is forgetting to actually enable Grid.

Wrong
.container {
  grid-template-columns: 1fr 1fr 1fr;
  /* Missing display: grid! */
}
Correct
.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

Mistake 2: Using Commas in grid-template-columns

Grid values are space-separated, not comma-separated.

Wrong
grid-template-columns: 1fr, 1fr, 1fr;
Correct
grid-template-columns: 1fr 1fr 1fr;

Mistake 3: Mixing Up grid-column and grid-template-columns

These are different properties with different purposes.

/* Container */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
}

/* Item */
.item {
  grid-column: span 2; /* Item spans 2 columns */
}

Mistake 4: Percentages with Gap

Percentages do not account for gap space, so use FR units instead.

Wrong (columns overflow)
grid-template-columns: 33.33% 33.33% 33.33%;
gap: 20px; /* Gap breaks the layout */
Correct
grid-template-columns: 1fr 1fr 1fr;
gap: 20px; /* Gap is automatically accounted for */

Mistake 5: Using Old Syntax

The old grid-gap property still works, but use the modern gap instead.

Old (still works)
grid-gap: 20px;
Modern
gap: 20px;

Mistake 6: Not Planning for Mobile

Always test on mobile. Many columns do not work on small screens.

/* Desktop: 4 columns */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

/* Mobile: 1 column */
@media (max-width: 768px) {
  .grid {
    grid-template-columns: 1fr;
  }
}

Mistake 7: Overthinking Alignment

Do not use Grid for centering a single item; Flexbox is simpler.

Better with Flexbox
.center {
  display: flex;
  align-items: center;
  justify-content: center;
}

Debugging Tips

Pro Tip When something does not work, first check: is display: grid set, and are there any commas? These two issues cause most Grid problems.

Practice Time

Try the generator and intentionally make a mistake, like using commas, and see what happens.

Open Generator

Quick Check

Test your knowledge before moving to the next lesson. All 3 questions must be correct to continue.

1. What is wrong with: grid-template-columns: 1fr, 2fr, 1fr;

2. Why is using percentages with gap problematic?

3. What is the modern property name for spacing?

← Previous: Lesson 4