
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Add Sub Heading Using HTML
A subheading is a text element used to organize and structure the content of a webpage in HTML. Subheadings are commonly used to break up large blocks of text and provide a clear hierarchy of information for users. Subheadings are mostly created using the "H2", "H3", "H4", "H5", or "H6" tags in HTML. These tags indicate the level of the heading, with H1 being the highest level heading and H6 being the lowest level subheading.
Adding sub heading using HTML
HTML is a markup language used to structure and format content on the web page. One of the important aspect of HTML is the ability to create headings and subheadings to organize and structure text. In this article, we will discuss various methods on how to add subheadings using HTML.
Approach 1 ? Using the "H" tags
Approach 2 ? Using the "P" tag with CSS
Approach 3 ? Using the "Div" tag with CSS
Approach 1: Using the "H" tags
This is the most common way to create headings and subheadings in HTML. These tags range from H1 to H6, with H1 being the highest level heading and H6 being the lowest. For creating a subheading, we mostly use the H2, H3, H4, H5, or H6 tags. For example, to create a subheading using the H3 tag, you would use the following code ?
<h3>This is a subheading</h3>
Example
This example shows the first method how to add sub-heading in HTML.
<html> <head> <title>Adding Subheading Using HTML</title> <style> body{ background-color:#d1d0b4; } </style> </head> <body> <h1>This is a Main Heading</h1> <h2>This is a Sub Heading</h2> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p> </body> </html>
Approach 2: Using the "P" tag with CSS
Second Method to create subheadings in HTML is by using the "P" tag and styling it with CSS. This method is useful if we want to create a subheading that is not a traditional heading. For doing this, we would use the "P" tag and give it a class or ID that you can use to apply CSS styles. For example, to create a subheading using the p tag, you would use the following HTML and CSS code ?
CSS
.subheading { font-size: 24px; font-weight: bold; }
HTML
<p class="subheading">This is a subheading</p>
Example
This example shows the second method how to add sub-heading in HTML.
<html> <head> <title>Adding Subheading Using HTML</title> <style> div { margin: auto; height: 250px; width: 500px; padding-left:10px; background-color: #d1d0b4; border: 2px solid #000000; } .subheading { font-size: 24px; font-weight: bold; } </style> </head> <body> <div> <h1>This is a Main Heading</h1> <p class="subheading">This is a Sub Heading</h2> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p> </div> </body> </html>
Approach 3: Using the "Div" tag with CSS
A third method for creating subheadings in HTML is by using the "Div" tag and styling it with CSS. This method is similar to the "P" tag method.
Example
This example shows the "div" tag method how to add sub-heading in HTML.
<html> <head> <title>Adding Subheading Using HTML</title> <style> div { margin: auto; height: 200px; width: 450px; padding-left:10px; background-color: #2596; bder: 2px solid #000000; border-radius:10px; } .subheading { font-size: 24px; } </style> </head> <body> <div> <h1>This is a Main Heading</h1> <p class="subheading">This is a Sub Heading</h2> <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s.</p> </div> </body> </html>
Conclusion
There are multiple ways to add subheadings using HTML. The "H" tags, "P" tag with CSS, and "Div" tag with CSS are all effective methods. It is important to note that headings and subheadings should be used to organize and structure the content of the webpage, and not just for styling.