HTML Heading Tags (h1–h6)

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 5 Examples
Text Content

What You’ll Learn

By the end of this tutorial, you’ll structure pages with correct h1–h6 heading hierarchy for readability, SEO, and accessibility.

HTML provides six heading elements — <h1> through <h6> — that define the outline of your content. This guide covers syntax, hierarchy rules, styling, and best practices.

01

h1 to h6 Levels

Six heading levels from most to least important.

02

Document Hierarchy

Build a logical outline without skipping levels.

03

One h1 Per Page

Describe the main topic with a single h1.

04

id & class

Link to sections and apply CSS styles.

05

SEO Benefits

Help search engines understand structure.

06

header vs h1

Container landmark vs heading text label.

What Are HTML Heading Tags?

Heading tags (<h1> to <h6>) label sections of content by importance. <h1> is the main heading (largest, most significant) and <h6> is the smallest subheading. Browsers render each level at a default size, but CSS can change appearance while preserving semantic meaning.

💡
Structure, not just big text

Do not choose heading tags only for font size. Pick the level that matches your document outline. Use CSS for visual size when needed.

Proper heading structure helps screen readers navigate by headings, helps search engines understand topic hierarchy, and makes long pages scannable for all users.

📝 Syntax

Wrap heading text in the appropriate opening and closing tag:

syntax.html
<h1>Main Heading</h1>

<h2>Subheading</h2>

<h3>Section Title</h3>

<!-- ... -->

<h6>Least Significant Heading</h6>

Syntax Rules

  • Use exactly one h1 per page for the primary topic (in most layouts).
  • Do not skip levels — go from h2 to h3, not h2 to h5.
  • Heading elements are block-level and require closing tags.
  • Place headings inside main, article, or section — not randomly in footer for page structure.

⚡ Quick Reference

TagRoleTypical use
<h1>Main page headingOne per page — primary topic
<h2>Major sectionsChapter or section titles
<h3>SubsectionsTopics under an h2
<h4>Nested subsectionsDetails under h3
<h5>Minor labelsRare in simple pages
<h6>Least significantSmallest subheading level

⚖️ Heading Tags vs <header>

These are often confused. They work together but serve different purposes:

Featureh1–h6<header>
Element typeHeading text labelsSectioning / landmark container
PurposeDefine content hierarchyGroup intro content (logo, nav, title)
Count per pageOne h1 + multiple h2–h6One site header + optional section headers
Example<h1>Page Title</h1><header><h1>...</h1><nav>...</nav></header>

⚖️ Heading Level Hierarchy

Each level nests logically under the one above it:

LevelDocument roleOutline example
h1Page titleHTML Heading Tags Tutorial
h2Main sectionsSyntax · Examples · Best Practices
h3SubsectionsUnder each h2 topic
h4h6Further nestingDeep detail when needed

📚 Importance of Heading Tags

🔍

Semantic Structure

Headings create a machine-readable outline. Search engines and screen readers use this hierarchy to understand relationships between sections.

📈

SEO Benefits

Descriptive headings signal topic relevance. Use natural keywords in h1 and h2 text — never stuff keywords or use headings only for styling.

Accessibility

Screen reader users jump between headings to scan pages. Accurate levels and descriptive text make content navigable for everyone.

🧰 Attributes

Heading tags have no tag-specific attributes. These global attributes are most useful:

id Navigation

Creates a fragment target for in-page links (href="#section-id").

id="main-heading"
class Styling

Apply CSS classes for color, spacing, or custom typography.

class="page-title"
lang Global

Language of heading text when it differs from the page.

lang="fr"
aria-* A11y

Rarely needed if heading text is descriptive. Prefer clear visible text first.

aria-level="2"
attributes.html
<h1 id="main-heading" class="highlight">Main Heading</h1>

<h2 id="subheading" class="emphasis">Subheading</h2>

Examples Gallery

Heading hierarchy, attributes, document outline, and CSS styling with live previews and Try It Yourself editors.

Live Preview

All six heading levels from h1 (largest) to h6 (smallest):

Full Heading Hierarchy

Use h1 for the page topic and h2–h6 for nested subsections in logical order.

heading-hierarchy.html
<main>

  <h1>Main Heading</h1>

  <h2>Subheading</h2>

  <h3>Heading 3</h3>

  <h4>Heading 4</h4>

  <h5>Heading 5</h5>

  <h6>Least Significant Heading</h6>

</main>
Try It Yourself

id and class Attributes

Use id for fragment links and class for CSS styling on headings.

attributes.html
<h1 id="main-heading" class="highlight">Main Heading</h1>

<h2 id="subheading" class="emphasis">Subheading</h2>
Try It Yourself

📚 Common Use Cases

