
- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Advanced Features
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - grid-auto-rows Property
CSS grid-auto-rows property defines the dimensions for a grid row track or a set of tracks that are implicitly created. When a grid item is placed in a row with no specified size via grid-template-rows, the grid system creates implicit grid lanes to accommodate it. The property does not have any effect if grid-template-rows is used.
Syntax
grid-auto-rows: auto | length | percentage | max-content | min-content | minmax(min, max)| fit-content();
Property Values
Value | Description |
---|---|
auto | The size of the rows depends on the size of the container. Default. |
length | The size of the row is set using length units. |
percentage | The size of the row is set using percentage values. |
max-content | The size of the row depends on the length of the content. Wrapping do not occur. |
min-content | The size of the row depends on the length of the content. Wrapping occurs. |
minmax(min, max) | It specifies the minimum default row size and the maximum attainable row size. |
fit-content() | It specifies a size within which the content is to be shown. Wrapping can occur. |
Examples of CSS Grid Auto Rows Property
The following examples explain the grid-auto-rows property with different values.
Grid Auto Rows Property with Auto Value
To allow the grid item to size itself based on its content and the available space in the grid container, we use the auto value. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { background-color: lightgray; padding: 10px; display: grid; grid-auto-rows: auto; gap: 10px; } .grid-item { background-color: #336699; border: 3px solid blue; padding: 10px; text-align: center; color: white; } .item1 { grid-area: 1 / 1 / 2 / 2; } .item2 { grid-area: 1 / 2 / 2 / 3; } .item3 { grid-area: 1 / 3 / 2 / 4; } .item4 { grid-area: 2 / 1 / 3 / 2; } .item5 { grid-area: 2 / 2 / 3 / 3; } </style> </head> <body> <h2> CSS grid-auto-rows property </h2> <h4> grid-auto-rows: auto </h4> <div class="grid-container"> <div class="grid-item item1"> Item-1 </div> <div class="grid-item item2"> Item-2 </div> <div class="grid-item item3"> Item-3 </div> <div class="grid-item item4"> Item-4 </div> <div class="grid-item item5"> Item-5 </div> </div> </body> </html>
Grid Auto Rows Property with Length Values
To set the size of implicit rows, we can specify the size in length units (e.g. 10px, 20em etc.). All the implicitely created rows will thus be having the specified size. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { background-color: lightgray; padding: 10px; display: grid; grid-auto-rows: 140px; gap: 10px; } .grid-item { background-color: #336699; border: 3px solid blue; padding: 10px; text-align: center; color: white; } .item1 { grid-area: 1 / 1 / 2 / 2; } .item2 { grid-area: 1 / 2 / 2 / 3; } .item3 { grid-area: 1 / 3 / 2 / 4; } .item4 { grid-area: 2 / 1 / 3 / 2; } .item5 { grid-area: 2 / 2 / 3 / 3; } </style> </head> <body> <h2> CSS grid-auto-rows property </h2> <h4> grid-auto-rows: 140px (each row is 140px high) </h4> <div class="grid-container"> <div class="grid-item item1"> Item-1 </div> <div class="grid-item item2"> Item-2 </div> <div class="grid-item item3"> Item-3 </div> <div class="grid-item item4"> Item-4 </div> <div class="grid-item item5"> Item-5 </div> </div> </body> </html>
Grid Auto Rows Property with Percentage Values
To set the size of implicit rows, we can specify the size in percentage values (e.g. 10%, 20% etc.) which assign size as percent of the size of the container. All the implicitely created rows will thus be having the specified size. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { height: 300px; background-color: lightgray; padding: 10px; display: grid; grid-auto-rows: 40%; gap: 10px; } .grid-item { background-color: #336699; border: 3px solid blue; padding: 10px; text-align: center; color: white; } .item1 { grid-area: 1 / 1 / 2 / 2; } .item2 { grid-area: 1 / 2 / 2 / 3; } .item3 { grid-area: 1 / 3 / 2 / 4; } .item4 { grid-area: 2 / 1 / 3 / 2; } .item5 { grid-area: 2 / 2 / 3 / 3; } </style> </head> <body> <h2> CSS grid-auto-rows property </h2> <h4> grid-auto-rows: 40% (each row has 40% of the container's height) </h4> <div class="grid-container"> <div class="grid-item item1"> Item-1 </div> <div class="grid-item item2"> Item-2 </div> <div class="grid-item item3"> Item-3 </div> <div class="grid-item item4"> Item-4 </div> <div class="grid-item item5"> Item-5 </div> </div> </body> </html>
Grid Auto Rows Property with Max Content Value
To set the height of the row to be as tall as the maximum content it contains, we use the max-content value. This means the row will expand to fit its largest content item without any truncation or overflow. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { background-color: lightgray; padding: 10px; display: grid; grid-auto-rows: max-content; gap: 10px; } .grid-item { background-color: #336699; border: 3px solid blue; padding: 10px; text-align: center; color: white; } .item1 { grid-area: 1 / 1 / 2 / 2; } .item2 { grid-area: 1 / 2 / 2 / 3; } .item3 { grid-area: 1 / 3 / 2 / 4; } .item4 { grid-area: 2 / 1 / 3 / 2; } .item5 { grid-area: 2 / 2 / 3 / 3; } </style> </head> <body> <h2> CSS grid-auto-rows property </h2> <h4> grid-auto-rows: max-content (the height of the items in each row is determined by the longest sentence height in the row) </h4> <div class="grid-container"> <div class="grid-item item1"> This is the first Item </div> <div class="grid-item item2"> This is the second box in the grid layout and is being made longer to demonstrate the effect. </div> <div class="grid-item item3"> This is third box in the layout. </div> <div class="grid-item item4"> This is fourth box in the layout. </div> <div class="grid-item item5"> This is the fifth box in the grid layout. </div> </div> </body> </html>
Grid Auto Rows Property with Min Content Value
To set the row height to the minimum size needed to fit the content without overflowing, we use the min-content value. The row will be as short as possible while still ensuring that the content is fully visible and not cut off. This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { background-color: lightgray; padding: 10px; display: grid; grid-auto-rows: min-content; gap: 10px; } .grid-item { background-color: #336699; border: 3px solid blue; padding: 10px; text-align: center; color: white; } .item1 { grid-area: 1 / 1 / 2 / 2; } .item2 { grid-area: 1 / 2 / 2 / 3; } .item3 { grid-area: 1 / 3 / 2 / 4; } .item4 { grid-area: 2 / 1 / 3 / 2; } .item5 { grid-area: 2 / 2 / 3 / 3; } </style> </head> <body> <h2> CSS grid-auto-rows Property </h2> <h4> grid-auto-rows: min-content (The rows will be sized to fit the minimum height required by their content.) </h4> <div class="grid-container"> <div class="grid-item item1"> This is first item. </div> <div class="grid-item item2"> This is Second item. </div> <div class="grid-item item3"> This is third item </div> <div class="grid-item item4"> This is fourth </div> <div class="grid-item item5"> This is fifth </div> </div> </body> </html>
Grid Auto Rows Property with MinMax Function
To define a size range for the grid items, we use the minmax() function to specify the default minimum size of the item and the maximum attainable size of the item (e.g. minmax(50px,100px) indicates the initial size is 50px but the element can grow upto 100px). This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { background-color: lightgray; padding: 10px; display: grid; grid-auto-rows: minmax(40px, 87px); gap: 10px; } .grid-item { background-color: #336699; border: 3px solid blue; padding: 10px; text-align: center; color: white; } .item1 { grid-area: 1 / 1 / 2 / 2; } .item2 { grid-area: 1 / 2 / 2 / 3; } .item3 { grid-area: 1 / 3 / 2 / 4; } .item4 { grid-area: 2 / 1 / 3 / 2; } .item5 { grid-area: 2 / 2 / 3 / 3; } </style> </head> <body> <h2> CSS grid-auto-rows property </h2> <h4> grid-auto-rows: minmax(40px, 87px) (the initial height of the items is 40px and maximum attainable height is 87px) </h4> <div class="grid-container"> <div class="grid-item item1"> This is the first Item1 </div> <div class="grid-item item2"> This is the second box in the grid layout and is being made longer to demonstrate the effect. </div> <div class="grid-item item3"> This is third box in the layout. </div> <div class="grid-item item4"> This is fourth box in the layout. </div> <div class="grid-item item5"> This is the fifth box in the grid layout. </div> </div> </body> </html>
Grid Auto Rows Property with Fit Content Function
To set a row height that fits its content but within a specified maximum size (e.g. fit-content(200px) means the row will be as tall as needed to fit the content but will not exceed 200 pixels). This is shown in the following example.
Example
<!DOCTYPE html> <html> <head> <style> .grid-container { background-color: lightgray; padding: 10px; display: grid; grid-auto-rows: fit-content(50px); gap: 10px; } .grid-item { background-color: #336699; border: 3px solid blue; padding: 10px; text-align: center; color: white; } .item1 { grid-area: 1 / 1 / 2 / 2; } .item2 { grid-area: 1 / 2 / 2 / 3; } .item3 { grid-area: 1 / 3 / 2 / 4; } .item4 { grid-area: 2 / 1 / 3 / 2; } .item5 { grid-area: 2 / 2 / 3 / 3; } </style> </head> <body> <h2> CSS grid-auto-rows Property </h2> <h4> grid-auto-rows: fit-content (The rows will have a maximum height of 50px) </h4> <div class="grid-container"> <div class="grid-item item1"> This is first item. </div> <div class="grid-item item2"> This is Second item . </div> <div class="grid-item item3"> This is third item </div> <div class="grid-item item4"> This is fourth </div> <div class="grid-item item5"> This is fifth </div> </div> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
grid-auto-rows | 57 | 16 | 52 | 10 | 44 |