CSS grid-auto-rows Property

The CSS grid-auto-rows property defines the size of implicitly created rows in a CSS Grid container.

Implicit rows are generated when grid items need additional rows beyond those explicitly defined by grid-template-rows. The grid-auto-rows property controls the height of those rows using fixed lengths, percentages, flexible fractions, content-based values, and track-sizing functions.

grid-auto-rows Syntax

The grid-auto-rows property accepts one or more track-sizing values. A single value applies to every implicit row. Multiple values form a repeating sizing pattern.

Basic Syntax

selector {
  grid-auto-rows: auto;
}

Fixed Row Height

.container {
  display: grid;
  grid-auto-rows: 120px;
}

Flexible Row Height

.container {
  display: grid;
  grid-auto-rows: 1fr;
}

Minimum and Maximum Height

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

Content-Based Height

.container {
  display: grid;
  grid-auto-rows: max-content;
}

Multiple Row Sizes

.container {
  display: grid;
  grid-auto-rows: 100px 150px;
}

Percentage Height

.container {
  display: grid;
  grid-auto-rows: 25%;
}

CSS-Wide Keywords

.container {
  grid-auto-rows: initial;
}
.container {
  grid-auto-rows: inherit;
}
.container {
  grid-auto-rows: unset;
}
.container {
  grid-auto-rows: revert;
}
.container {
  grid-auto-rows: revert-layer;
}

The property sizes only implicit rows. Rows explicitly defined by grid-template-rows retain their own sizing rules.

Property Values

The grid-auto-rows property supports the following track-sizing values and functions.

Value Description
auto Sizes implicit rows according to their contents and available space using automatic track-sizing rules.
<length> Defines a track height using units such as px, rem, or em.
<percentage> Sizes implicit rows relative to the grid container's content-box height when that height is definite.
<flex> Uses an fr unit to assign a flexible share of available space.
min-content Uses the minimum intrinsic track size required by the contents.
max-content Uses the maximum intrinsic track size required by the contents.
minmax() Defines minimum and maximum track-sizing limits.
fit-content() Limits the track's maximum size while accounting for its content requirements.
inherit Inherits the computed value from the parent element.
initial Resets the property to auto.
unset Resets the non-inherited property to auto.
revert Reverts the property according to the cascade origin rules.
revert-layer Reverts the property according to the cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto
Inherited No
Applies to Grid containers
Computed value As specified, with relative lengths converted to absolute lengths
Animation type By computed value type
Percentages Relative to the grid container's content-box height
Default track sizing auto

Track sizes must be nonnegative. The property accepts a space-separated list of sizes, but the repeat() function is not permitted in its value syntax.

How It Works

CSS Grid creates implicit rows whenever grid placement requires rows outside the explicitly defined grid.

Create a Grid Container

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 120px;
}

Place Grid Items

With three explicit columns and the default row-based auto-placement behavior, the first three items occupy the first row. Additional items require more rows.

Generate Implicit Rows

The browser creates new rows as needed to accommodate the remaining items.

Apply Automatic Row Sizing

Each generated row uses the track size defined by grid-auto-rows.

Continue Placement

Additional items continue to fill the available grid cells according to grid-auto-flow and any explicit placement rules.

Important Consideration

Declaring grid-auto-rows does not create rows by itself. The grid layout must require implicit rows before the property has a visible effect.

Implicit vs. Explicit Rows

CSS Grid distinguishes between rows defined in the grid template and rows generated automatically.

Explicit Rows

.container {
  display: grid;
  grid-template-rows: 100px 150px;
}

The grid contains two explicitly defined rows.

Implicit Rows

.container {
  display: grid;
  grid-template-rows: 100px 150px;
  grid-auto-rows: 200px;
}

Any rows generated outside the explicit grid use the 200-pixel automatic track size.

Place an Item Beyond the Explicit Grid

.item {
  grid-row: 4;
}

Placing an item in the fourth row requires the browser to generate implicit rows beyond the two explicitly defined rows.

