CSS

CSS Minmax: Syntax, Usage, and Examples

The minmax() function in CSS defines a size range—setting both a minimum and maximum—for grid tracks. It’s part of the CSS grid layout system and helps make layouts responsive and flexible. The CSS minmax function allows a track to shrink no smaller than a given minimum and grow no larger than a specified maximum, making it ideal for fluid, grid-based designs.

How to Use CSS Minmax

The minmax() function is used within the grid-template-columns or grid-template-rows properties when defining CSS grid layouts.

grid-template-columns: minmax(min, max);
  • min: the minimum size the column or row can shrink to
  • max: the maximum size it can grow to

Example:

.container {
  display: grid;
  grid-template-columns: minmax(200px, 1fr);
}

This creates one column that won’t shrink below 200 pixels but can grow as large as one fraction of the available space.

When to Use Minmax CSS

Use CSS minmax when you want grid tracks to be responsive while maintaining a sensible lower and upper bound. It works best in flexible layouts that need to adjust across different devices and screen sizes.

Creating Flexible Columns

grid-template-columns: minmax(150px, 300px);

This column adjusts between 150px and 300px depending on the space available. It’s great for ensuring your content doesn’t become unreadably narrow or too wide.

Combining with Fractional Units

grid-template-columns: 1fr minmax(150px, 3fr) 1fr;

This setup allows one track to grow more aggressively than the others, but only after it reaches a base size. This balances content width without breaking the layout.

Building Responsive Layouts

When you don’t know exactly how much space your container will have, minmax helps adapt the content gracefully:

grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));

This repeats columns that are at least 250px wide but stretch to fill the row if more space is available.

Examples of CSS Minmax in Action

A Basic 2-Column Layout

.container {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) 2fr;
  gap: 16px;
}

One column starts at 200px but grows with the layout. The second column gets twice the space of the first.

Auto-Fitting Columns with a Minimum Width

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

This layout automatically adds or removes columns based on the container size. It’s one of the most common patterns for responsive card layouts.

Dynamic Row Height

.grid {
  display: grid;
  grid-template-rows: minmax(100px, auto);
}

This ensures rows don’t shrink below 100px but can grow to fit their content.

Learn More About CSS Grid Minmax

Using Auto, %, px, fr, and min-content/max-content

The min and max values in minmax() can be any valid length unit or keyword:

  • px, em, rem: fixed sizes
  • %: relative to container
  • fr: fractional space
  • auto: adapts to content
  • min-content / max-content: adjusts to smallest or largest content size

Example using content-based sizing:

grid-template-columns: minmax(min-content, 1fr);

This column won’t be smaller than the smallest word or content, but it can stretch up to fill the remaining space.

Nesting Minmax Inside Repeat

You can nest minmax inside a repeat() function to create multiple responsive tracks:

grid-template-columns: repeat(3, minmax(100px, 1fr));

This creates three equal-width columns that can shrink to 100px and grow equally beyond that if space allows.

Combining With Auto-Fill vs Auto-Fit

grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  • auto-fill fills the grid with as many columns as possible, even empty ones.
  • auto-fit collapses empty columns, giving more space to those that remain.

Both work well with minmax to create responsive, auto-adjusting layouts.

CSS Grid Minmax vs Flexbox

Flexbox is useful for one-dimensional layouts, while CSS grid minmax shines in two-dimensional arrangements. Here’s a key difference:

Flexbox might require manual width limits:

.flex-item {
  flex: 1 1 200px;
  max-width: 300px;
}

Grid handles this more declaratively:

grid-template-columns: minmax(200px, 300px);

No need for individual item rules—just declare track behavior up front.

CSS Minmax for Sidebars and Main Content

A popular use case is layouts with a fixed-width sidebar and a flexible main area:

grid-template-columns: minmax(200px, 300px) 1fr;

The sidebar never gets too narrow or too wide, and the content area grows naturally.

Advanced Layout with Minmax and Grid Areas

.layout {
  display: grid;
  grid-template-columns: minmax(250px, 1fr) 2fr;
  grid-template-areas:
    "sidebar main";
}

This makes your layout semantic, responsive, and visually balanced—all in one clean declaration.

Accessibility Considerations

While CSS minmax is layout-focused, it helps prevent overly compressed text and avoids layout breaking. Use it to maintain minimum readable widths for content like paragraphs, forms, or buttons. Combine with semantic HTML and ARIA labels for optimal accessibility.

Troubleshooting Minmax Behavior

  • Avoid nesting minmax within fixed-size containers that don't have room to expand.
  • Test different units (fr, px, auto) to see how they interact.
  • Use developer tools to inspect how each grid track behaves at different breakpoints.

The CSS minmax function is one of the most versatile tools in grid layout design. It allows you to set dynamic size limits that adapt gracefully across screen sizes and content types.

Learn CSS for Free
Start learning now
button icon
To advance beyond this tutorial and learn CSS by doing, try the interactive experience of Mimo. Whether you're starting from scratch or brushing up your coding skills, Mimo helps you take your coding journey above and beyond.

Sign up or download Mimo from the App Store or Google Play to enhance your programming skills and prepare for a career in tech.

You can code, too.

© 2025 Mimo GmbH