Skip to main content

Naming Grid Items with grid-area

Grid areas take their names from two properties working together. On a grid item, grid-area assigns a name; on the grid container, grid-template-areas uses those names to define areas within the layout.

Inside that value, each row is written between its own pair of apostrophes, with the named items listed and separated by spaces. A second set of apostrophes therefore adds a second row.

A grid item with no name is represented by a period sign (.).

Spanning five columns

Naming item1 "myHeader" lets it span all five columns of a five-column grid layout.

Prompt
Create a CSS Grid layout with a container of 5 columns. Use grid-template-areas to name item1 as "myHeader" spanning all five columns. Display 6 numbered grid items with item1 at the top spanning the full width.
Output: complete HTML page

Period sign for unnamed items

In this five-column grid layout, "myHeader" spans three columns, and period signs stand for items with no name.

Prompt
Create a CSS Grid layout with 5 columns. Use grid-template-areas where "myHeader" spans the first three columns and the last two columns use a period sign (.) for unnamed items. Display 6 numbered grid items.
Output: complete HTML page

Spanning columns and rows

Here "myHeader" covers two columns and two rows of the grid.

Prompt
Create a CSS Grid layout with 5 columns and use grid-template-areas with two rows where "myHeader" spans two columns and two rows. Use period signs for unnamed cells. Display 6 numbered grid items.
Output: complete HTML page

Make a ready-to-use Webpage Template

Give every grid item a name, and grid-template-areas can describe a complete webpage layout template for you.

Example

A ready-to-use webpage template, built by naming every grid item, with header, menu, main, right, and footer areas.

Prompt
Create a CSS Grid webpage template with named areas: header (top row, full width), menu (left column rows 2-3), main (center of row 2), right (right column row 2), and footer (bottom row spanning from column 2). Use grid-template-areas to define the layout with 6 columns.
Output: complete HTML page