HTML Headings
Learn to create effective document structure and improve accessibility using HTML heading elements h1 through h6.
What are HTML Headings?
HTML headings are used to create a hierarchical structure for your content, similar to the chapters and sections in a book. They range from <h1>
(the most important) to <h6>
(the least important), helping both users and search engines understand the organization and priority of your content.
Headings serve multiple crucial purposes: they create visual hierarchy for users, provide structure for screen readers and assistive technologies, help search engines understand your content organization, and make your pages more scannable and readable.
📚 Key Concept
Think of headings as the outline of your content. Just like you wouldn't start a book chapter with a subsection, you shouldn't skip heading levels in HTML. This creates a logical, accessible structure.
The Six Heading Levels
HTML provides six levels of headings, each with default styling that decreases in size and importance:
<h1>This is a Heading 1</h1> <h2>This is a Heading 2</h2> <h3>This is a Heading 3</h3> <h4>This is a Heading 4</h4> <h5>This is a Heading 5</h5> <h6>This is a Heading 6</h6>
This is a Heading 1
This is a Heading 2
This is a Heading 3
This is a Heading 4
This is a Heading 5
This is a Heading 6
Proper Heading Hierarchy
The key to effective headings is maintaining a logical hierarchy. Here's how to structure your content properly:
<!-- ✅ Good: Proper hierarchy --> <h1>Main Page Title</h1> <h2>Major Section</h2> <h3>Subsection</h3> <h4>Sub-subsection</h4> <h3>Another Subsection</h3> <h2>Another Major Section</h2> <!-- ❌ Bad: Skipping levels --> <h1>Main Title</h1> <h4>This skips h2 and h3</h4> <h2>This breaks the logical flow</h2>
🎯 Hierarchy Rules
- One h1 per page: Use h1 for the main page title
- Don't skip levels: Go h1 → h2 → h3, not h1 → h3
- Logical nesting: Each level should represent a subdivision of the level above
- Consistent structure: Maintain the same pattern throughout your site
Real-World Examples
Let's see how headings work in practical scenarios:
Blog Post Structure
<article> <h1>How to Learn Web Development in 2025</h1> <h2>Getting Started</h2> <p>Introduction paragraph...</p> <h2>Essential Technologies</h2> <h3>HTML Fundamentals</h3> <p>HTML content...</p> <h3>CSS Styling</h3> <p>CSS content...</p> <h4>CSS Grid vs Flexbox</h4> <p>Comparison content...</p> <h3>JavaScript Basics</h3> <p>JavaScript content...</p> <h2>Learning Resources</h2> <p>Resources content...</p> <h2>Conclusion</h2> <p>Conclusion content...</p> </article>
Website Homepage Structure
<main> <h1>Welcome to TechCorp Solutions</h1> <section> <h2>Our Services</h2> <div class="service"> <h3>Web Development</h3> <h4>Frontend Development</h4> <h4>Backend Development</h4> </div> <div class="service"> <h3>Digital Marketing</h3> <h4>SEO Services</h4> <h4>Social Media</h4> </div> </section> <section> <h2>About Us</h2> <h3>Our Mission</h3> <h3>Our Team</h3> </section> </main>
SEO and Accessibility Benefits
Proper heading usage provides significant benefits for both search engine optimization and accessibility:
SEO Benefits
- Content Structure: Search engines use headings to understand content hierarchy
- Keyword Relevance: Headings carry more weight than regular text
- Featured Snippets: Well-structured content is more likely to appear in featured snippets
- Topic Clusters: Help search engines understand content relationships
Accessibility Benefits
- Screen Readers: Users can navigate by headings to find specific content quickly
- Voice Control: Voice navigation software uses headings as landmarks
- Cognitive Accessibility: Clear structure helps users with cognitive disabilities
- Keyboard Navigation: Some browsers allow users to jump between headings
Styling Headings with CSS
While HTML provides the structure, CSS controls the appearance. Here are some common styling patterns:
/* Reset default heading styles */ h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: normal; line-height: 1.2; } /* Custom heading styles */ h1 { font-size: 2.5rem; font-weight: bold; color: #2c3e50; margin-bottom: 1rem; } h2 { font-size: 2rem; font-weight: 600; color: #34495e; margin: 2rem 0 1rem; border-bottom: 2px solid #3498db; padding-bottom: 0.5rem; } h3 { font-size: 1.5rem; font-weight: 600; color: #2c3e50; margin: 1.5rem 0 0.75rem; }
Advanced Heading Techniques
Adding Subtitles
<!-- Method 1: Using hgroup (HTML5) --> <hgroup> <h1>The Complete Guide to Web Development</h1> <h2>From Beginner to Professional Developer</h2> </hgroup> <!-- Method 2: Using p element --> <h1>The Complete Guide to Web Development</h1> <p class="subtitle">From Beginner to Professional Developer</p> <!-- Method 3: Using span for styling --> <h1> The Complete Guide to Web Development <span class="subtitle">From Beginner to Professional Developer</span> </h1>
Section Headings with IDs
<!-- Adding IDs for anchor links --> <h2 id="introduction">Introduction</h2> <h2 id="getting-started">Getting Started</h2> <h2 id="advanced-topics">Advanced Topics</h2> <!-- Table of contents linking to headings --> <nav class="table-of-contents"> <h2>Table of Contents</h2> <ul> <li><a href="#introduction">Introduction</a></li> <li><a href="#getting-started">Getting Started</a></li> <li><a href="#advanced-topics">Advanced Topics</a></li> </ul> </nav>
Common Heading Mistakes
- Using headings for styling: Don't choose a heading level based on size
- Multiple H1 tags: Use only one H1 per page
- Skipping levels: Don't jump from H1 to H3
- Empty headings: Every heading should contain meaningful text
- Using headings as decoration: Headings should represent actual structure
<!-- ❌ Wrong: Using headings for styling --> <h3>This should be an H1 but I like the size</h3> <h1>This should be an H2 but I made it bigger with CSS</h1> <!-- ✅ Correct: Proper semantic structure --> <h1 class="small-title">Main Title (styled smaller with CSS)</h1> <h2 class="big-subtitle">Section Title (styled larger with CSS)</h2>
Best Practices Summary
🏆 Heading Excellence Checklist
- ✅ Use exactly one H1 per page
- ✅ Maintain logical hierarchy (don't skip levels)
- ✅ Make headings descriptive and specific
- ✅ Include keywords naturally in headings
- ✅ Use CSS for styling, not different heading levels
- ✅ Add IDs to headings for navigation
- ✅ Keep headings concise but meaningful
- ✅ Test with screen readers and keyboard navigation
Content Writing Tips
- Be specific: "JavaScript Array Methods" vs "Programming Concepts"
- Use action words: "How to Create..." "Why You Should..."
- Include keywords: But keep it natural and readable
- Match content: Heading should accurately represent the section
- Consider length: Aim for 2-8 words when possible