Course contentsShow
← Web Development
Lesson 376 of 2,9826. CSS GridFree lesson

Grid with Fallbacks

Provide Flexbox or float-based fallbacks for browsers without Grid support.

Grid with Fallbacks

You'll learn how to support older browsers that don't understand CSS Grid by providing alternative layouts.

Why Fallbacks Matter

Not all browsers support CSS Grid, especially older versions of Internet Explorer and very outdated mobile browsers. However, Grid wasn't the first layout tool—Flexbox and floats came before it. A "fallback" means writing simpler CSS that older browsers can understand, then layering Grid on top for browsers that support it.

How Fallbacks Work

The key insight: browsers ignore CSS properties they don't understand. If a browser sees display: grid, but doesn't support Grid, it simply skips that rule and uses whatever layout came before.

Think of it like ordering at a restaurant with backup choices: "I'll have the special if you have it, otherwise the regular menu item." Older browsers get the regular item (Flexbox or float layout), modern browsers get the special (Grid).

The Fallback Pattern

.container {
  /* Fallback: Flexbox for older browsers */
  display: flex;
  flex-wrap: wrap;
}

.container {
  /* Modern: Grid for supporting browsers */
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.item {
  /* Fallback spacing */
  flex: 1 1 250px;
  margin: 10px;
}

Browsers that don't understand display: grid will use display: flex instead. Modern browsers apply the Grid rules last, overriding the Flexbox. You might need to reset Flexbox-specific properties (like margin) when Grid takes over, but the basic structure works.

Key Takeaway: Write simpler Flexbox or float layouts first, then add Grid declarations afterward—older browsers use the fallback automatically while modern browsers upgrade to Grid.