Sub topic 13
Alignment and grid support for hierarchy
This chapter assumes you know the basics of type (typeface, size, weight) and can read simple CSS. It builds on the chapters about measure and the type scale. Size and weight rank the text. Alignment and a grid make that ranking easy to follow.
Why alignment matters for hierarchy
A reader scans a page along edges. When headlines, subheads, and body text share a left edge, the eye moves down that edge and picks out the larger or heavier lines. When each element starts at a different position, the reader has to find the start of every line again. The hierarchy is still there, but it takes more effort to see.
Alignment also shows grouping. Elements that share an edge look related. A subhead that lines up with its paragraph reads as part of that section.
Choosing an alignment
For left-to-right languages, left-aligned text with a ragged right edge is the safest default for body text. Every line starts at the same place, and the uneven line endings help the eye find the next line.
- Left-aligned: best for body text, subheads, and most headlines.
- Centered: acceptable for a short headline or a title block. Avoid it for paragraphs, because the start of each line moves.
- Justified: gives clean edges but can leave uneven gaps between words. It needs hyphenation to work well.
Pick one alignment for each role and keep it. Switching between centered and left-aligned subheads within one article weakens the hierarchy.
A grid as a shared set of edges
A grid is a set of columns and gutters (the gaps between columns) that elements snap to. It gives every level of the hierarchy the same few edges to align with. Your body text sets the column width, which connects the grid to the measure you chose earlier: a column of about 65 characters is a sound starting point.
.page {
display: grid;
grid-template-columns: 1fr min(65ch, 100%) 1fr;
column-gap: 1rem;
}
.page > * {
grid-column: 2;
}
.page > .wide {
grid-column: 1 / -1;
}Here every child sits in a centered column that is at most 65 characters wide. Headlines, subheads, and paragraphs all share that column's left edge. An element marked wide, such as a large image, can break out across the full width. This breaking out is a deliberate exception, so it draws attention.
Using the grid to separate levels
A grid can raise a level without making it bigger. Two common techniques:
- Outdenting. Place subheads in a narrow side column to the left of the body text. They become easy to scan, and the body keeps a clean edge.
- Spanning. Let the headline cover more columns than the body. The extra width marks it as the top level.
Keep the number of distinct left edges small. Two or three edges is usually enough. More than that looks accidental.
Baseline alignment
When body text sits in several columns, lines in neighboring columns can drift out of step. Aligning them to a shared baseline grid, a set of invisible horizontal lines spaced at your line height, keeps them level. In CSS, choosing spacing values that are multiples of the line height gets you most of the way.
:root {
--line: 1.5rem;
}
p { line-height: var(--line); margin: 0 0 var(--line); }
h2 { line-height: var(--line); margin: calc(var(--line) * 2) 0 calc(var(--line) / 2); }Common errors
- Mixed alignments in one layout, such as a centered headline over left-aligned subheads, with no clear reason.
- Too many edges, with indents and offsets that do not repeat.
- Centered paragraphs longer than two or three lines.
- Grid column widths that ignore the measure, so lines run too long or too short.
Exercise
A page has a left-aligned headline, centered subheads, and body text indented by a different amount in each section. Name two problems this causes for the hierarchy and one fix.
Show answer
The reader must find a new starting point for each element, which slows scanning, and the mixed edges make related items look unrelated. Fix: put the headline, subheads, and body text on one shared left edge in a single grid column, and use size and weight, not alignment changes, to rank them.