Property Comparison

Feature grid-template-rows grid-auto-rows
Controls Explicit rows Implicit rows
Defines track count Yes No
Initial value none auto
Multiple sizes Supported Supported
repeat() function Supported Not supported

Important Consideration

Explicit and implicit rows can coexist in the same grid. Their sizing rules are controlled independently.

Fixed Row Sizes

Fixed lengths assign a predictable height to each implicitly generated row.

Pixel Height

.container {
  display: grid;
  grid-auto-rows: 120px;
}

rem Units

.container {
  display: grid;
  grid-auto-rows: 8rem;
}

em Units

.container {
  display: grid;
  grid-auto-rows: 10em;
}

Fixed Rows with Gaps

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 140px;
  gap: 16px;
}

Rows with Overflow

.container {
  display: grid;
  grid-auto-rows: 100px;
}
.container .grid-item {
  overflow: auto;
}

If an item's content exceeds its fixed row height, overflow handling can prevent that content from covering adjacent grid items.

Important Consideration

Fixed track heights do not automatically expand to accommodate large amounts of content. Use content-based sizing or minmax() when row heights should grow as necessary.

The auto Value

The auto keyword is the initial value of grid-auto-rows.

Basic Example

.container {
  display: grid;
  grid-auto-rows: auto;
}

Content-Based Height

Automatically sized rows use the grid track-sizing algorithm to determine their heights based on content requirements and available space.

Rows with Different Content

.container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: auto;
  gap: 12px;
}

A row containing a taller item may need more height than a row containing only short text.

Automatic Stretching

When the grid container has additional space along the block axis, automatically sized rows may stretch according to the container's alignment settings.

Important Consideration

The auto value does not guarantee equal row heights. The final sizes depend on content, available space, and the grid sizing algorithm.

Fractional Units

The fr unit represents a flexible share of available space in the grid container.

Equal Flexible Rows

.container {
  display: grid;
  height: 400px;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 1fr;
}

Implicit rows share the available height according to the grid's flexible track-sizing rules.

Different Flexible Sizes

.container {
  display: grid;
  height: 500px;
  grid-auto-rows: 1fr 2fr;
}

The sizing pattern alternates between tracks with one and two flexible shares.

Automatic Minimum Size

A bare 1fr track has an automatic minimum sizing behavior that can prevent it from shrinking below certain content requirements.

Allow Rows to Shrink

.container {
  display: grid;
  height: 400px;
  grid-auto-rows: minmax(0, 1fr);
}

Indefinite Container Height

When the grid container has no definite height, fractional track sizing follows the grid's intrinsic sizing rules rather than simply dividing a fixed amount of free space.

Important Consideration

Flexible row sizing does not guarantee that content fits within the available height. Check intrinsic minimum sizes and overflow behavior.

The minmax() Function

The minmax() function establishes minimum and maximum sizing limits for implicit grid rows.

Minimum Height with Automatic Growth

.container {
  display: grid;
  grid-auto-rows: minmax(120px, auto);
}

Each implicit row has a minimum height of 120 pixels but can grow to accommodate content.

Fixed Minimum and Maximum

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

Flexible Maximum

.container {
  display: grid;
  height: 500px;
  grid-auto-rows: minmax(100px, 1fr);
}

Content-Based Maximum

.container {
  display: grid;
  grid-auto-rows: minmax(80px, max-content);
}

Minimum of Zero

.container {
  display: grid;
  grid-auto-rows: minmax(0, 1fr);
}

Sizing Rules

The first argument establishes the minimum track sizing function. The second establishes the maximum. An fr value is permitted as the maximum but not as the minimum.

Important Consideration

When a definite maximum is smaller than the minimum, the maximum is treated as equal to the minimum. The resulting track size must still follow the grid sizing algorithm.

Content-Based Sizing

Content-based track sizes respond to the intrinsic height requirements of grid items.

min-content

.container {
  display: grid;
  grid-auto-rows: min-content;
}

