How to add sub heading using HTML ?
Last Updated :
30 Sep, 2024
In HTML, headings are used to structure the content, creating a clear hierarchy that improves readability and organization. Subheadings help break down sections of content, guiding users through the information.
There are several ways to add subheadings in HTML, and we'll explore two common methods to define the hierarchy of headings and subheadings on your webpage.
Ways To Add Sub Heading in HTML
1. Using HTML Tags
The easiest way to add subheadings in HTML is by using heading tags. HTML provides six levels of headings (<h1> to <h6>), where <h1> is the highest level, typically used for the main heading, and <h2> and beyond are used for subheadings. Subheadings are written in a tag with a lower level than the main heading, such as <h2> or <h3>.
Example: In the following example, the main heading uses the <h1> tag, and the subheading uses the <h2> tag to demonstrate the hierarchy of content.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Adding Sub Heading</title>
<style>
.container {
height: 200px;
width: 600px;
background-color: green;
color: black;
border-radius: 10px;
border: 2px solid gray;
}
</style>
</head>
<body>
<div class="container">
<h1>GeeksforGeeks - Main Heading</h1>
<div>
<h2>About GeeksforGeeks - Sub Heading</h2>
<p>
A Computer Science portal for geeks.
It contains well written,well thought
and well explained computer science
and programming articles, quizzes
</p>
</div>
</div>
</body>
</html>
Output :

Note: HTML headings have a default size and styling. Users can alter them according to their needs.
2. Using a Combination of Heading Tags and Divs
Another method to add subheadings is by using the <div> tag along with CSS styling. The <div> tag is a generic block-level container and is often used to create sections within a webpage. While it doesn't inherently carry the same semantic meaning as heading tags, it can be styled to look and function like a subheading. This method gives more flexibility for custom styling.
Use the <div> tag to create a section, and apply custom CSS styles to make it visually similar to a heading tag. This method is useful when you want full control over how the subheading looks, without being limited to the default styles of HTML headings.
Example: In the following example, the <div> tag is used for the subheading, styled with CSS to look like a subheading.
HTML
<!DOCTYPE html>
<html>
<head>
<title>Adding Sub Heading 2</title>
<style>
.container {
height: 200px;
width: 600px;
background-color: green;
color: white;
border-radius: 10px;
border: 2px solid gray;
}
.subHeading {
display: block;
font-size: 1.5em;
margin-top: 0.83em;
margin-bottom: 0.83em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>GeeksforGeeks - Main Heading</h1>
<div>
<div class="subHeading">
About GeeksforGeeks - Sub Heading
</div>
<p>
A Computer Science portal for geeks.
It contains well written,well thought
and well explained computer science and
programming articles, quizzes
</p>
</div>
</div>
</body>
</html>
Output :
Similar Reads
How to define an HTML heading in HTML5 ? An HTML heading tag is used to define the headings of a page. Headings are defined with the <h1> to <h6> tags. The size of the text depends upon the type of heading tag. h1 is the largest heading tag and h6 is the smallest one (h1 > h2 > h3 > h4 > h5 > h6). Syntax: <h1
1 min read
How to add description list of an element using HTML ? To define the description of an element, the <dl> tag is used. This tag is used with <dt> and <dd> tag. In HTML4.1, it defines the definition list and in HTML5, it defines the description list. Syntax: <dl> Contents... </dl> Example 1: html <!DOCTYPE html> <htm
2 min read
How to add description list of an element using HTML ? To define the description of an element, the <dl> tag is used. This tag is used with <dt> and <dd> tag. In HTML4.1, it defines the definition list and in HTML5, it defines the description list. Syntax: <dl> Contents... </dl> Example 1: html <!DOCTYPE html> <htm
2 min read
How to add description list of an element using HTML ? To define the description of an element, the <dl> tag is used. This tag is used with <dt> and <dd> tag. In HTML4.1, it defines the definition list and in HTML5, it defines the description list. Syntax: <dl> Contents... </dl> Example 1: html <!DOCTYPE html> <htm
2 min read
How to Create Header Cell in a Table using HTML? A header cell in a table made with <th> tag is used to label columns or rows, helping organize information. To create a header cell in an HTML table, use the <th> element. Header cells typically contain titles for each column or row, and they are bold by default.Syntax<th> Contents
1 min read
How to Build a Website using HTML? Building a website using HTML (Hypertext Markup Language) is the foundation of web development. HTML allows you to structure content, define headings, paragraphs, lists, and links, and create visually appealing web pages.In this article, we'll learn the fundamentals of How to build a Website using H
5 min read