Use headings for page titles, article sections, FAQ questions, documentation chapters, card titles inside articles, and table-of-contents anchors. Pair h1 with main and nest h2–h3 inside section elements for clear outlines.

Document Outline

Nested sections with h2 and h3 create a scannable document structure:

document-outline.html
<main>

  <h1>HTML Tutorial</h1>

  <section>

    <h2>Getting Started</h2>

    <h3>Install Tools</h3>

    <p>Setup instructions...</p>

  </section>

  <section>

    <h2>First Page</h2>

    <p>Build your first HTML file...</p>

  </section>

</main>

CSS Styled Headings

Change visual appearance with CSS while keeping semantic h1–h6 markup.

styled-headings.html
<h1 class="page-title">Styled Main Heading</h1>

<h2 class="section-title">Styled Subheading</h2>
Try It Yourself

Styling Headings with CSS

Customize color, size, and spacing without changing heading level semantics:

font-size Visual scale
color Brand typography
margin Section spacing
border-bottom Underline h1/h2
heading-styles.css
h1.page-title {

  font-size: 2rem;

  color: #1d4ed8;

  border-bottom: 2px solid #93c5fd;

  padding-bottom: 0.35rem;

}



h2.section-title {

  font-size: 1.375rem;

  color: #059669;

  margin-top: 1.5rem;

}

Live styled headings

♿ Accessibility

Headings are one of the most important accessibility features on a page:

  • Write descriptive text — headings should summarize the section they introduce.
  • Do not skip levels — jumping from h1 to h4 confuses screen reader outline navigation.
  • One h1 per page — in most documents, a single h1 identifies the main topic.
  • Do not use headings for styling only — pick the correct level; use CSS for size and color.

🧠 How Heading Tags Work

1

Author marks section titles

Wrap titles in h1h6 by importance.

Markup
2

Browser builds document outline

Assistive tech exposes a heading list for quick navigation.

Accessibility
3

CSS styles appearance

Default sizes can be overridden while semantic level stays intact.

Design
=

Clear, scannable content

Users, search engines, and screen readers all benefit from proper headings.

Universal Browser Support

Heading tags <h1> through <h6> are core HTML elements supported in every browser.

Baseline · Core HTML

Heading tags since HTML 1

h1–h6 are among the oldest HTML elements. Every browser renders them with full support.

100% Core tag support
Google Chrome All versions
Full support
Mozilla Firefox All versions
Full support
Apple Safari All versions
Full support
Microsoft Edge All versions
Full support
Internet Explorer All versions
Full support
Opera All versions
Full support
h1–h6 tags 100% supported

Bottom line: Heading tags are universal. Focus on correct hierarchy and descriptive text in every project.

Conclusion

Mastering HTML heading tags is fundamental for well-structured, accessible web content. Use one descriptive h1, nest h2h6 logically, and style with CSS without breaking semantic meaning.

Good heading structure improves user experience and helps search engines understand your pages. Practice the hierarchy until it becomes second nature.

💡 Best Practices

✅ Do

  • Use one h1 per page for the main topic
  • Follow logical order: h1 → h2 → h3
  • Write descriptive heading text that summarizes the section
  • Use id on headings for table-of-contents links
  • Style appearance with CSS, not by picking the wrong level

❌ Don’t

  • Skip heading levels (h1 to h4 without h2/h3)
  • Use multiple h1 tags without a clear reason
  • Put page-structure headings only inside footer
  • Confuse header element with heading tags
  • Keyword-stuff headings for SEO

Key Takeaways

Knowledge Unlocked

Six truths every developer should know about heading tags

Bookmark these before you ship — they keep your document outline clear and accessible.

6
Core concepts
📈 02

One h1

One main topic per page.

Hierarchy
🔍 03

SEO Structure

Headings signal topic outline.

Discovery
🏠 04

Not header

Headings label; header groups.

Comparison
05

No Skipping

Follow h1 → h2 → h3 order.

Accessibility
🌐 06

100% Supported

Core HTML in all browsers.

Compatibility

❓ Frequently Asked Questions

Six elements — h1 through h6 — that label content by importance, with h1 as the main heading.
Yes. Include one descriptive h1 that states the page’s main topic, then use h2–h6 for subsections.
header is a container landmark. h1 is a heading tag that labels text and often sits inside header or main.
Avoid skipping levels. Go from h1 to h2 to h3 in order for a clear document outline and better screen reader navigation.
Yes. Headings help search engines understand page structure. Use natural, descriptive text — not keyword stuffing.
Yes. Heading tags are core HTML supported universally in every browser.

Practice Heading Hierarchy

Build a correct h1–h6 outline in the interactive HTML editor.

Try h1–h6 hierarchy →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful