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

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.
Six heading levels from most to least important.
Build a logical outline without skipping levels.
Describe the main topic with a single h1.
Link to sections and apply CSS styles.
Help search engines understand structure.
Container landmark vs heading text label.
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.
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.
Wrap heading text in the appropriate opening and closing tag:
<h1>Main Heading</h1>
<h2>Subheading</h2>
<h3>Section Title</h3>
<!-- ... -->
<h6>Least Significant Heading</h6>h1 per page for the primary topic (in most layouts).h2 to h3, not h2 to h5.main, article, or section — not randomly in footer for page structure.| Tag | Role | Typical use |
|---|---|---|
<h1> | Main page heading | One per page — primary topic |
<h2> | Major sections | Chapter or section titles |
<h3> | Subsections | Topics under an h2 |
<h4> | Nested subsections | Details under h3 |
<h5> | Minor labels | Rare in simple pages |
<h6> | Least significant | Smallest subheading level |
<header>These are often confused. They work together but serve different purposes:
| Feature | h1–h6 | <header> |
|---|---|---|
| Element type | Heading text labels | Sectioning / landmark container |
| Purpose | Define content hierarchy | Group intro content (logo, nav, title) |
| Count per page | One h1 + multiple h2–h6 | One site header + optional section headers |
| Example | <h1>Page Title</h1> | <header><h1>...</h1><nav>...</nav></header> |
Each level nests logically under the one above it:
| Level | Document role | Outline example |
|---|---|---|
h1 | Page title | HTML Heading Tags Tutorial |
h2 | Main sections | Syntax · Examples · Best Practices |
h3 | Subsections | Under each h2 topic |
h4–h6 | Further nesting | Deep detail when needed |
Headings create a machine-readable outline. Search engines and screen readers use this hierarchy to understand relationships between sections.
Descriptive headings signal topic relevance. Use natural keywords in h1 and h2 text — never stuff keywords or use headings only for styling.
Screen reader users jump between headings to scan pages. Accurate levels and descriptive text make content navigable for everyone.
Heading tags have no tag-specific attributes. These global attributes are most useful:
id NavigationCreates a fragment target for in-page links (href="#section-id").
id="main-heading"class StylingApply CSS classes for color, spacing, or custom typography.
class="page-title"lang GlobalLanguage of heading text when it differs from the page.
lang="fr"aria-* A11yRarely needed if heading text is descriptive. Prefer clear visible text first.
aria-level="2"<h1 id="main-heading" class="highlight">Main Heading</h1>
<h2 id="subheading" class="emphasis">Subheading</h2>Heading hierarchy, attributes, document outline, and CSS styling with live previews and Try It Yourself editors.
All six heading levels from h1 (largest) to h6 (smallest):
Use h1 for the page topic and h2–h6 for nested subsections in logical order.
<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>Use id for fragment links and class for CSS styling on headings.
<h1 id="main-heading" class="highlight">Main Heading</h1>
<h2 id="subheading" class="emphasis">Subheading</h2>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.
Nested sections with h2 and h3 create a scannable document structure:
<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>Change visual appearance with CSS while keeping semantic h1–h6 markup.
<h1 class="page-title">Styled Main Heading</h1>
<h2 class="section-title">Styled Subheading</h2>Customize color, size, and spacing without changing heading level semantics:
font-size Visual scalecolor Brand typographymargin Section spacingborder-bottom Underline h1/h2h1.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
Headings are one of the most important accessibility features on a page:
Wrap titles in h1–h6 by importance.
Assistive tech exposes a heading list for quick navigation.
Default sizes can be overridden while semantic level stays intact.
Users, search engines, and screen readers all benefit from proper headings.
Heading tags <h1> through <h6> are core HTML elements supported in every browser.
h1–h6 are among the oldest HTML elements. Every browser renders them with full support.
Bottom line: Heading tags are universal. Focus on correct hierarchy and descriptive text in every project.
Mastering HTML heading tags is fundamental for well-structured, accessible web content. Use one descriptive h1, nest h2–h6 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.
h1 per page for the main topicid on headings for table-of-contents linksfooterheader element with heading tagsBookmark these before you ship — they keep your document outline clear and accessible.
h1 (main) through h6 (least).
FoundationOne main topic per page.
HierarchyHeadings signal topic outline.
DiscoveryHeadings label; header groups.
ComparisonFollow h1 → h2 → h3 order.
AccessibilityCore HTML in all browsers.
Compatibilityh1 through h6 — that label content by importance, with h1 as the main heading.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.Build a correct h1–h6 outline in the interactive HTML editor.
6 people found this page helpful