CSS Grid Layout

You are Here:

Demo

This demo is an overview of most of the CSS grid properties. Learn all CSS grid property one by one displayed under 'CSS grid' heading on the left side menu.

Header
Left side Menu
Page Content
Advertisement
Footer

What is grid layout?

CSS grid layout is used to divide a page into major regions (rows and colums) of our choice.

Like tables, grid layout enables an author to align elements into columns and rows. However, the grid layout provides more flexibility and control over tables.

In the following example, we will customize the grid layout to look like a webpage.

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <head> <style> #outerdiv{ display: grid; grid: 90px/ auto auto auto; background-color: #cccccc; } #outerDiv div{ border: 1px solid #267326; padding: 25px; background: #339933; color: #fff; margin: 8px; text-align: center; } #outerDiv div:nth-child(1){ grid-column: 1 / span 3; } #outerDiv div:nth-child(2){ background: #cc6600; grid-row: 2 / span 3; } #outerDiv div:nth-child(3){ background: #ff1a1a; grid-row: 2 / span 2; } #outerDiv div:nth-child(4){ background: #008ae6; grid-row: 3 / span 1; } #outerDiv div:nth-child(5){ background: #b31aff; grid-area: 4 / 2 / span 1 / span 2; } </style> </head> <body> <div id="outerDiv"> <div>Header</div> <div>Left side Menu</div> <div>Page Content</div> <div>Advertisement</div> <div>Footer</div> </div> </body> </html>

CSS grid Properties (for parents)

The following table provides a list of CSS properties to control all the grid items in a grid container.

PropertyExplanation
displayWill treat a container (<div>) as grid.
grid-template-rowsSpecifies the height of rows in a grid layout.
grid-template-columnsSpecifies the width of columns in a grid layout.
grid-template-areasSpecifies areas within the grid layout.
grid-templateA shorthand property for
grid-auto-rowsSpecifies a size for the rows in a grid container.
grid-auto-columnsSpecifies a size for the columns in a grid container.
grid-auto-flowSpecifying exactly how auto-placed items get flowed into the grid.
gridA shorthand property for .
grid-row-gapSpecifies the size of the gap between the rows in a grid layout.
grid-column-gapSpecifies the size of the gap between the columns in a grid layout.
grid-gapSpecifies the gaps (gutters) between rows and columns.

CSS grid Properties (for children)

The following table provides a list of CSS properties to control a specific grid item in a grid container.

PropertyExplanation
grid-row-startSpecifies on which row-line the item will start.
grid-column-startSpecifies on which column-line the item will start.
grid-row-endSpecifies on which row-line the item will end.
grid-column-endSpecifies on which column-line the item will end.
grid-rowA shorthand property for
grid-columnA shorthand property for
grid-areaA shorthand property for

Reminder

Hi Developers, we almost covered 98.7% of CSS Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in CSS.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author