Building two-dimensional page layouts with CSS Grid — containers, tracks, fractional space, gaps, responsive sizing, and precise item placement
Chapter 15 introduced Flexbox as a one-dimensional layout system for rows and columns. Flexbox is excellent for navigation bars, card rows, centered content, and similar single-axis arrangements. But many layouts on the web are genuinely two-dimensional: they need rows and columns working together at the same time. CSS Grid is the layout system built for that job.
This chapter teaches CSS Grid from the ground up. You will learn how Grid containers and Grid items relate to each other, how to define rows and columns using tracks, how to use fractional units to distribute space proportionally, how to control gaps, and how to place items precisely within a Grid. You will also learn when to reach for Grid and when Flexbox is the better tool. By the end of this chapter, you will be able to build image galleries, page skeletons, dashboard cards, and multi-column content layouts using Grid — and you will understand how Grid and Flexbox complement each other in the same project.
Imagine a web page with a header at the top, a sidebar on one side, a main content area beside it, and a footer at the bottom — all positioned in relation to each other, not just stacked top to bottom. Flexbox can approximate this with effort, but it was designed to manage a single row or a single column at a time. What if a layout system could let you define rows and columns together, on one container, and then drop any element into any cell of that structure? That system is CSS Grid, and that is exactly what this chapter teaches you to build.
By the end of this chapter, you should be able to:
display: grid changes a page.grid-template-columns and grid-template-rows to define the structure of a grid.fr unit to distribute space proportionally between columns and rows.gap to control spacing between rows and columns without affecting outer spacing.repeat() and minmax() together to build responsive grids without writing media queries.grid-column, grid-row, line numbers, and the span keyword.grid-template-areas and grid-area.display: grid and misplaced properties.display: grid; how containers and items relate; the mental model of structure versus flowgrid-template-columnsDefining column tracks; fixed and mixed widths; building a three-column card gridgrid-template-rowsDefining explicit row heights; implicit rows; grid-auto-rows and minmax() for uniform cellsgap, row-gap, and column-gap; the difference between gap and paddingfr unit; equal and unequal proportions; mixing fixed and fractional units for sidebar layoutsrepeat() and minmax()Avoiding repetition; auto-fill for responsive column counts; the combined responsive gallery patternspan keyword; named grid areas with grid-template-areasBefore CSS Grid, developers built two-dimensional layouts using floats, tables repurposed as layout tools, and complicated hacks with absolute positioning. These approaches were fragile. A layout that worked in one browser often broke in another. Pages required deeply nested HTML just to create a column. Changing the layout meant rewriting large amounts of HTML.
Flexbox improved this situation significantly when it arrived. But Flexbox was designed to work along a single axis at a time. It does rows or columns, not rows and columns simultaneously. When designers needed true grid-based layouts — a page with a sidebar, main content, and footer all positioned in relation to each other — Flexbox required workarounds.
CSS Grid was designed specifically to solve two-dimensional layout. It lets you define both rows and columns on a single container, then place any child element into any cell in that grid. The HTML can stay clean. The layout logic moves into CSS where it belongs. Grid became fully supported across all major browsers starting around 2017 and is now one of the most important layout tools in CSS. Learning it is not optional for modern web development.
You will use both Grid and Flexbox in the same project. They are not competitors. They are tools for different problems, and this chapter will return to that distinction in Section 16.10.
Like Flexbox, CSS Grid is applied to a container element. The container becomes a Grid container. Its direct children automatically become Grid items. To make an element a Grid container, you apply one CSS property: display: grid.
<div class="gallery">
<div class="card">Card 1</div>
<div class="card">Card 2</div>
<div class="card">Card 3</div>
<div class="card">Card 4</div>
<div class="card">Card 5</div>
<div class="card">Card 6</div>
</div>
.gallery {
display: grid;
}
At this point, nothing visible has changed yet. The div.gallery is now a Grid container, and the six .card divs are Grid items. But without defining columns or rows, the browser stacks everything in a single column exactly as block elements normally would. The visual change comes when you define the structure of the grid, starting in Section 16.4.
The container defines structure. The items flow into it. The Grid container decides how many columns exist, how many rows exist, how large each track is, and how much space goes between items. Grid items respond to that structure. By default they flow into cells automatically from left to right and top to bottom, but you can also give individual items instructions about exactly where they should sit, as you will see in Section 16.9.
The building blocks of a CSS Grid are tracks. A track is a single row or a single column in the grid. When you define a grid, you are defining its tracks. The space between tracks is the gap. The intersections of rows and columns create cells. A rectangular area covering one or more cells is called a grid area.
Visualizing the grid is important. Imagine graph paper. The horizontal lines create rows. The vertical lines create columns. Each square on the paper is a cell. An item can occupy one cell or span multiple adjacent cells.
Grid also gives you access to grid lines — the dividing lines between tracks. They are numbered starting from 1. A three-column grid has four vertical grid lines: line 1 on the left edge, line 2 between the first and second columns, line 3 between the second and third columns, and line 4 on the right edge. Understanding grid lines becomes important when placing items explicitly in Section 16.9.
When you define columns and rows in your CSS, those are called explicit tracks. You have deliberately told the browser how many tracks to create and how large they should be.
When items overflow the explicit grid — meaning you defined three columns but have enough items to need more rows than you explicitly defined — the browser creates additional rows automatically. These are called implicit tracks. You can control the size of implicit tracks using the grid-auto-rows property, covered in Section 16.5. For most beginner layouts, thinking in terms of explicit tracks is enough.
grid-template-columnsThe grid-template-columns property defines how many columns the grid has and how wide each column should be. The value is a space-separated list of sizes. Each size you provide creates one column. Two sizes create a two-column grid. Four sizes create a four-column grid.
.gallery {
display: grid;
grid-template-columns: 200px 200px 200px;
}
This creates a three-column grid where each column is exactly 200 pixels wide. Items flow into the columns from left to right. When three items have filled the first row, the next item starts a new row automatically. You can use any CSS length unit for column sizes: px, em, rem, percentages, and the fractional unit fr (covered in Section 16.7).
Columns do not have to be the same size. A sidebar layout might use a wide main column and a narrower sidebar column:
.page-layout {
display: grid;
grid-template-columns: 200px 1fr;
}
This example uses two different units on purpose. The sidebar is 200 pixels fixed. The 1fr means the remaining space goes to the main content area. The fr unit is one of Grid's most powerful features and gets its own full section later in the chapter.
<article class="card"> elements live inside a <div class="card-grid">..card-grid { display: grid; grid-template-columns: 300px 300px 300px; }grid-template-rowsThe grid-template-rows property defines explicit row heights. It works the same way as grid-template-columns but controls horizontal tracks instead of vertical ones.
.dashboard {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-template-rows: 200px 400px;
}
This creates a three-column, two-row grid. The first row is 200 pixels tall. The second row is 400 pixels tall. In many practical layouts, you do not need to define row heights explicitly. If you do not define rows, the browser creates them implicitly as content overflows the explicit grid, and each row takes the height of its tallest item. This natural behavior is usually what you want.
grid-auto-rowsWhen the browser creates implicit rows automatically, you can control their default height with grid-auto-rows:
.card-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-auto-rows: 250px;
}
Now every automatically created row will be 250 pixels tall, giving the grid a uniform cell height regardless of how many rows the content requires. A more flexible approach uses minmax(), covered fully in Section 16.8:
.card-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-auto-rows: minmax(200px, auto);
}
This tells the browser: each row should be at least 200 pixels tall, but it can grow larger if the content inside it is taller. This is a very common pattern in gallery and card layouts.
Like Flexbox, CSS Grid uses the gap property to control the space between tracks. The gap appears between columns and between rows, but never on the outer edges of the grid.
.card-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 1.5rem;
}
This adds 1.5rem of space between every row and every column. If you need different horizontal and vertical spacing, you can provide two values. The first value controls the row gap; the second controls the column gap:
.card-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 2rem 1rem;
}
Here the rows have 2rem of space between them, and the columns have 1rem of space between them. You can also use the longhand properties row-gap and column-gap individually, though the shorthand gap is preferred for most use cases.
gap does not add space outside the grid itself. If you need space around the outside of the grid, use padding on the container: gap: 1.5rem; padding: 2rem; gives the cards breathing room between each other from gap, and breathing room around the whole grid from padding.
The fr unit is unique to CSS Grid. It stands for fraction of the available space. When you use fr units in grid-template-columns, the browser calculates how much space is left after fixed-size columns and gaps have been placed, then divides that remaining space among the fractional columns according to their proportions.
.gallery {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}
Three columns, each getting one-third of the total available space. If the container is 900 pixels wide, each column is 300 pixels wide. If the container is 600 pixels wide, each column is 200 pixels wide. The columns grow and shrink with the container automatically — already a significant improvement over writing 33.33% and dealing with rounding errors.
.layout {
display: grid;
grid-template-columns: 1fr 2fr 1fr;
}
The middle column gets twice as much space as each side column. In a 900-pixel container, the middle column is 450 pixels wide and each side column is 225 pixels wide. A common main-content-plus-sidebar proportion is grid-template-columns: 3fr 1fr; — the main content gets three-quarters of the available space, and the sidebar gets one-quarter.
.layout {
display: grid;
grid-template-columns: 250px 1fr;
}
One of the most powerful patterns in Grid is mixing px (or rem) with fr. The sidebar is always 250 pixels wide. The main content area fills all remaining space. This is a much cleaner way to write a classic sidebar layout than the float-based approaches of the past. When the browser calculates the 1fr, it first subtracts the 250 pixels of the fixed column (and any gaps) from the total container width, then assigns the remainder to the 1fr column.
repeat() and minmax() at an Introductory LevelTwo CSS Grid functions are worth learning early because they appear in nearly every real project: repeat() and minmax().
repeat()The repeat() function lets you avoid writing the same track size multiple times. Instead of writing grid-template-columns: 1fr 1fr 1fr 1fr;, you write:
grid-template-columns: repeat(4, 1fr);
The first argument to repeat() is the number of times to repeat. The second argument is the track size (or sizes) to repeat. These produce an equivalent four-column equal-width grid. repeat() becomes especially useful with the auto-fill keyword, which allows the browser to create as many columns as will fit in the container:
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, 250px);
gap: 1.5rem;
}
With auto-fill, the browser creates as many 250px columns as will fit in the available space and wraps excess items to new rows. This creates a naturally responsive gallery without media queries — if the viewport is wide, you get many columns; if it is narrow, you get fewer. The difference between auto-fill and auto-fit is subtle and involves how empty space is handled at the end of a row. For most beginners, auto-fill is the safer default.
minmax()The minmax() function defines a size range for a track. It takes two arguments: a minimum size and a maximum size.
.gallery {
display: grid;
grid-template-columns: repeat(3, minmax(200px, 1fr));
gap: 1.5rem;
}
Each column is at least 200 pixels wide but will grow up to an equal share of available space (1fr). This prevents columns from collapsing to an unreadably narrow width while still allowing them to expand naturally. A very common professional pattern combines auto-fill with minmax():
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
gap: 1.5rem;
}
Create as many columns as will fit, where each column is at least 250 pixels wide but can grow to fill equal shares of available space. This single line creates a fully responsive card grid that adjusts its number of columns based on viewport width with no media queries needed. You will use this pattern often — it appears again in the Mini-Project at the end of this chapter.
By default, Grid items flow automatically into the grid from left to right and top to bottom, filling each cell in order. This automatic placement is called auto-placement and is exactly what you want for galleries, card grids, and other uniform layouts. But Grid also allows you to place items explicitly into specific positions. This is what makes Grid so powerful for page-level layouts.
Every Grid container has numbered lines. For columns, line 1 is the left edge. For rows, line 1 is the top edge. The last line number is one more than the number of tracks. A three-column grid has vertical lines 1, 2, 3, and 4. A two-row grid has horizontal lines 1, 2, and 3.
You can tell a Grid item where to start and end using these line numbers:
.item {
grid-column: 1 / 3;
grid-row: 1 / 2;
}
This places the item starting at column line 1 and ending at column line 3 — meaning it spans two columns. It starts at row line 1 and ends at row line 2 — meaning it occupies the first row.
span KeywordInstead of specifying end line numbers, you can use the span keyword to indicate how many tracks an item should cross:
.featured {
grid-column: span 2;
}
This tells the featured item to span two columns, starting wherever the auto-placement algorithm puts it.
Consider a simple page where you want a header that spans the full width, a main content area, and a sidebar:
.page {
display: grid;
grid-template-columns: 1fr 300px;
grid-template-rows: auto 1fr auto;
gap: 1.5rem;
min-height: 100vh;
}
.site-header {
grid-column: 1 / 3;
}
.site-footer {
grid-column: 1 / 3;
}
The header and footer span both columns using grid-column: 1 / 3. The main content and sidebar each occupy one column in the middle row, placed there automatically by the browser. This pattern — a two-column layout with a full-width header and footer — is one of the most common page structures on the web, and Grid makes it straightforward.
Grid also allows you to name areas and assign items to those names, which many developers find easier to read than line numbers:
.page {
display: grid;
grid-template-columns: 1fr 300px;
grid-template-areas:
"header header"
"content sidebar"
"footer footer";
gap: 1.5rem;
}
.site-header { grid-area: header; }
.main-content { grid-area: content; }
.sidebar { grid-area: sidebar; }
.site-footer { grid-area: footer; }
The grid-template-areas property uses quoted strings where each string represents a row. Each word in the string represents a column. When the same name appears in multiple cells, the item stretches across those cells. A period . represents an empty cell. Named grid areas make layout intentions explicit and readable — particularly helpful in large projects where the layout code needs to be easy to understand weeks or months later.
Now you will put these concepts together into a realistic full-page layout. This example builds the core skeleton of the Student Learning Site's main layout: a full-width site header, a full-width navigation below it, a main content area on the left, a 280-pixel sidebar on the right, and a full-width footer.
<div class="page-wrapper">
<header class="site-header">
<p class="site-name">Student Learning Site</p>
</header>
<nav class="site-nav">
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>
<li><a href="lessons.html" aria-current="page">Lessons</a></li>
<li><a href="resources.html">Resources</a></li>
<li><a href="contact.html">Contact</a></li>
</ul>
</nav>
<main class="main-content">
<h1>Lessons</h1>
<p>Browse the lessons below to begin learning.</p>
<div class="lesson-grid">
<article class="lesson-card">
<h2>Lesson 1: HTML Foundations</h2>
<p>Learn how HTML gives structure to web pages.</p>
</article>
<article class="lesson-card">
<h2>Lesson 2: CSS Basics</h2>
<p>Learn how CSS controls visual presentation.</p>
</article>
<article class="lesson-card">
<h2>Lesson 3: CSS Layout</h2>
<p>Learn Flexbox, Grid, and responsive design.</p>
</article>
</div>
</main>
<aside class="sidebar">
<h2>Quick Links</h2>
<ul>
<li><a href="#">Getting Started Guide</a></li>
<li><a href="#">HTML Cheat Sheet</a></li>
</ul>
</aside>
<footer class="site-footer">
<p>© 2025 Student Learning Site. All rights reserved.</p>
</footer>
</div>
.page-wrapper {
display: grid;
grid-template-columns: 1fr 280px;
grid-template-areas:
"header header"
"nav nav"
"content sidebar"
"footer footer";
gap: 2rem;
max-width: 1100px;
margin: 0 auto;
padding: 0 2rem;
}
.site-header { grid-area: header; }
.site-nav { grid-area: nav; }
.main-content { grid-area: content; }
.sidebar { grid-area: sidebar; }
.site-footer { grid-area: footer; }
.site-nav ul {
display: flex;
gap: 1.25rem;
list-style: none;
}
.lesson-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
gap: 1.25rem;
}
.sidebar {
align-self: start;
}
Walk through the important decisions in this code. The .page-wrapper is the Grid container. It has two columns: the main content area gets 1fr (all available space), and the sidebar gets a fixed 280px. The grid-template-areas property names four rows of layout. The header and nav each span both columns. The content and sidebar sit side by side in the middle row. The footer spans both columns again at the bottom. Each semantic element then receives its grid-area assignment in a clean, readable block.
Notice that the .lesson-grid inside the main content is itself a second Grid using repeat(auto-fill, minmax(240px, 1fr)). This is a nested Grid. The outer Grid controls the overall page structure. The inner Grid controls the lesson card layout. Nesting Grid inside Grid is normal and common.
The sidebar uses align-self: start so it does not stretch to match the full height of the main content column. Without this, the sidebar would expand to fill all available vertical space. align-self: start keeps it flush with the top.
Both Grid and Flexbox are essential. Knowing which to use comes with practice, but here are reliable starting rules.
margin-left: auto)A page built with Grid for its overall layout can have a Flexbox navigation inside the header, Flexbox buttons inside each card, and a Flexbox-centered footer. They solve different problems and work well together — exactly as shown in the page layout example above, where the outer structure is Grid and the .site-nav ul is Flexbox.
display: gridYou can write grid-template-columns and nothing will happen unless you have also applied display: grid to the container. Always verify the container has the Grid context.
grid-template-columns and grid-template-rows go on the container. Properties like grid-column and grid-row go on individual items. Mixing these up is a very common early mistake. If columns are not forming, check whether your properties are on the right element.
A grid with no gap will have items sitting directly against each other with no breathing room. Always add gap to avoid cramped layouts. Even gap: 1rem makes a significant visual difference.
fr Would Be BetterIf you write grid-template-columns: 300px 300px 300px;, the grid will overflow its container on narrow screens. Using 1fr 1fr 1fr or repeat(3, 1fr) instead allows columns to shrink proportionally. Use fixed pixel sizes only when you specifically need a column to remain a constant width.
Grid places items into cells, but it does not center them within those cells by default. To center content inside a grid item, use display: flex; align-items: center; justify-content: center; on the item itself, or use place-items: center on the grid container to center all items in their cells.
If you define named areas in grid-template-areas but forget to assign the corresponding grid-area property to an element, that element will fall outside the named layout and cause unexpected visual results. Make sure every named area has a matching grid-area assignment on the correct HTML element.
Browser developer tools have excellent Grid debugging features. When you inspect a Grid container in the Elements panel, Firefox shows an overlay with column and row numbers drawn directly on the page, including gaps and track sizes — the most detailed Grid debugger available in any browser. Chrome and Edge show a Grid badge next to Grid containers in the Elements panel; clicking the badge toggles a visual overlay showing the grid lines.
display: grid, whether track sizes make sense, and whether items are placed on the correct grid lines or areas.Using the Grid overlay in Firefox for a complicated layout is one of the most productive debugging actions you can take. It shows you immediately whether your CSS is creating the structure you intended.
display: grid turns an element into a Grid container; its direct children automatically become Grid items. The container defines structure; items flow into it by default.grid-template-columns defines the number and width of columns. Mixing fixed units with flexible ones (like 200px 1fr) is a foundational sidebar pattern.grid-template-rows defines explicit row heights. grid-auto-rows, often combined with minmax(), controls the height of automatically created implicit rows.gap controls space between tracks only — never on the outer edge of the grid. Use padding on the container for outer spacing.fr unit distributes remaining space proportionally after fixed-size tracks and gaps are subtracted. It enables equal columns, unequal proportions, and flexible sidebar layouts without percentage math.repeat() avoids repeating track sizes manually. Combined with auto-fill and minmax(), it creates fully responsive galleries with no media queries.grid-column and grid-row using line numbers or span. Named areas via grid-template-areas and grid-area make page layout code more readable.display: grid applied. It defines the grid structure.grid-template-columns or grid-template-rows.grid-template-columnsgrid-template-rowsgrid-auto-rowsgapfr unitfr represents a share of the remaining available space.repeat()auto-fill and auto-fit.minmax()auto-fillrepeat() that tells the browser to create as many tracks as will fit in the container.grid-columngrid-rowspangrid-column or grid-row to indicate how many tracks an item should cross.grid-template-areasgrid-areagrid-template-areas.align-self: startAnswer these questions before beginning the full review questions. They check basic understanding, not deep analysis.
display: grid do to an element and its direct children?fr unit represent, and why is it different from a fixed unit like px?gap and padding on a Grid container?repeat(auto-fill, minmax(250px, 1fr)) solve without needing a media query?Study each example carefully. Before looking at the questions, trace through the code and describe what you expect to see.
.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 1rem;
}
<div class="container">
<div>A</div>
<div>B</div>
<div>C</div>
<div>D</div>
<div>E</div>
<div>F</div>
</div>
1fr 1fr 1fr 1fr mean in terms of width?.layout {
display: grid;
grid-template-columns: 200px 1fr;
grid-template-areas:
"header header"
"sidebar content"
"footer footer";
gap: 1.5rem;
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.content { grid-area: content; }
.footer { grid-area: footer; }
grid-area: header from the .header rule?.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
gap: 1.25rem;
}
For each exercise, draw or describe the grid structure. Label the rows, columns, tracks, and gaps.
display: grid;
grid-template-columns: 1fr 2fr 1fr;
gap: 20px;
Describe how wide each column is. (Hint: 900px minus two 20px gaps leaves 860px to distribute. The first 1fr gets one-quarter, the 2fr gets two-quarters, the last 1fr gets one-quarter.)
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-auto-rows: 180px;
gap: 1rem;
How many rows form? How tall is each row?
.page {
display: grid;
grid-template-columns: 1fr 250px;
grid-template-areas:
"header header"
"main aside"
"main aside"
"footer footer";
}
Describe the visual layout produced. Which elements are wide? Which are narrow? How does the main content compare in height to the aside?
For each scenario, decide whether Flexbox or Grid is the better choice. Explain your reasoning.
Each example below has a problem. Identify the mistake and write a corrected version.
.card {
grid-template-columns: 1fr 1fr 1fr;
gap: 1rem;
}
There are six child elements inside .card but they are not forming a three-column grid. What is missing?
.page {
display: grid;
grid-template-columns: 250px 1fr;
grid-template-areas:
"nav nav"
"sidebar main"
"footer footer";
}
.sidebar { grid-area: sidebar; }
.main-content { grid-area: main-content; }
.site-nav { grid-area: nav; }
.site-footer { grid-area: footer; }
The main content area is not appearing in the correct grid area. What is the problem?
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, 200px);
gap: 1rem;
}
On a wide screen the gallery looks fine. On a narrow mobile screen, cards overflow outside the container. Which change would fix this without adding media queries?
.layout {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-areas:
"header sidebar"
"main sidebar"
"footer footer";
}
.header { grid-area: header; }
.sidebar { grid-area: sidebar; }
.main { grid-area: main; }
.footer { grid-area: footer; }
A student wants the header to span both columns. The grid-template-areas declaration shows "header sidebar" in the first row, meaning the header only takes one column. How should grid-template-areas be changed so the header spans both columns?
Complete each task in a code editor. Test in the browser before moving on.
<article> elements inside a <section class="cards">. Write CSS that makes .cards a three-column grid using repeat(3, 1fr) with a gap of 1.25rem. Give each article a background color, padding, and border radius.grid-auto-rows: minmax(150px, auto) to the card grid from Task 16-F1. Add varying amounts of text to different cards to see how the row height responds. Observe that shorter and taller cards in the same row all match the tallest card in that row.1fr wide and contain a heading and two paragraphs. The right column should be 280px wide and contain a list of links inside an <aside>. Add align-self: start to the aside so it does not stretch to full height.grid-template-areas. Name the areas main and sidebar. Assign them using grid-area on the relevant elements.<figure> elements, each containing an <img> (or a colored placeholder div) and a <figcaption>. Use repeat(auto-fill, minmax(220px, 1fr)) for the columns and a gap of 1rem. Resize the browser window and observe how the column count changes.repeat(auto-fill, minmax(240px, 1fr))css/main.css<h1> that describes the page content.<article> or another appropriate semantic element.<h2> (or another appropriate level) and follow a logical heading order.alt text, or alt="" if purely decorative.aria-current="page".These questions draw on material from earlier chapters.
padding: 1rem, border: 2px solid #ccc, and a defined width: 300px. By default, what is the total rendered width of the card, and how does box-sizing: border-box change this?position: absolute.1rem and 1em for font size on paragraph text. What is the difference, and which is generally safer for consistent results across nested elements?h2 { color: gray; } and a class selector .highlight { color: blue; }. The heading element in the HTML has class="highlight". Which color wins? Why?<style> tag inside the <head>. You later move those styles to an external main.css file and link it properly. Should the styles still work? What are the advantages of the external file approach?grid-template-columns control? Give an example with three columns of different sizes.fr unit represent, and how is it different from a percentage?gap property in a Grid layout?repeat() and minmax() each do? Why are they often used together?grid-template-areas and grid-area?repeat(auto-fill, minmax(250px, 1fr)) creates a responsive layout without any media queries.align-self: start matter for a sidebar inside a Grid layout? What happens if it is omitted?grid-column: 1 / 3 and grid-column: span 2. Are there situations where these produce the same result?grid-template-columns that achieves this.grid-template-columns: 300px 300px 300px; gap: 1rem; inside a container that is only 700px wide on a phone screen. Identify the problem this will cause and rewrite the CSS to fix it responsively.grid-area assigned. Predict what will happen to the sidebar in the rendered page.grid-template-areas for a blog post page that includes a full-width header, a full-width title section below it, a main article column, a related-posts sidebar, and a full-width footer. Write the grid-template-areas declaration and the grid-area assignments.grid-template-columns and grid-template-rows to define a grid's structure.fr unit to create equal and unequal column proportions.gap to control spacing without affecting the outer edges of the grid.repeat() and minmax() together to build a responsive gallery with no media queries.span keyword.grid-template-areas and grid-area.display: grid when a layout is not forming.grid-template-columns/grid-template-rows belong on the container, while grid-column/grid-row belong on items.Chapter 17 covers responsive design and media queries. You now know how to build Grid layouts that use fr units and auto-fill to adapt naturally to different widths. Chapter 17 takes the next step: writing media queries that change layout, typography, spacing, and navigation at specific breakpoints. You will also learn mobile-first design — the practice of writing styles for small screens first and adding complexity for larger screens. By the end of Chapter 17, your Student Learning Site pages will look and work well on phones, tablets, and large monitors.