CSS Grid
Create two-dimensional layouts with explicit tracks, auto placement, and resilient minimums.
Grid controls rows and columns together. Track functions define available space, minmax() protects useful minimums, and auto-fit can create responsive card layouts without a breakpoint for every device width.
See the core pattern
Read this rule set from the outside in. Identify the inputs, the decision or transformation, and the result before changing it.
.course-grid {
display: grid;
grid-template-columns:
repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
gap: 1.25rem;
}
/* Add multi-column spans only when the layout has enough tracks. */Working rules
- Use minmax(0, 1fr) when content causes track overflow
- Name important page regions when it improves clarity
- Let auto placement handle regular collections
A common mistake
A minimum such as 320px can still overflow a 280px viewport. Wrap it with min(100%, 20rem).
Guided practice
Choose the function that repeats as many tracks as fit while collapsing unused ones.
- Copy the example into the editable notebook below.
- Change one thing at a time and keep the program or rule valid.
- Explain the result in one sentence without relying on jargon.