Bird
Raised Fist0
CSSmarkup~10 mins

Grid template areas in CSS - Browser Rendering Trace

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Render Flow - Grid template areas
Parse CSS Grid Container
Identify grid-template-areas
Create named grid areas
Assign grid items to areas
Calculate grid tracks
Place items according to areas
Paint grid and items
Composite final layout
The browser reads the grid container's CSS, creates named areas from the template, assigns items to these areas, calculates the grid layout, and then paints the items in their correct positions.
Render Steps - 4 Steps
Code Added:display: grid;
Before
[grid-container]
  [header]
  [sidebar]
  [content]
  [footer]
After
[grid-container: grid]
  [header]
  [sidebar]
  [content]
  [footer]
Turning the container into a grid enables grid layout but items still stack by default.
🔧 Browser Action:Creates grid formatting context, triggers reflow
Code Sample
A grid layout with named areas places header spanning two columns on top, sidebar and content side by side in the middle, and footer spanning two columns at the bottom.
CSS
<div class="grid-container">
  <div class="header">Header</div>
  <div class="sidebar">Sidebar</div>
  <div class="content">Content</div>
  <div class="footer">Footer</div>
</div>
CSS
.grid-container {
  display: grid;
  grid-template-areas: 
    "header header"
    "sidebar content"
    "footer footer";
  grid-template-columns: 1fr 3fr;
  grid-template-rows: auto 1fr auto;
  gap: 0.5rem;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.content { grid-area: content; }
.footer { grid-area: footer; }
Render Quiz - 3 Questions
Test your understanding
After applying step 2, what does the grid layout visually show?
AA single column stack of all items
BA 3-row by 2-column grid with named areas arranged as header spanning top row, sidebar and content side by side in middle, footer spanning bottom row
CA 2-row by 3-column grid with header on left
DItems overlapping each other in one cell
Common Confusions - 2 Topics
Why do my grid items not appear in the right places even though I set grid-template-areas?
You must assign the matching grid-area name to each grid item. Without grid-area on the children, they won't move to the named areas defined.
💡 Always pair grid-template-areas with grid-area on children to see the layout from step 4.
Why does the grid have empty space or unexpected gaps?
If your grid-template-areas strings don't cover all columns or rows fully, or if you have gaps set, space appears. Also, missing area names or dots (.) create empty cells.
💡 Use dots (.) in grid-template-areas to mark empty cells and check your area strings cover all columns.
Property Reference
PropertyValue AppliedAxis/DirectionVisual EffectCommon Use
displaygridN/ACreates grid container for layoutEnable grid layout
grid-template-areas"header header" "sidebar content" "footer footer"2D gridDefines named areas for grid placementSemantic layout naming
grid-template-columns1fr 3frHorizontalSets column widths proportionallyControl column sizes
grid-template-rowsauto 1fr autoVerticalSets row heights with flexible middle rowControl row sizes
grid-areaheader, sidebar, content, footerN/AAssigns grid items to named areasPlace items in grid
Concept Snapshot
Grid template areas let you name parts of a grid layout. Use grid-template-areas on the container to define the layout shape. Assign grid-area names to children to place them in those areas. Set grid-template-columns and rows to control sizes. This creates clear, semantic, and easy-to-read grid layouts.

Practice

(1/5)
1. What does the grid-template-areas property do in CSS Grid?
easy
A. It names areas of the grid to place items easily.
B. It sets the colors of grid cells.
C. It defines the size of grid gaps.
D. It controls the font size inside grid items.

Solution

  1. Step 1: Understand the purpose of grid-template-areas

    This property lets you assign names to parts of the grid layout, making it easier to place items by referring to those names.
  2. Step 2: Compare with other grid properties

    Other properties like gap or font size do not name areas; they control spacing or style, so they are not correct here.
  3. Final Answer:

    It names areas of the grid to place items easily. -> Option A
  4. Quick Check:

    grid-template-areas = names grid parts [OK]
Hint: Remember: areas = named parts of grid layout [OK]
Common Mistakes:
  • Confusing grid-template-areas with grid-gap
  • Thinking it sets colors or fonts
  • Mixing it up with grid-template-columns
2. Which of the following is the correct syntax for defining grid-template-areas with two rows and three columns?
easy
A. grid-template-areas: ['header' 'header' 'header'] ['main' 'main' 'sidebar'];
B. grid-template-areas: header header header; main main sidebar;
C. grid-template-areas: "header header header" "main main sidebar";
D. grid-template-areas: ("header header header", "main main sidebar");

Solution

  1. Step 1: Check the syntax format

    The correct syntax uses quoted strings for each row, separated by spaces for columns, all inside the property value.
  2. Step 2: Identify correct quotes and separators

    grid-template-areas: "header header header" "main main sidebar"; uses double quotes around each row and spaces between area names, which is correct. Other options use incorrect brackets or missing quotes.
  3. Final Answer:

    grid-template-areas: "header header header" "main main sidebar"; -> Option C
  4. Quick Check:

    Quotes per row, spaces per column [OK]
Hint: Use quotes for each row, spaces for columns [OK]
Common Mistakes:
  • Omitting quotes around rows
  • Using brackets instead of quotes
  • Separating rows with commas or semicolons incorrectly
3. Given this CSS:
  .container {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    grid-template-areas:
      "nav nav nav"
      "sidebar main main";
  }
  .nav { grid-area: nav; }
  .sidebar { grid-area: sidebar; }
  .main { grid-area: main; }
What will be the layout of the grid areas?
medium
A. The nav, sidebar, and main all overlap in the first row.
B. The nav is only in the first column; sidebar and main share the second row equally.
C. The nav is in the last column; sidebar spans all columns in second row.
D. The nav spans all three columns in the first row; sidebar is left in second row; main spans two columns on right in second row.

Solution

  1. Step 1: Analyze grid-template-areas rows

    The first row is "nav nav nav", so nav covers all three columns in row one. The second row is "sidebar main main", so sidebar is in first column, main spans second and third columns.
  2. Step 2: Match grid-area assignments

    Each class uses grid-area matching the names in template areas, so items appear in those named spots.
  3. Final Answer:

    The nav spans all three columns in the first row; sidebar is left in second row; main spans two columns on right in second row. -> Option D
  4. Quick Check:

    Named areas match layout positions [OK]
Hint: Repeat area names in quotes to span columns [OK]
Common Mistakes:
  • Assuming nav only covers one column
  • Mixing up row and column spans
  • Ignoring repeated area names for spanning
4. Identify the error in this CSS snippet:
  .container {
    display: grid;
    grid-template-areas:
      "header header header"
      "content sidebar";
  }
  .header { grid-area: header; }
  .content { grid-area: content; }
  .sidebar { grid-area: sidebar; }
medium
A. The grid-template-areas rows have different numbers of columns.
B. Missing grid-template-columns property.
C. The grid-area names do not match the template areas.
D. Using double quotes instead of single quotes.

Solution

  1. Step 1: Count columns in each grid-template-areas row

    The first row "header header header" has 3 area names (columns). The second row "content sidebar" has 2 area names. Mismatch!
  2. Step 2: Verify the rule

    All rows in grid-template-areas must have the same number of area names to define consistent columns.
  3. Step 3: Check other options

    B: grid-template-columns is implicitly created by areas. C: Names match exactly. D: Double quotes are valid.
  4. Final Answer:

    The grid-template-areas rows have different numbers of columns. -> Option A
  5. Quick Check:

    Same # areas per row [OK]
Hint: Every row must have identical number of area names [OK]
Common Mistakes:
  • Assuming rows have same columns without counting
  • Thinking missing grid-template-columns is the error
  • Believing quote type causes issues
5. You want a grid layout with three rows and three columns. The top row is a header spanning all columns. The middle row has a sidebar on the left and main content spanning the other two columns. The bottom row is a footer spanning all columns. Which grid-template-areas value correctly defines this layout?
hard
A. "header sidebar main" "header sidebar main" "footer footer footer"
B. "header header header" "sidebar main main" "footer footer footer"
C. "header header header" "main main sidebar" "footer footer footer"
D. "header header" "sidebar main main" "footer footer footer"

Solution

  1. Step 1: Understand the layout requirements

    Top row: header spans all 3 columns. Middle row: sidebar left (1 column), main content spans 2 columns on right. Bottom row: footer spans all 3 columns.
  2. Step 2: Match the grid-template-areas string

    "header header header" "sidebar main main" "footer footer footer" matches exactly: first row "header header header" (3 columns), second row "sidebar main main" (sidebar left, main spans 2 columns), third row "footer footer footer" (footer spans all columns).
  3. Step 3: Check other options for errors

    "header sidebar main" "header sidebar main" "footer footer footer" splits header and sidebar in first row, which is wrong. "header header header" "main main sidebar" "footer footer footer" swaps main and sidebar positions. "header header" "sidebar main main" "footer footer footer" has only 2 columns in first row, inconsistent with 3 columns.
  4. Final Answer:

    "header header header" "sidebar main main" "footer footer footer" -> Option B
  5. Quick Check:

    Repeat area names to span columns correctly [OK]
Hint: Repeat area names in quotes to span columns properly [OK]
Common Mistakes:
  • Mismatching number of columns per row
  • Swapping sidebar and main positions
  • Not repeating area names to span columns