CSS Grid is a layout system for arranging content in rows and columns. It is useful when a component needs control in two dimensions, from a card collection to a dashboard or a complete page structure.

Define a grid container

Set display: grid on the parent. Use grid-template-columns and grid-template-rows to define tracks. The fr unit distributes available space between flexible tracks, while minmax() sets a minimum and maximum track size.

Use gaps for spacing

The gap property creates consistent space between rows and columns. This keeps the layout predictable and avoids a collection of individual margin adjustments.

Build responsive columns

For cards, a repeat pattern using auto-fit or auto-fill with minmax() can let columns respond to available width. Test long titles and narrow containers so items do not become too small or overflow.

Place items deliberately

Grid items can span tracks or use named areas. Named areas can make a page layout easier to understand when a header, sidebar, main region and footer need distinct positions. Keep the document source order logical so content remains understandable when visual placement changes.

Example

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1.25rem;
}

Combine Grid and Flexbox

Grid can manage the larger two-dimensional structure while Flexbox aligns content inside cards or toolbars. Choose the model that expresses the relationships most clearly.

Conclusion

CSS Grid provides control over rows, columns and responsive track sizing. Start with a clear container, use flexible tracks and test real content at different widths.