How to add sub heading using HTML?

A subheading is a text element used to organize and structure content on a webpage. Subheadings break up large blocks of text and provide a clear hierarchy of information for users. In HTML, subheadings are primarily created using heading tags <h2>, <h3>, <h4>, <h5>, or <h6>, with <h1> being the main heading and <h6> being the lowest level subheading.

Syntax

Following is the basic syntax for creating subheadings in HTML

<h2>Subheading Level 2</h2>
<h3>Subheading Level 3</h3>
<h4>Subheading Level 4</h4>
<h5>Subheading Level 5</h5>
<h6>Subheading Level 6</h6>

The heading tags create a semantic hierarchy where <h1> is the most important and <h6> is the least important. Screen readers and search engines use this hierarchy to understand content structure.

Using Semantic Heading Tags

This is the most common and recommended way to create subheadings in HTML. The heading tags <h2> through <h6> provide semantic meaning and accessibility benefits. Each level represents a different importance level in the content hierarchy.

Example

Following example demonstrates proper heading hierarchy using semantic HTML tags

<!DOCTYPE html>
<html>
<head>
   <title>Semantic Subheadings</title>
</head>
<body style="font-family: Arial, sans-serif; padding: 20px; background-color: #f9f9f9;">
   <h1>HTML Tutorial</h1>
   <h2>Introduction to HTML</h2>
   <p>HTML is the standard markup language for creating web pages.</p>
   
   <h2>HTML Elements</h2>
   <h3>Heading Elements</h3>
   <p>Heading elements range from h1 to h6.</p>
   
   <h3>Text Elements</h3>
   <h4>Paragraph Element</h4>
   <p>The paragraph element defines a block of text.</p>
   
   <h4>Span Element</h4>
   <p>The span element is used for inline styling.</p>
</body>
</html>

The output shows a properly structured document with clear heading hierarchy

HTML Tutorial                    (largest, h1)
Introduction to HTML             (medium, h2)
HTML is the standard markup language for creating web pages.

HTML Elements                    (medium, h2)
Heading Elements                 (smaller, h3)
Heading elements range from h1 to h6.

Text Elements                    (smaller, h3)
Paragraph Element                (smallest, h4)
The paragraph element defines a block of text.

Span Element                     (smallest, h4)
The span element is used for inline styling.
HTML Heading Hierarchy H1 Main Title H2 Major Section H3 Subsection H4 Sub-subsection H5 Minor heading Decreasing importance and visual size

Using Paragraph Tags with CSS Styling

While not semantically ideal, paragraph tags can be styled to look like subheadings using CSS. This approach should be used sparingly and only when semantic heading tags are not appropriate for the content structure.

Example

Following example shows how to create subheading-like appearance using paragraph tags

<!DOCTYPE html>
<html>
<head>
   <title>Paragraph as Subheading</title>
   <style>
      .custom-subheading {
         font-size: 18px;
         font-weight: bold;
         color: #2c3e50;
         margin-top: 20px;
         margin-bottom: 10px;
      }
   </style>
</head>
<body style="font-family: Arial, sans-serif; padding: 20px; line-height: 1.6;">
   <h1>Web Development Guide</h1>
   <p class="custom-subheading">Getting Started with HTML</p>
   <p>HTML forms the backbone of web development and provides the structure for web content.</p>
   
   <p class="custom-subheading">Understanding CSS Basics</p>
   <p>CSS controls the visual presentation and layout of HTML elements on web pages.</p>
</body>
</html>

The output shows styled paragraphs that visually resemble subheadings

Web Development Guide                    (main heading)
Getting Started with HTML               (bold, larger paragraph)
HTML forms the backbone of web development and provides the structure for web content.

Understanding CSS Basics                (bold, larger paragraph)
CSS controls the visual presentation and layout of HTML elements on web pages.

Using Div Elements with CSS Styling

Similar to paragraphs, <div> elements can be styled to appear as subheadings. This method offers more flexibility in styling but lacks semantic meaning for accessibility tools and search engines.

Example

Following example demonstrates creating subheadings using div elements

<!DOCTYPE html>
<html>
<head>
   <title>Div as Subheading</title>
   <style>
      .section-container {
         max-width: 600px;
         margin: 20px auto;
         padding: 20px;
         background-color: #ecf0f1;
         border-left: 4px solid #3498db;
      }
      .div-subheading {
         font-size: 20px;
         font-weight: bold;
         color: #2980b9;
         margin-bottom: 15px;
         text-transform: uppercase;
         letter-spacing: 1px;
      }
   </style>
</head>
<body style="font-family: Arial, sans-serif; padding: 10px;">
   <h1 style="text-align: center;">Programming Languages</h1>
   
   <div class="section-container">
      <div class="div-subheading">Frontend Technologies</div>
      <p>Frontend technologies include HTML, CSS, and JavaScript for creating user interfaces.</p>
   </div>
   
   <div class="section-container">
      <div class="div-subheading">Backend Technologies</div>
      <p>Backend technologies handle server-side logic, databases, and application architecture.</p>
   </div>
</body>
</html>

The output displays custom-styled div elements that function as visual subheadings

Programming Languages                    (centered main heading)

FRONTEND TECHNOLOGIES                    (blue, uppercase, in bordered box)
Frontend technologies include HTML, CSS, and JavaScript for creating user interfaces.

BACKEND TECHNOLOGIES                     (blue, uppercase, in bordered box)
Backend technologies handle server-side logic, databases, and application architecture.

Comparison of Subheading Methods

Following table compares the different approaches for creating subheadings

Method Semantic Meaning Accessibility SEO Benefits Styling Flexibility
Heading Tags (h2-h6) High Excellent High Good
Paragraph with CSS Low Poor Low Excellent
Div with CSS None Poor None Excellent

Best Practices for Subheadings

Following are the key best practices when creating subheadings

  • Use semantic heading tags Always prefer <h2> through <h6> for proper document structure and accessibility.

  • Maintain hierarchy Do not skip heading levels (e.g., don't jump from <h2> directly to <h4>).

  • One h1 per page Use only one <h1> element per page for the main title.

  • Descriptive text Make subheadings descriptive and meaningful to users and search engines.

  • Consistent styling Apply consistent visual styling to headings of the same level throughout your website.

Conclusion

The recommended approach for creating subheadings is using semantic HTML heading tags (<h2> to <h6>) as they provide proper document structure, accessibility benefits, and SEO advantages. While CSS styling of paragraphs and divs offers visual flexibility, they should be used sparingly and only when semantic headings are not appropriate for the content structure.

Updated on: 2026-03-16T21:38:54+05:30

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements