Sub topic 4
Visual hierarchy: guiding the eye with size, contrast and space
This chapter assumes you can write basic HTML and CSS. It also assumes you know the parts of a page (header, hero, call to action) and the idea from earlier chapters that visitors scan before they read. Here you will learn the tools that decide where a scanning eye lands first, second and last.
What visual hierarchy is
Visual hierarchy is the order in which a viewer notices the elements on a page. Every page has one, whether you design it or not. If you don't, the browser's defaults and the loudest element win.
A scanning visitor does not process the page evenly. They look for an anchor, such as a headline, a number or a button, and then move to the next most prominent thing. Hierarchy sets that sequence. A good one answers three questions in a glance:
- What is this page about?
- What are the main parts?
- What should I do next?
Four levers control the hierarchy: size, contrast, whitespace and position. They work together. A large, high-contrast element with space around it, placed top left, will almost always be seen first.
Size
Larger elements attract the eye sooner. On the web, size mostly means type size, but it also covers images, buttons and the area an element occupies.
Use a deliberate type scale instead of picking sizes one at a time. A scale multiplies a base size by a fixed ratio. With a base of 1rem and a ratio of 1.25, you get roughly 1rem, 1.25rem, 1.56rem, 1.95rem and 2.44rem. Because every step is visibly different from its neighbors, the reader can tell levels apart. Steps that differ by only a pixel or two look like mistakes, not structure.
Two rules help:
- Keep the number of levels small. Most pages need a page title, section headings, body text and small print. More levels dilute each one.
- Make the largest element mean something. If a decorative banner is bigger than the headline, the banner wins.
Contrast
Contrast is any difference that makes one element stand out from its surroundings. Color contrast is the most obvious kind, but weight, typeface, saturation and shape also count.
Dark text on a light background is the baseline. Raising contrast on one element, for example a saturated button on a pale page, pulls the eye to it. Lowering contrast on secondary content, such as captions or timestamps, pushes it back.
Accessibility sets a floor. WCAG 2.x requires a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text and for interface components such as button borders. Light gray text that fails this is a hierarchy problem and an accessibility failure at the same time, because readers who need the text most can't find it.
Contrast has a budget. Each high-contrast element competes with the others. If five things are bright, bold and large, the page has no hierarchy, only noise.
Whitespace
Whitespace (also called negative space) is the empty area around and between elements. It does not have to be white. Whitespace does two jobs.
First, it isolates. An element surrounded by space is noticed more than the same element in a crowded area. A single button with generous margin beats an identical button wedged between links.
Second, it groups. Elements close together read as related, and elements far apart read as separate. This is the Gestalt principle of proximity. In practice:
- Put less space between a heading and the paragraph beneath it than between that paragraph and the next section's heading.
- Put the space between groups clearly above the space inside groups.
A frequent error is uniform spacing, where every gap is the same. The reader then can't see which heading owns which text. A rule of thumb is to make the gap above a heading about twice the gap below it.
Position
Position is where an element sits. In languages read left to right, attention tends to start at the top left and move down and to the right. Elements placed there are seen earlier, and elements near the bottom are seen later or not at all unless something pulls the eye down.
Position also interacts with the other levers. A small element at the top left can outrank a larger one at the bottom right. Later chapters cover how scanning patterns make some positions stronger than others. For now, treat position as a tiebreaker: when two elements are otherwise equal, the earlier one in the viewing path wins.
The levers in a worked example
The page below is a small pricing card. It uses all four levers on purpose. Save it as an .html file and open it in a browser.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Pricing card</title>
<style>
:root {
--ink: #1a1a1a; /* 16:1 on white */
--muted: #595959; /* 7:1 on white, still passes 4.5:1 */
--accent: #0b5fff; /* 5.6:1 against white text on the button */
--step-0: 1rem;
--step-1: 1.25rem;
--step-3: 1.95rem;
--step-5: 3.05rem;
}
body {
font-family: system-ui, sans-serif;
color: var(--ink);
background: #f4f5f7;
margin: 0;
padding: 3rem 1rem;
}
.card {
max-width: 24rem;
margin: 0 auto;
padding: 2.5rem 2rem; /* whitespace isolates the content */
background: #fff;
border-radius: 0.5rem;
}
.plan { /* small, muted, first in reading order */
margin: 0 0 0.5rem;
font-size: var(--step-0);
font-weight: 600;
letter-spacing: 0.05em;
text-transform: uppercase;
color: var(--muted);
}
.price { /* largest element: the anchor */
margin: 0;
font-size: var(--step-5);
line-height: 1.1;
font-weight: 800;
}
.price small {
font-size: var(--step-0);
font-weight: 400;
color: var(--muted);
}
.pitch {
margin: 1rem 0 0;
font-size: var(--step-1);
}
ul {
margin: 2rem 0; /* bigger gap separates the group */
padding: 0;
list-style: none;
color: var(--muted);
}
li { margin: 0.25rem 0; } /* small gap groups the items */
.cta { /* the only saturated element */
display: block;
padding: 0.875rem 1rem;
text-align: center;
font-size: var(--step-1);
font-weight: 700;
color: #fff;
background: var(--accent);
border-radius: 0.375rem;
text-decoration: none;
}
</style>
</head>
<body>
<article class="card">
<h1 class="plan">Team plan</h1>
<p class="price">$12 <small>per user, per month</small></p>
<p class="pitch">Shared boards for tasks, deadlines and files.</p>
<ul>
<li>Unlimited projects</li>
<li>10 GB of storage per user</li>
<li>Email support</li>
</ul>
<a class="cta" href="/signup">Start free trial</a>
</article>
</body>
</html>Walk through what each lever does here:
- Size: The price is about three times the body size, so it is the anchor. The plan name is small because it is a label, not the message.
- Contrast: Everything is neutral except the button, which is the only saturated block. The feature list uses a muted gray that still passes the 4.5:1 requirement.
- Whitespace: The 2rem margin around the list separates features from the offer, and the small gap between list items groups them.
- Position: The price sits near the top, and the call to action closes the card, so the eye travels from the offer to the action.
Notice also that the plan name is an h1 styled small. The heading level describes the document structure. CSS controls how it looks. Don't choose h3 because you want smaller text, and don't choose h1 for size alone.
Checking a hierarchy
You don't need eye-tracking equipment to test a hierarchy. Three quick checks work well.
- The squint test. Blur your eyes, or apply a blur filter to a screenshot. The elements that still stand out are your actual hierarchy. If the call to action vanishes, it is too weak.
- The grayscale test. Desaturate the screenshot. If the order of importance is lost, you relied on color alone.
- The five-second test. Show the page to someone for five seconds, then ask what the page was about and what they would click. Wrong answers point at the element that is too loud or too quiet.
A short script can apply the first two checks to any local screenshot. This one uses Pillow, installed with pip install pillow.
from PIL import Image, ImageFilter, ImageOps
import sys
def make_test_images(path: str) -> None:
"""Write a blurred and a grayscale copy of a screenshot."""
image = Image.open(path).convert("RGB")
blurred = image.filter(ImageFilter.GaussianBlur(radius=12))
gray = ImageOps.grayscale(image)
blurred.save("squint_test.png")
gray.save("grayscale_test.png")
print("Wrote squint_test.png and grayscale_test.png")
if __name__ == "__main__":
if len(sys.argv) != 2:
sys.exit("Usage: python hierarchy_check.py screenshot.png")
make_test_images(sys.argv[1])Open both outputs and ask: which three things do I see first, and are they the three I intended?
Common errors
| Error | Why it fails | Fix |
|---|---|---|
| Everything is bold or large | When every element is emphasized, none is | Choose one primary element per screen and demote the rest |
| Several competing accent colors | The eye can't pick a first target | Reserve the strongest color for the main action |
| Low-contrast gray for body text | Fails WCAG and slows scanning | Keep body text at 4.5:1 or better |
| Equal spacing everywhere | Groups are not visible | Use less space inside groups and more between them |
| Decorative image outranks the headline | The image absorbs attention that the message needed | Shrink or mute the image, or crop it |
| Heading levels chosen for size | Breaks document structure for screen readers and search engines | Use the correct level, and style it with CSS |
| Hierarchy fixed on desktop only | Stacking on mobile can reorder importance | Check the order at each breakpoint |
Edge cases
Hierarchy is relative, so context changes it. A few cases to watch:
- Animation and motion. Moving elements pull the eye strongly, often against your intended order. An auto-playing carousel can outrank the headline. Use motion sparingly and respect the
prefers-reduced-motionsetting. - Faces and images. Photographs of people attract attention, and a gaze direction can steer it. A face looking toward the headline helps. A face looking away from it can pull the eye off the page.
- Dark mode. Contrast ratios and the apparent weight of text change on dark backgrounds. White text on black can look bolder than the same weight in dark on light, so recheck your scale in both themes.
- Dense data pages. Dashboards and tables are scanned for specific values, not read from the top. Hierarchy here comes from alignment, consistent column structure and a few highlighted values, not from large type.
- Zoom and large text settings. Users who increase text size change your scale. Use relative units such as
remso proportions hold.
Summary
Visual hierarchy is built from four levers. Size sets rank, contrast pulls attention, whitespace isolates and groups, and position sets the order. They add up, so adjust them as a set, and spend them on few elements. Check the result with a squint test, a grayscale view and a quick five-second test before you trust it.
Exercise
A landing page has a headline, a hero photo, three feature blurbs and a "Sign up" button. In a squint test, the hero photo and a bright orange promotional badge in the corner stand out, and the button disappears. Name two changes that fix the hierarchy and say which lever each uses.
Show answer
Any two of these work. (1) Give the button a saturated color that no other element uses, which raises its contrast. (2) Remove or mute the promotional badge, which frees the contrast budget for the button. (3) Surround the button with extra margin so it is isolated, which uses whitespace. (4) Enlarge the button and its label, which uses size. (5) Move the button closer to the headline or the start of the viewing path, which uses position. The photo can also be cropped or darkened so it stops outranking the headline.
Exercise
A pricing page uses the same 1.5rem gap between every heading, paragraph and list. Readers say they can't tell which text belongs to which heading. Which principle explains the problem, and what spacing change fixes it?
Show answer
The principle is proximity: elements that are close together read as related. Because every gap is equal, nothing groups. Reduce the space between a heading and the content it introduces (for example to 0.5rem) and keep a larger gap, such as 2rem or more, above each new heading so the sections separate clearly.