Useful functions
Functions that simplify creating dynamic and responsive grids.
- repeat(n, value): avoids writing the same value n times manually.
- minmax(min, max): defines minimum and maximum values.
- auto-fit: tries to fit columns to the container’s width; if there’s extra space, it collapses gaps.
- auto-fill: similar to auto-fit, but leaves empty slots if there aren’t enough items.
Example
In this example, with grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)) we create as many columns as fit (auto-fit), each column will be at least 70px, and extra space is distributed proportionally (1fr). With grid-auto-rows: minmax(50px, auto), each row has a minimum height of 50px.
ResultLive
html
css