Grid Container


1

2

3

4

5

6

7

8


Grid Container

To turn an HTML element into a grid container, you need to change the display property to either grid or inline-grid.

Grid containers are made up of grid items that are put into columns and rows.


The grid-template-columns Property

The grid-template-columns property determines how many columns your grid layout has, and it can also specify the width of each column.

The value is a list of words separated by spaces. Each word in the list tells us how wide a column should be

If you want your grid design to have 4 columns, you can set the width of these columns individually, or simply use auto if you want all columns to be the same width.

Important: If you have more than 4 items in a grid with 4 columns, the grid will automatically create a new row to accommodate the extra items.

You can use the grid-template-columns property to set the width of columns in a grid.


The grid-template-rows Property

The grid-template-rows property sets how tall each row is in a grid.

1

2

3

4

5

6

7

8

The value is a list of words separated by spaces. Each word in the list tells us how tall a row should be.


The justify-content Property

The justify-content property is employed to position the entire grid within the container, maintaining its width and height as specified.

1

2

3

4

5

6


The align-content Property

The align-content property helps position the entire grid vertically within its container.

1

2

3

4

5

6

Important: The combined height of the grid must be smaller than the container's height for the align-content property to work.