The min-content keyword uses the minimum intrinsic block size required by the row's contents.

max-content

.container {
  display: grid;
  grid-auto-rows: max-content;
}

The max-content keyword uses the maximum intrinsic block size required by the contents.

fit-content()

.container {
  display: grid;
  grid-auto-rows: fit-content(200px);
}

The fit-content() function provides content-based sizing with a specified upper constraint, while still respecting minimum content requirements.

Automatic Sizing

.container {
  display: grid;
  grid-auto-rows: auto;
}

Images and Dynamic Content

Images, expanding panels, and changing text content can influence the height of content-sized implicit rows.

Important Consideration

Content-based row sizing is useful when the amount of content varies. Fixed heights may be more predictable, but they require additional care to avoid clipping or overflow.

Multiple Track Sizes

The grid-auto-rows property accepts multiple track sizes separated by spaces. The sequence repeats as implicit rows are generated.

Two-Size Pattern

.container {
  display: grid;
  grid-auto-rows: 100px 150px;
}

Three-Size Pattern

.container {
  display: grid;
  grid-auto-rows: 80px 120px 160px;
}

Mixed Track Sizes

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

Repeating Pattern

For a grid that creates five implicit rows using 100px 150px, the sizes repeat as follows:

Implicit Row Track Size
Row 1 100px
Row 2 150px
Row 3 100px
Row 4 150px
Row 5 100px

Rows Before the Explicit Grid

When implicit rows are generated before the explicit grid, the sizing pattern is applied in reverse order from the explicit grid boundary.

Important Consideration

The repeat() function is not valid inside grid-auto-rows. Use a space-separated list of track sizes to create a repeating pattern.

Automatic Row Placement

The grid-auto-flow property determines how automatically positioned items move through the grid.

Default Row Placement

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-flow: row;
  grid-auto-rows: 120px;
}

The browser places items across the three columns, generating additional rows as necessary.

Dense Row Placement

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-flow: row dense;
  grid-auto-rows: 120px;
}

Dense packing allows later items to fill earlier available spaces when their spans permit.

Column-Based Placement

.container {
  display: grid;
  grid-template-rows: repeat(2, 100px);
  grid-auto-flow: column;
  grid-auto-rows: 150px;
}

Column-based placement generally creates additional columns. Implicit rows can still be generated by item placement outside the explicit row structure.

Important Consideration

Use grid-auto-flow to control placement direction and grid-auto-rows to control the size of the implicit rows that are created.

Explicit Item Placement

Grid items positioned outside the explicitly defined rows can cause the browser to generate implicit rows.

Define Two Explicit Rows

.container {
  display: grid;
  grid-template-rows: 100px 100px;
  grid-auto-rows: 150px;
}

Place an Item in Row Four

.item {
  grid-row: 4 / 5;
}

The browser creates additional implicit rows to accommodate the specified placement.

Span Beyond the Explicit Grid

.item {
  grid-row: 2 / 5;
}

Use grid-area

.item {
  grid-area: 3 / 1 / 5 / 2;
}

The item begins at the third row line and extends to the fifth row line.

Implicit Rows Before the Explicit Grid

.item {
  grid-row: -5 / -4;
}

Negative line references can create implicit rows before the explicit grid when the specified lines extend beyond its boundaries.

Important Consideration

Implicit rows can be generated before or after the explicit grid. Their sizes follow the applicable implicit track-sizing sequence.

Percentage Sizing

Percentage values size implicit rows relative to the content-box height of the grid container.

Percentage Height

.container {
  display: grid;
  grid-auto-rows: 25%;
}

Definite Container Height

.container {
  display: grid;
  height: 400px;
  grid-auto-rows: 25%;
}

With a definite content-box height of 400 pixels, each implicit row receives a track size of 100 pixels.

Percentage Rows with Gaps

.container {
  display: grid;
  height: 400px;
  grid-auto-rows: 25%;
  row-gap: 20px;
}

