CHAPTER 74

CSS Grid Layout

Learn how CSS Grid can create complete website layouts with header, sidebar, main content and footer.

01. What is CSS Grid Layout?

CSS Grid can organize an entire page into structured areas.
grid-template-areas gives names to layout regions.
This can make complex layouts easier to understand.

02. Syntax

.page { display: grid; grid-template-areas: "header header" "sidebar main" "footer footer"; }

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>

.page {
    display: grid;

    grid-template-columns: 220px 1fr;

    grid-template-areas:
        "header header"
        "sidebar main"
        "footer footer";

    min-height: 500px;
}

header {
    grid-area: header;
    background: #020617;
    color: white;
    padding: 20px;
}

aside {
    grid-area: sidebar;
    background: #dbeafe;
    padding: 20px;
}

main {
    grid-area: main;
    padding: 20px;
}

footer {
    grid-area: footer;
    background: #020617;
    color: white;
    padding: 20px;
}

</style>
</head>

<body>

<div class="page">

    <header>Header</header>

    <aside>Sidebar</aside>

    <main>Main Content</main>

    <footer>Footer</footer>

</div>

</body>
</html>

04. Important Points

✓ grid-template-areas names page regions.
✓ grid-area assigns an element to a named region.
✓ Grid can create clear page structures.
✓ Media queries can change the areas on mobile.

05. Common Mistakes

⚠ Using inconsistent area names.
⚠ Creating invalid grid area patterns.
⚠ Forgetting mobile layout changes.

06. Real World Use

Grid layouts are useful for education portals, dashboards, admin systems, blogs and business websites.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create a Full Website Layout

Build a page with header, sidebar, main content and footer using grid-template-areas.