HTML Headings
In this page:
<h1>Heading text</h1>
<h2>Heading text</h2>
<h3>Heading text</h3>
The Heading Hierarchy (h1 to h6)
HTML offers six levels of headings, starting with h1 as the largest and most important, moving down to h6 as the smallest. This hierarchy establishes a clear order of importance for your content, similar to chapters and sub-chapters in a book.
Example: The Heading Hierarchy (h1 to h6)
<h1>Main Title</h1>
<h2>Section</h2>
<h3>Subsection</h3>
<h4>Sub-subsection</h4>
<h5>Minor heading</h5>
<h6>Smallest heading</h6>
Why Headings Matter for SEO
Search engines use headings to read, categorize, and index your website. If you structure your headings properly with relevant keywords, search bots can easily determine what services or products you offer.
Example: Why Headings Matter for SEO
<h1>Affordable Web Hosting Plans</h1>
<h2>Shared Hosting Pricing</h2>
Accessibility and Screen Readers
Visually impaired users often rely on assistive technologies like screen readers to navigate websites. These devices allow users to skip from heading to heading to skim the content, making proper heading structures essential.
Example: Accessibility and Screen Readers
<h1>Article Title</h1>
<h2>Introduction</h2>
<h2>Conclusion</h2>
Headings are Structural, Not Visual
A common mistake is selecting a heading tag based purely on how large it looks in the browser. Headings must represent structural relationships. If you want larger or smaller text, you should always control that using CSS.
Example: Headings are Structural, Not Visual
<h2>Correct: Structural Heading</h2>
<p style="font-size: 24px;">Large text without using a heading tag</p>
Managing Default Spacing and Margins
Browsers automatically add pre-set margins above and below headings to separate them from adjacent paragraphs. Understanding these default styles prevents layout surprises when arranging elements.
Example: Managing Default Spacing and Margins
<h2 style="margin: 0;">Heading with margins removed</h2>
<p>Paragraph sitting closer to the heading above.</p>
- Using h3 or h4 tags purely because you like their default size, ignoring the hierarchy.
- Including more than one h1 tag on a single webpage.
- Using bold paragraph tags instead of heading tags, which makes your site invisible to screen-reader shortcuts.
- HTML headings organize content into six structural levels from h1 to h6.
- Proper heading hierarchy is crucial for search engine optimization and website navigation.
- Headings should define structural hierarchy, while CSS should define visual size and design.
Heading elements from h1 to h6 have absolute native support across every browser ever made.
Chapter Quiz — Complete all 11 topics to unlock
0/11 topics done
Complete these topics first: