What is the difference between fr and percent in grid?▾
Percent tracks are calculated from the grid container's total size, including gaps. fr units distribute only the remaining free space after fixed tracks and gaps are subtracted. In most cases fr is more predictable since it avoids overflow caused by combining percent tracks with gaps.
When should I use auto-fit vs auto-fill?▾
Both keywords create as many tracks as will fit at the minimum size. auto-fit collapses empty tracks to zero width, so remaining items stretch to fill the container. auto-fill keeps empty tracks at their minimum size, leaving space. For growing items, auto-fit is usually what you want.
How do named grid areas work?▾
grid-template-areas assigns string names to rectangular regions. A cell name repeated in adjacent columns/rows spans those cells. Items placed with grid-area: name automatically occupy the named region. The string pattern serves as a visual map of the layout.
What is the difference between grid and flexbox?▾
Grid is two-dimensional — you define both rows and columns and place items across both axes simultaneously. Flexbox is one-dimensional — items flow along one axis. Use grid for page scaffolds and component layouts requiring both-axis alignment; use flexbox for toolbars, navigation rows, and single-axis arrangements.
Can grid items overlap each other?▾
Yes. Grid items can be placed in the same cell or overlapping cell ranges using grid-column and grid-row. z-index controls visual stacking order for overlapping items. This makes grid useful for layered UI like image overlays and stacked hero content.
How do I make a grid responsive without media queries?▾
Use repeat(auto-fit, minmax(minimum, 1fr)) for grid-template-columns. The browser calculates how many tracks fit at the minimum size and reflows automatically as the container resizes. This one declaration handles most responsive card grid scenarios without breakpoints.
What does minmax(280px, 1fr) mean?▾
minmax() defines a range for a track size. 280px is the minimum size — the track will never shrink below this. 1fr is the maximum — when there is extra space, the track grows proportionally with other fr tracks. This pattern creates responsive tracks that flex above their minimum.
Why are my grid items not in the cells I expected?▾
CSS grid places items in auto-flow order (left-to-right, top-to-bottom) by default. If explicit placements using grid-column or grid-row conflict or leave gaps, auto-placed items fill in differently than expected. Use grid-auto-flow: dense to fill holes, or explicitly place all items.