HTML <h1> to <h6> Tags

Our topic in this post is HTML Tag Hn examples. In hopes that it would provide learners with what they need to learn.

In HTML, heading tags are used to define headings or titles for different sections of a web page. There are six levels of heading tags in HTML, from <h1> to <h6>, with <h1> being the most important and <h6> being the least important. Here’s an overview of how heading tags work in HTML:

  • <h1> is used for the main heading of a web page, which is usually the title of the page.
  • <h2> is used for the subheading of a page, which is a secondary heading that describes the main topic of the page.
  • <h3> to <h6> are used for further subheadings and subsections of a page, with each level indicating a decreasing level of importance.

Tip : Heading tags are not only used for visual purposes, but they also have semantic meaning for search engines and screen readers. Using appropriate heading tags with meaningful content can improve the accessibility and SEO of a web page.

The given code explains the working of different heading tags in html:

Example: 

<!DOCTYPE html> <html> <body> <h1>Here is how heading 1 looks like</h1> <h2>Here is how heading 2 looks like</h2> <h3>Here is how heading 3 looks like</h3> <h4>Here is how heading 4 looks like</h4> <h5>Here is how heading 5 looks like</h5> <h6>Here is how heading 6 looks like</h6> </body> </html>

Headings background and text colors can be set by applying CSS:

Example: 

<!DOCTYPE html> <html> <body> <h1 style="background-color:Blue;">Heading 1 with background color blue</h1> <h2 style="color:Red;">Heading 2 with color red</h2> </body> </html>

The following CSS code can be used to align headings:

Example: 

<!DOCTYPE html> <html> <body> <h1 style="text-align:center">Heading 1 with text-align center</h1> <h2 style="text-align:right">Heading 2 with text-align right</h2> <h3 style="text-align:left">Heading 3 with text-align left</h3> <h4 style="text-align:justify">Heading 4 with text-align justify</h4> </body> </html>

Here is an example of using H1-H6 tags in an HTML document to structure a webpage about a fictional book:

Example: 

<!DOCTYPE html> <html> <body> <h1>The Adventures of Tom Sawyer</h1> <h2>About the Author</h2> <p>Mark Twain was an American author and humorist known for his novels The Adventures of Tom Sawyer and Adventures of Huckleberry Finn.</p> <h2>Summary</h2> <p>The Adventures of Tom Sawyer tells the story of a young boy growing up in the fictional town of St. Petersburg, Missouri. Tom gets into various mischievous adventures with his friends, including whitewashing a fence and attending his own funeral. Along the way, he also learns valuable lessons about friendship and responsibility.</p> <h3>Chapters</h3> <h4>Chapter 1: The Boys' Adventure in the Cave</h4> <h4>Chapter 2: The Search for Treasure</h4> <h4>Chapter 3: The Trial of Injun Joe</h4> <h2>Reviews</h2> <h3>The New York Times</h3> <p>"A thrilling and heartwarming tale that will delight readers of all ages."</p> <h3>Publishers Weekly</h3> <p>"Mark Twain's classic novel is a timeless masterpiece of American literature."</p> <h2>Buy the Book</h2> <p>The Adventures of Tom Sawyer is available for purchase at all major book retailers.</p> </body> </html>


Tag Hn Usage

Headings in HTML are defined by the Tag Hn <h1> through <h6>.

The headings with the <h1> tag are considered the most important, whereas the heading with the <h6> tag is the least prominent.

IMPORTANT: Be sure to utilize one <h1> on each page – it specifies the main heading/subject for the whole page.

Additionally, ensure not to skip heading levels – start with <h1>, then <h2>, etc.


Attributes

Global

Tag Hn from <h1> to <h6> are compatible with HTML’s Global Attributes.

Event

Tag Hn from <h1> to <h6> are compatible with HTML’s Event Attributes.


Browser Compatibility

Element
<h1> – <h6>YesYesYesYesYes

Predefined CSS

When it comes to Tag Hn, a lot of browsers will render the <h1> element with the following default values:

h1 {
display: block;
font-size: 2em;
margin-top: 0.67em;
margin-bottom: 0.67em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}

The majority of browsers will render the <h2> element with the following default values:

h2 {
display: block;
font-size: 1.5em;
margin-top: 0.83em;
margin-bottom: 0.83em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}

The majority of browsers will render the <h3> element with the following default values:

h3 {
display: block;
font-size: 1.17em;
margin-top: 1em;
margin-bottom: 1em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}

The majority of browsers will render the <h4> element with the following default values:

h4 {
display: block;
font-size:
1em;
margin-top: 1.33em;
margin-bottom: 1.33em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}

The majority of browsers will render the <h5> element with the following default values:

h5 {
display: block;
font-size: .83em;
margin-top: 1.67em;
margin-bottom: 1.67em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}

The majority of browsers will render the <h6> element with the following default values:

h6 {
display: block;
font-size: .67em;
margin-top: 2.33em;
margin-bottom: 2.33em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}

HTML Hn Tag Importance

Here are some reasons why heading tags are important:

  • Heading tags create a visual hierarchy on a web page, making it easier for users to understand the structure of the content and navigate the page. They also help users to quickly scan the page and identify the most important sections.
  • Screen readers and other assistive technologies rely on heading tags to navigate a web page and provide context to visually impaired users. Properly structured heading tags can significantly improve the accessibility of a web page.
  • Heading tags provide valuable information to search engines about the structure and content of a web page. Search engines use heading tags to determine the main topic of the page and the importance of each section. Proper use of heading tags can improve a page’s visibility and ranking in search results.
  • Heading tags help to structure the content of a web page and make it easier to read and understand. They also make it easier to maintain consistency across multiple pages of a website.
  • Proper use of heading tags can help to organize the content of a web page and improve its readability. By breaking up the content into sections with meaningful headings, users can quickly find the information they need without being overwhelmed by a large block of text.
If this article was informative enough to meet your educational desires, then do share this meaningful information with your friends by clicking on the links below.
We value your feedback.
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0
+1
0

Subscribe To Our Newsletter
Enter your email to receive a weekly round-up of our best posts. Learn more!
icon

Leave a Reply

Your email address will not be published. Required fields are marked *