Performance: Grid rows and columns
This affects how the browser calculates layout and paints the grid structure, impacting page load and rendering speed.
Jump into concepts and practice - no test required
display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(5, auto);
display: grid; grid-template-columns: repeat(50, 1fr); grid-template-rows: repeat(50, 1fr);
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large grid (50x50) | High (many grid cells) | High (many layout recalculations) | High (many paint areas) | [X] Bad |
| Moderate grid (5x5) | Low (fewer grid cells) | Low (simpler layout) | Low (fewer paint areas) | [OK] Good |
grid-template-columns control in a grid layout?grid-template-columns suggests it controls columns.repeat() function is the correct way to repeat values in grid-template-columns.display: grid; grid-template-columns: 150px 1fr 2fr; grid-template-rows: 100px auto;
display: grid; grid-template-columns: 100px, 200px, 100px; grid-template-rows: 50px 50px;
repeat(4, 1fr) creates 4 columns each taking equal space.grid-template-rows: 100px 1fr 1fr; sets first row fixed 100px, next two share remaining space equally.