Row gaps are added between percentage-sized tracks. The combined heights of the rows and gaps can exceed the grid container.

Indefinite Container Height

When the grid container's height depends on its contents, percentage track sizing can create a cyclic dependency. In these situations, percentages are treated as auto for intrinsic track sizing.

Important Consideration

Percentage row heights are most predictable when the grid container has a definite height. Consider minmax() or content-based sizing when the container height is determined by its contents.

grid-auto-rows vs. grid-template-rows

Both properties define grid row sizes, but they control different types of tracks.

Explicit Row Sizing

.container {
  display: grid;
  grid-template-rows: 100px 150px;
}

Implicit Row Sizing

.container {
  display: grid;
  grid-auto-rows: 120px;
}

Combined Example

.container {
  display: grid;
  grid-template-rows: 100px 150px;
  grid-auto-rows: 120px;
}

The first two rows are explicitly defined. Additional implicit rows use the 120-pixel track size.

Choosing the Correct Property

Use grid-template-rows when the number and sizes of rows are known in advance. Use grid-auto-rows when additional rows may be created automatically.

Important Consideration

The two properties can be used together. grid-auto-rows does not override explicitly defined row sizes.

Responsive Layouts

The grid-auto-rows property is useful for card grids, image galleries, and layouts where the number of rows changes with the available width.

Responsive Card Grid

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  grid-auto-rows: minmax(180px, auto);
  gap: 16px;
}

The number of columns adjusts to the available width, while generated rows have a minimum height of 180 pixels and can grow for taller content.

Fixed-Height Gallery Rows

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 150px;
  gap: 12px;
}

Responsive Row Heights

.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: 120px;
  gap: 12px;
}
@media (min-width: 768px) {
  .gallery {
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: 180px;
  }
}

Content-Friendly Card Heights

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  grid-auto-rows: minmax(160px, auto);
  gap: 16px;
}

Important Consideration

When grid items contain variable amounts of text, avoid fixed heights that could cause content to overflow. A minimum height with an automatic maximum is often more adaptable.

Inheritance

The grid-auto-rows property is not inherited.

Parent Grid Container

.parent-grid {
  display: grid;
  grid-auto-rows: 150px;
}

Nested Grid Container

.nested-grid {
  display: grid;
}

The nested grid uses its own initial grid-auto-rows: auto value unless another value is specified.

Explicit Inheritance

.nested-grid {
  display: grid;
  grid-auto-rows: inherit;
}

The inherit keyword copies the computed value from the parent element.

Reset to Initial Value

.nested-grid {
  display: grid;
  grid-auto-rows: initial;
}

Important Consideration

Nested grid containers maintain independent track-sizing rules. Define implicit row sizes separately when a nested grid requires different behavior.

grid-auto-rows Example

This example creates a three-column grid with automatically generated rows. Every implicit row has a minimum height of 100 pixels and can expand to accommodate its contents.

HTML Example

<div class="grid-auto-rows-demo">
  <div class="grid-item">Item 1</div>
  <div class="grid-item">Item 2</div>
  <div class="grid-item">Item 3</div>
  <div class="grid-item">Item 4</div>
  <div class="grid-item">Item 5</div>
  <div class="grid-item">Item 6</div>
</div>

CSS Example

.grid-auto-rows-demo {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(100px, auto);
  gap: 12px;
}
.grid-auto-rows-demo .grid-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background-color: #2456a6;
  color: #ffffff;
  font-weight: bold;
  border-radius: 4px;
}
Browser Result
Item 1
Item 2
Item 3
Item 4
Item 5
Item 6

The three explicit columns determine how many items fit in each row. Since no rows are explicitly defined, the browser generates implicit rows as needed.

The grid-auto-rows: minmax(100px, auto) declaration gives each generated row a minimum height of 100 pixels while allowing it to grow if the contents require additional space.

The gap property adds 12 pixels between rows and columns without changing the declared minimum track height.

Common Mistakes

