Sub topic 3
Spacing and Proximity: Grouping Related Content
Assume you know basic HTML headings, paragraphs, links, buttons, and CSS selectors, custom properties, and the box model.
Spacing is a visual cue. Elements with less space between them appear related. Larger gaps suggest a new group. This is called the proximity principle.
.card {
padding: 1.25rem;
}
.card__title {
margin: 0 0 0.25rem;
}
.card__description {
margin: 0 0 1.5rem;
}
.card + .card {
margin-top: 2rem;
}The small gap connects the title and description. The larger gap separates one card from the next. Consistent padding also keeps content inside each group.
Combining Emphasis Cues
Size, contrast, and position should support one clear priority. If every element is large, brightly colored, and placed at the top, nothing is primary.
Use a filled, high-contrast button for the main action. Give secondary actions less visual weight. Keep supporting text smaller and farther from the primary heading.
Keeping Visual and DOM Order Aligned
The DOM is the browser's document structure. Keyboard users and screen readers follow this source order. Keep the important heading, explanation, and action in the same sequence visually and in HTML. Avoid using CSS order or absolute positioning to create a misleading reading path.
Preserving Hierarchy Across Screens
A responsive layout changes with available space, but its priorities should remain stable. On a narrow screen, stack content in the same order. On a wide screen, use columns only when the source order still makes sense.
.hero {
display: grid;
gap: 1rem;
}
@media (min-width: 48rem) {
.hero {
grid-template-columns: 2fr 1fr;
}
}Checking the Result
Try the squint test: blur your vision or squint at the page. You should still identify the main heading and primary action. Then check text and interface contrast with a WCAG contrast checker. Normal text generally needs a ratio of at least 4.5:1, while large text needs 3:1.
Exercise
A page has three equally bright buttons. How can you create one primary action?
Show answer
Keep the primary button filled and high contrast, then use an outline or lower-contrast treatment for the secondary buttons.