Grid Template Areas Named Layout
Create a named grid layout using template areas for an app shell with header, sidebar, main, and footer regions.
Code
.app-shell {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
grid-template-columns: 240px 1fr;
grid-template-rows: auto 1fr auto;
min-height: 100vh;
gap: 1rem;
}
.app-header { grid-area: header; }
.app-sidebar { grid-area: sidebar; }
.app-main { grid-area: main; }
.app-footer { grid-area: footer; }How the snippet works
display: grid owns the layout: tracks are declared on the container, so children fall into place without wrapper markup.
gap spaces grid/flex items without margins on the children.
grid-template-columns declares the column tracks the children flow into.
The rules target .app-shell, .app-sidebar, .app-main, .app-footer — each selector names the element it restyles, in source order.
Interactive Tools for This Topic
CSS Grid PlaygroundExperiment with CSS grid layout properties interactively. Define columns, rows, gaps, and areas while watching the grid template update in a live visual preview.CSS Flexbox PlaygroundInteractively test CSS flexbox container and item properties with a live preview. Adjust justify-content, align-items, flex-direction, and flex-grow to see layout changes.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
FAQ
- Which elements does this stylesheet target?
- The rules bind to `.app-shell`, `.app-sidebar`, `.app-main`, `.app-footer`; when two rules tie in specificity, the one written later in the file wins.
Report a problem with this exampleOpens a pre-filled issue on GitHub.