Common problems with grid-auto-rows involve confusing implicit and explicit tracks or expecting the property to create rows automatically.

Expecting the Property to Create Rows

.container {
  display: grid;
  grid-auto-rows: 150px;
}

This declaration sizes implicit rows but does not determine how many rows the grid creates.

Using It Instead of grid-template-rows

Use grid-template-rows to define explicit rows. Use grid-auto-rows to size rows generated outside the explicit grid.

Using Negative Track Sizes

.container {
  grid-auto-rows: -100px;
}

Negative track sizes are invalid.

Using repeat()

.container {
  grid-auto-rows: repeat(3, 100px);
}

The repeat() function is not permitted in grid-auto-rows. Use a space-separated list of track sizes instead.

Assuming auto Produces Equal Heights

Automatically sized rows respond to their contents and available space. They do not always have identical heights.

Ignoring Content Overflow

Fixed-height rows may be too small for their contents. Consider minmax(100px, auto) when rows should expand as needed.

Assuming Percentages Always Resolve Predictably

Percentage row sizes depend on the grid container's height. An indefinite height can produce different sizing behavior from a fixed-height container.

Confusing Rows and Columns

The grid-auto-rows property sizes implicit rows. Use grid-auto-columns to size implicit columns.

Ignoring Row Gaps

Row gaps add space between tracks. They are not included in the specified track height.

Expecting grid-auto-flow to Set Row Heights

The grid-auto-flow property controls placement direction and packing behavior, not row height.

Important Considerations

Keep the following points in mind when using grid-auto-rows:

  • Purpose: Controls the size of implicitly generated grid rows.
  • Initial value: auto.
  • Inheritance: The property is not inherited.
  • Applies to: Grid containers.
  • Explicit rows: Controlled separately by grid-template-rows.
  • Row generation: Occurs when item placement requires tracks outside the explicit grid.
  • Automatic placement: Row-based placement commonly generates additional implicit rows.
  • Fixed sizing: Supports nonnegative length values.
  • Percentage sizing: Relative to the grid container's content-box height.
  • Flexible sizing: Supports fr units.
  • Content sizing: Supports auto, min-content, and max-content.
  • Track limits: Supports minmax() and fit-content().
  • Multiple values: A space-separated list repeats as implicit rows are generated.
  • repeat(): Not supported in this property.
  • Track count: The property does not define the number of rows.
  • Grid gaps: Controlled separately using gap or row-gap.
  • Overflow: Fixed row heights may require additional content overflow handling.
  • Responsive design: Row heights can be adjusted using media queries.
  • Dynamic content: Content-based row sizing can accommodate changing text and image dimensions.
  • Accessibility: Avoid fixed row heights that clip text when users enlarge fonts or increase text spacing.
  • Browser testing: Check implicit track creation, sizing, and overflow with different content lengths.

The grid-auto-rows property provides consistent sizing rules for rows that are generated as content is added or positioned outside the explicit grid. It is particularly useful for responsive card layouts and other grids where the number of rows is not known in advance.

Browser Support

The CSS grid-auto-rows property has Widely available support in modern browsers as part of CSS Grid Layout.

Modern versions of Chrome, Edge, Firefox, Safari, and other major browsers support implicit row sizing with fixed lengths, flexible fractions, and content-based values.

Standard Example

.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: minmax(100px, auto);
}

Legacy Browser Considerations

Internet Explorer used an older, prefixed CSS Grid implementation with different automatic placement and track-sizing behavior. Modern grid-auto-rows declarations are not supported by that legacy grid system.

Browser Compatibility

For current compatibility details, visit Can I Use? and search for grid-auto-rows.

Specifications

The grid-auto-rows property is defined in the CSS Grid Layout specification.

CSS Grid Layout Module Level 1: grid-auto-rows

The specification defines implicit grid tracks, track-sizing functions, and how automatically generated tracks interact with the explicit grid.

CSS Grid Layout Module Level 2

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: grid-auto-rows