Sub topic 1
Why Pages Use a Column Grid
A column grid divides the width of a page into repeating vertical tracks. Designers place content on those tracks instead of choosing each width by eye. This chapter explains what problems that solves, what it costs, and when to bend it. Later chapters cover the parts of a grid and the CSS to build one.
Prerequisites
This chapter assumes you already know:
- Basic HTML structure, including elements and classes.
- Basic CSS syntax, including selectors, properties, and units such as
px,rem, and%. - The CSS box model: how
margin,padding, andwidthcombine to size an element.
You do not need to know CSS Grid yet. The code here is a preview, and the chapters that follow explain each piece.
The problem: widths chosen one at a time
Suppose you build a page with a main article and a sidebar. Without a system, you pick widths that look right. The article is 647px wide. The sidebar is 293px with a 20px gap. The footer has three columns, and you make them each 30% wide because that looked fine.
Each choice is reasonable alone. Together they cause trouble:
- The footer columns do not line up with the article and sidebar edges above them.
- A new component, such as a pricing table, needs yet another width.
- Another developer picks a different gap between cards, and the page now has several spacings that are almost equal.
- When the viewport changes, every one of these numbers needs its own fix.
A column grid replaces these individual decisions with one shared structure. Every element's width and position is described in terms of that structure.
What a grid gives you
A grid helps in five ways. Each is a separate reason, and you can weigh them differently on different projects.
Alignment
When elements start and end on the same vertical lines, the eye reads the page as ordered. Edges that almost line up look like mistakes, and edges that clearly line up look intentional. A grid makes exact alignment the default. A heading, an image, and a card three sections down all start on the same column line.
Consistency across pages
A site has many pages built at different times, often by different people. If every page uses the same column count, gutter, and margins, the pages feel like one product. A reader moving from the home page to a product page does not see the layout shift sideways.
A limited set of widths
With twelve columns, a block can be 3, 4, 6, 8, or 12 columns wide, and so on. That is a small vocabulary instead of unlimited pixel values. A small vocabulary speeds up design decisions and makes layouts easier to review. Twelve is common because it divides evenly by 2, 3, 4, and 6, so halves, thirds, quarters, and sixths all work.
Shared language between design and code
Design tools such as Figma and Sketch can overlay a column grid on a frame. A designer can say "main spans 8, sidebar spans 4", and a developer can write exactly that. Without a grid, the handoff is a list of pixel measurements that the developer must interpret.
A basis for responsive layout
A grid expresses layout as proportions and counts, not fixed pixel positions. That makes it easier to change at different screen sizes. A card that spans 4 of 12 columns on a desktop can span all 4 of 4 columns on a phone. You change the grid, not every element.
A first look in code
The markup below has a container, a grid element, and two items. The next two CSS snippets lay it out in two ways.
<div class="page">
<div class="grid">
<main class="main">Main content</main>
<aside class="sidebar">Sidebar</aside>
</div>
</div>First, the ad hoc approach, with widths picked by eye and fixed in pixels:
.grid {
display: flex;
}
.main {
width: 647px;
}
.sidebar {
width: 293px;
margin-left: 20px;
}This works at 960px wide. The numbers have no relationship to anything else on the page. Nothing in the CSS says why 647 or 293. Anything else that must align with these edges needs the same magic numbers.
Now the same layout on a twelve-column grid:
.page {
max-width: 72rem;
margin-inline: auto;
padding-inline: 1rem;
}
.grid {
display: grid;
grid-template-columns: repeat(12, 1fr);
column-gap: 1.5rem;
}
.main {
grid-column: span 8;
}
.sidebar {
grid-column: span 4;
}The container caps the width at 72rem, centers it, and keeps side margins through padding. The grid creates twelve equal flexible columns with a 1.5rem gutter. The main area spans 8 columns and the sidebar spans 4. If a footer needs three equal blocks, each spans 4, and its edges land on the same lines as the sidebar's.
You do not need to memorize this yet. The point is the change in how the layout is described: "8 and 4 of 12" instead of "647px and 293px".
Trade-offs and limits
A grid is a tool, and it has costs.
- Rigidity. If every element must snap to a column, some designs feel boxy. A grid constrains you on purpose, but the constraint can be too strict for editorial or art-directed pages.
- Up-front decisions. You must choose the column count, gutter, and margins before building. Changing them later can mean revisiting many components.
- False precision. A twelve-column grid does not make a layout good. Content with poor hierarchy still looks poor when it is aligned.
- Overkill for tiny pages. A single centered column of text, such as a simple blog post, needs a container and a readable line length, and little else.
Breaking the grid deliberately
Experienced designers often break the grid on purpose. A full-bleed image might run edge to edge. A pull quote might hang into the margin. This works because the rest of the page is aligned, so the exception reads as a choice. Breaking a grid by accident reads as an error. If you cannot say why an element sits off the grid, put it back on.
Grids and content
A grid organizes space, but content decides how much space you need. Body text is easiest to read at roughly 45 to 80 characters per line. If a text block spans too many columns, lines become too long no matter how neatly the grid aligns. Check the grid against real content, not placeholder boxes.
Common errors when adopting a grid
- Choosing columns before looking at content. Pick a count that fits the components you actually have. Twelve is a common default, not a requirement.
- Treating the grid as visible decoration. Columns and gutters are guides. Readers should see aligned content, not a pattern of columns.
- Mixing systems. Using a grid for the page and unrelated pixel widths inside it brings back the misalignment the grid was meant to remove. A later chapter on nested grids covers the right way to carry the grid inward.
- Hard-coding pixel positions. A grid specified in fixed pixel offsets breaks at other viewport widths. Prefer proportional units and counts.
- Ignoring order for non-visual readers. Screen readers and keyboard users follow the HTML source order, not the visual position. A grid can place items anywhere, so make sure the source order still makes sense. A later chapter covers this in detail.
How this chapter fits the rest
This chapter gives the reason for a grid. The following chapters break it into parts and techniques:
| Topic | Question it answers |
|---|---|
| Parts of a grid | What are columns, gutters, and margins? |
| Containers | How wide should the grid be, and where does it sit? |
| Fixed and fluid grids | Do the columns have set widths or flexible ones? |
| CSS Grid and spanning | How do I build the grid and place items on it? |
| Responsive grids | How does the grid change across screen sizes? |
| Pitfalls | What commonly goes wrong? |
Exercise
A teammate sets the main article to 647px and the sidebar to 293px with a 20px gap, and sets the footer's three columns to 30% each. Name two problems this causes that a shared column grid would avoid.
Show answer
Any two of these: the footer columns do not align with the article and sidebar edges above them; the widths are unrelated numbers, so each new component needs another width; nothing documents why the values were chosen, which makes design-to-code handoff and review harder; the fixed pixel widths are hard to adapt at other screen sizes. On a twelve-column grid, the article and sidebar could span 8 and 4, and the footer blocks could span 4 each, so all edges fall on shared column lines.
Exercise
Why is twelve a common column count, and why is it not always the right one?
Show answer
Twelve divides evenly by 2, 3, 4, and 6, so halves, thirds, quarters, and sixths all fit without fractions. It is not always right because the best count depends on the components you have. A simple text page may need only a single column, and a layout of mostly four-up cards might be simpler with a four-column grid.
Exercise
A designer lets a hero image run past the page margins while the text stays on the grid. When is this a good use of breaking the grid, and when is it a mistake?
Show answer
It is good when it is deliberate and the rest of the page stays aligned, so the exception stands out as a choice. It is a mistake when the designer cannot explain why the element sits off the grid, or when it happens by accident through unrelated pixel values.