71. Grid Gaps (Spacing Between Tracks)
Similar to Flexbox, CSS Grid uses the gap properties to define spacing between grid tracks (columns and rows), eliminating the need for complex margin calculations on grid items.
The Gap Properties
column-gap: Space between columns (vertical lines).row-gap: Space between rows (horizontal lines).gap(Shorthand): Sets bothrow-gapandcolumn-gap.
Example
css .grid-container { display: grid; grid-template-columns: repeat(3, 1fr);
/* 1. Setting individual gaps */ row-gap: 20px; column-gap: 15px;
/* 2. Shorthand (preferred for equal spacing) / / gap: 20px; */
/* 3. Shorthand (Row, Column) / / gap: 20px 15px; */ }
Key Advantage: Unlike margins, gap spacing is always internal to the container and never leaks outside or causes margin collapse, making spacing highly predictable.