It is a CSS property that offers a grid-based layout system, with rows and columns, making it easier to design web pages without floats and positioning.

Syntax:
grid: none|grid-template-rows / grid-template-columns|grid-template-areas| grid-template-rows / [grid-auto-flow] grid-auto-columns|[grid-auto-flow] grid-auto-rows / grid-template-columns|initial|inherit;
Property values:
| Value | Description |
|---|---|
| none | It is default value no specific size mentioned for row and column. |
| grid-template-rows / grid-template-columns | It is used to sepcifie the size of rows and columns. |
| grid-template-areas | It is used to specifie the grid layout using named items. |
| grid-template-rows / grid-auto-columns | It is used to specifie the auto size(height) and sets the auto size columns. |
| grid-auto-rows / grid-template-columns | It is used to specifie the auto size and sets the auto grid size columns. |
| grid-template-rows / grid-auto-flow grid-auto-columns | It is used to specifie how to place items and auto size row and columns. |
| grid-auto-flow grid-auto-rows / grid-template-columns | It is used to specifie how to place items and auto size row and grid-template columns. |
Example 1: Grid with 2-rows and 4-column.
<!DOCTYPE html> <html> <head> <title> CSS | grid Property </title> <style> .main { display: grid; grid: auto auto / auto auto auto auto; grid-gap: 10px; background-color: green; padding: 10px; } .gfg { background-color: lightgrey; text-align: center; padding: 25px 0; font-size: 30px; } </style> </head> <body> <h1>Welcome to GFG </h1> <h3>This tutorial is on CSS grid property</h3> <div class="main"> <div class="gfg">1</div> <div class="gfg">2</div> <div class="gfg">3</div> <div class="gfg">4</div> <div class="gfg">5</div> <div class="gfg">6</div> <div class="gfg">7</div> <div class="gfg">8</div> </div> </body> </html> |
Output :

This can be used as a shorthand property for :
- grid-template-rows : Specifies the size of the rows.
- grid-template-columns : This specifies the size of the columns.
- grid-template-areas : This specifies the grid layout using named items.
- grid-auto-rows : This specifies the auto size of the rows.
- grid-auto-columns : This specifies the auto size of the columns.
- grid-auto-flow : This specifies how to place auto-placed items, and the auto size of the row.
Example 2: This is example for the grid-template-rows and grid-template-columns.
<!DOCTYPE html> <html> <head> <title> CSS | grid Property </title> <style> .main { display: grid; grid-template-columns: 156px 156px 156px 156px; grid-template-rows: 100px 200px; grid-gap: 5px; background-color: green; padding: 5px; } .gfg { background-color: lightgrey; text-align: center; padding: 20px 0; font-size: 30px; } </style> </head> <body> <h1>Welcome to GFG </h1> <h3>This tutorial is on CSS grid property</h3> <div class="main"> <div class="gfg">1</div> <div class="gfg">2</div> <div class="gfg">3</div> <div class="gfg">4</div> <div class="gfg">5</div> <div class="gfg">6</div> <div class="gfg">7</div> <div class="gfg">8</div> </div> </body> </html> |
Output :
Height of the first row is set to 100px and height of the second row is set to 200px and width of every column is set to 156px.

Supported Browsers: The browser supported by CSS | grid Property are listed below:
- Google Chrome
- Internet Explorer
- Firefox
- Opera
- Safari
Recommended Posts:
- CSS | grid-template-columns Property
- CSS | grid-column-start Property
- CSS | grid-row-gap Property
- CSS | grid-column-gap Property
- CSS | grid-row Property
- CSS | grid-gap Property
- CSS | grid-row-end Property
- CSS | grid-column-end Property
- CSS | grid-template-rows Property
- CSS | grid-template Property
- CSS | grid-area Property
- CSS | grid-column Property
- CSS | grid-auto-flow Property
- CSS | grid-row-start Property
- CSS | grid-auto-columns Property
- CSS | grid-auto-rows Property
- CSS | grid-template-areas Property
- CSS | Grid Layout Module
- CSS | Grid Inspector
- Creating Responsive Grid Vanilla using HTML,CSS and Bootstrap
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

