π What is minmax()?
minmax() is a CSS Grid sizing function that allows you to define aminimum and maximum size for grid rows or columns. It creates responsive and flexible grid tracks that resize intelligently based on available space.
π― Syntax
minmax() Syntax
minmax(<minimum>, <maximum>)You can use many CSS units: px, %, fr, auto, max-content, min-content, etc.
π Why Use minmax()?
- To prevent items from getting too small or too large
- To make responsive layouts without media queries
- To create dynamic grids that adapt to screen width
- To mix flexible (fr) and fixed sizing safely
π§ͺ Basic Example
Basic minmax Example
.container {
display: grid;
grid-template-columns: minmax(200px, 1fr) 1fr;
}The first column will never be smaller than 200px, but can stretch up to 1fr.
π Visual Representation

π₯ Creating Responsive Grids With auto-fit / auto-fill
minmax() becomes extremely powerful when used withrepeat(auto-fit / auto-fill).
Fully Responsive Grid
.gallery {
display: grid;
gap: 20px;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}Each item will be at least 250px wide, but the grid automatically adds/removes columns as space changes.
π Popular minmax() Patterns
1οΈβ£ Fixed Minimum, Flexible Maximum
minmax with fixed min
minmax(150px, 1fr)Prevents items from shrinking too small on small screens.
2οΈβ£ Content-Based Minimum
Content Min
minmax(min-content, 1fr)Ensures the track is never smaller than the smallest content size.
3οΈβ£ Content-Based Maximum
Content Max
minmax(0, max-content)Lets content expand without wrapping if space allows.
4οΈβ£ Preventing Overflow
minmax(0, 1fr)
minmax(0, 1fr)Ensures columns shrink safely without causing overflow β commonly used for complex dashboard layouts.
π§© Practical Example β Card Grid
Responsive Cards
.cards {
display: grid;
gap: 15px;
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}Columns grow, shrink, and auto-wrap without media queries.
π± Another Example β Sidebar + Content
Sidebar Layout
.layout {
display: grid;
grid-template-columns: minmax(240px, 300px) 1fr;
}The sidebar stays between 240pxβ300px.
The content takes up the rest.
β οΈ Common Mistakes
- Using auto when you should constrain with minmax()
- Mixing fixed px values with fr units incorrectly
- Expecting minmax() to affect grid alignment (it only controls track size)
- Forgetting that minmax() is applied to tracks, not items
Note
π₯ Summary
minmax() is one of the most powerful and essential tools in CSS Grid. It gives your layouts flexibility while preventing UI breakage. Whether itβs responsive galleries, sidebars, or dashboards, minmax() ensures smooth resizing across all screen sizes.
Learn more βMDN Docs π