Heading Hierarchy
You'll learn how to create visual distinction between heading levels (h1-h6) using size, weight, and spacing while preserving semantic HTML structure.
The Core Idea
Imagine a book where chapter titles, section headings, and sub-section titles all looked identical—you'd struggle to navigate it. Your webpage works the same way. While HTML gives you six semantic heading levels (<h1> through <h6>) for structure and accessibility, CSS lets you style them so users instantly understand the content hierarchy at a glance.
The key is visual distinction. Your <h1> should be the most prominent, with each subsequent level progressively less so. You achieve this through three primary tools:
Size: Each heading level should be noticeably smaller than the one above it. Your type scale (from the previous lesson) provides these proportional sizes.
Weight: Heavier font weights (700, 800) signal importance. An <h1> might use font-weight: 800, while an <h3> uses 600.
Spacing: More important headings often need more breathing room. Larger margins above and below separate major sections, while smaller headings sit closer to their related content.
Building the Hierarchy
h1 {
font-size: 3rem;
font-weight: 800;
margin-top: 0;
margin-bottom: 2rem;
}
h2 {
font-size: 2.25rem;
font-weight: 700;
margin-top: 3rem;
margin-bottom: 1.5rem;
}
h3 {
font-size: 1.75rem;
font-weight: 600;
margin-top: 2rem;
margin-bottom: 1rem;
}
Notice how each property decreases systematically. The margin-top on h2 is generous (3rem) to clearly separate major sections, while h3 uses less space since it's nested within those sections.
Key Takeaway: Heading hierarchy uses size, weight, and spacing in combination to create clear visual levels that mirror your HTML's semantic structure, making content scannable and accessible.