Home > Article > Web Front-end > How to add subtitle using HTML? To translate this question into Chinese, it would be: How to add subtitle using HTML?
Subtitle is a text element used in HTML to organize and structure web content. Subheadings are often used to break up large blocks of text and provide users with a clear hierarchy of information. Subtitles are usually 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.
HTML is a markup language used to structure and format content on web pages. An important aspect of HTML is the ability to create headings and subheadings to organize and structure text. In this article, we will discuss various ways to add subtitles using HTML.
Method 1 - Use the "H" tag
Method 2 - Using the "P" tag with CSS
Approach 3 − Using the "Div" tag with CSS
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>
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>
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>
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>
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.
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>
There are several ways to add subtitles using HTML. The "H" tag, the "P" tag with CSS, and the "Div" tag with CSS are all valid methods. It’s important to note that headings and subheadings should be used to organize and structure web content, not just for style.
The above is the detailed content of How to add subtitle using HTML? To translate this question into Chinese, it would be: How to add subtitle using HTML?. For more information, please follow other related articles on the PHP Chinese website!