CSS grid-auto-rows Property

CSS grid-auto-rows Property


This property is used to set the row size in the grid container.

Syntax - 

grid-auto-rows: auto|max-content|min-content|length;

Now we will see the values with descriptions -

Value

Description

auto

Row size is determined by the size of the largest item in the row, and this is the default value.

max-content

This sets the size of each row to which depends upon the largest item in the row.

min-content

This sets the size of each row which depends upon the largest item in the row

length

By using a legal length value this sets the size of the rows by 

Now we will see the example -
Example  1 -

<style>
.container {
display: grid;
grid-template-columns: 10rem 10rem;
grid-template-rows: 5rem 5rem;
gap: 5px;
}
.item {
background: lightgray;
text-align: center;
}
</style>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
</div>

Output -

We see items 5 and 6 in the grid. These items are in the implicit grid. 

Also notice that they are automatically sized to fit their content. 

This is the default behavior for implicit grid items. 
 

This behavior can be controlled with the grid-auto-rows property, where we specify the sizing for implicit grid rows. 
Example -

specifying grid-auto-rows

<style>
.container {
display: grid;
grid-template-columns: 10rem 10rem;
grid-template-rows: 5rem 5rem;
grid-auto-rows: 5rem;
gap: 5px;
}
.item {
background: lightgray;
text-align: center;
}
</style>

<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
</div>

Output -