Home > Web Front-end > HTML Tutorial > How to add subtitle using HTML? To translate this question into Chinese, it would be: How to add subtitle using HTML?

How to add subtitle using HTML? To translate this question into Chinese, it would be: How to add subtitle using HTML?

PHPz
Release: 2023-08-25 20:13:02
forward
1844 people have browsed it

如何使用HTML添加子标题?

To translate this question into Chinese, it would be:

如何使用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.

Add subtitle using HTML

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

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> 
Copy after login

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>
Copy after login

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;
}
Copy after login

HTML

<p class="subheading">This is a subheading</p> 
Copy after login

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>
Copy after login

Method of using CSS "Div" tag

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> 
Copy after login

in conclusion

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template