The h2
tag defines a second-level heading on a webpage. It’s used to mark important subsections under the main h1
heading.
✅ Basic Syntax
<h2>About Our Services</h2>
📍 Result:
A prominent heading, slightly smaller than <h1>
, used to organize content into meaningful sections.
📚 Heading Hierarchy
HTML provides six levels of headings:
<h1>Main Title</h1>
<h2>Section Title</h2>
<h3>Subsection Title</h3>
<h4>Smaller Heading</h4>
<h5>Even Smaller</h5>
<h6>Smallest Heading</h6>
<h2>
comes right after<h1>
, and you can have multiple<h2>
tags per page.- Use
<h2>
to break content into logical sections beneath the main heading.
🎯 Semantic Importance
The <h2>
tag helps:
- Search engines understand your page structure
- Screen readers navigate the document easily
- Users scan content quickly
🎨 Styling Example (CSS)
h2 {
font-size: 2rem;
color: #34495e;
margin-top: 30px;
margin-bottom: 15px;
}
⚠️ Best Practices
✅ Do | ❌ Avoid |
---|---|
Use <h2> for main sections | Skipping heading levels |
Maintain logical heading order | Jumping directly from <h1> to <h4> |
Make headings descriptive | Using vague titles like “Section 1” |
✅ Summary
Feature | <h2> Tag |
---|---|
Purpose | Defines second-level headings |
Usage | For subsections under <h1> |
SEO Impact | Helps structure content for SEO |
Styling | Smaller than <h1> , can be customized |