HTML Headings
HTML Headings
HTML headings define the hierarchy (levels) and structure of content on a webpage. They create a visual hierarchy, with the highest-level heading, which is h1 , indicating the most important content or the main heading, and lower-level headings like h2 , h3 , h4 , etc. for subtopics.
Reason to use Headings
Headings are crucial for structuring content and providing a clear visual indication of the beginning of new sections or topics. Properly structured headings enhance readability and user experience on websites, ensuring that information is organized and easy to navigate.
-
Heading Impact on SEO: The well-organized headings help search engines to understand the content structure and indexing.
-
Highlighting Important Topics: The use of heading tags properly keeps the content readable.
HTML Heading Tags
The headings are defined with headings tags ( <h1> to <h6> ). It is important to use heading tags to show the content structure on a webpage. HTML has a different level of heading tags. The hierarchy determines the importance of content and aids in creating a clear information flow for both users and search engines.
Example
The following example shows the different levels of the HTML heading β
Hierarchical Structure of Heading Tags
Below is the list according to the hierarchy of the heading tags (most to least significant) β
- The
<h1>Tag β The top-level heading denotes the main topic or title of the entire page.
The <h1> Tag β The top-level heading denotes the main topic or title of the entire page.
- The
<h2>Tag β Subheadings under<h1>represent major sections related to the main topic. They provide a more specific context to the content.
The <h2> Tag β Subheadings under <h1> represent major sections related to the main topic. They provide a more specific context to the content.
- The
<h3>to<h6>Tags β These tags are used for further subsections or nested content within<h2>headings. They offer a deeper level of hierarchy for organizing content within specific sections.
The <h3> to <h6> Tags β These tags are used for further subsections or nested content within <h2> headings. They offer a deeper level of hierarchy for organizing content within specific sections.
Examples of HTML Headings
In these examples, you will see the usage of all the heading tags to create different types of headings and styling them using the CSS β
Headings Using <h1> to <h6> Tags
In this example, we will use the heading tags (h1 to h6); each of them has a different size and weight for the content β
Styling Headings With CSS
In the following example, we will apply the style such as font family , font color , font size , etc. to the headings β
Here, we have applied β Verdana β font style to all heading tags, defined the β Red β color to H1 heading with the font size 32px , and defined the β Green β color to H2 heading with the font size 30px .
Using HTML Tags Within Heading Tags
HTML headings (h1 to h6) serve as the main titles and subheadings for content organization. Within these heading tags, you can use various other HTML tags to enhance and structure your content effectively. Here are some examples β
The <span> Tag
You can use the <span> tag to apply inline styles or classes to specific portions of the text within a heading. This allows for custom styling of text within the heading.
The <a>Tag for Links
To create a link within a heading, use the <a> tag . This is useful for headings that lead to other pages or sections of your website.
The <em> and <strong> Tags
These tags are used for emphasizing text within headings. The <em> tag italicizes the text, while <strong> makes it bold.
The <sup> and <sub> Tags
In heading, to include superscript or subscript text within a heading, use <sup> and <sub> .
The <abbr> Tag for Abbreviations
When you need to include an abbreviation or acronym in a heading, use the <abbr> tag. It often provides a tooltip with the full meaning.
The <br> Tag for Line Breaks
Sometimes, you might want to create line breaks within a heading for better formatting. The <br> tag serves this purpose.
The <mark> Tag
Use the <mark> tag to highlight specific text within a heading. Itβs often used to indicate search results or selected portions of text.
Mistakes to be Avoided
Make sure we avoid the following mistakes while using the heading tag β
-
Skipping Levels β Always follow the proper hierarchy (h1, h2, h3, etc.). Donβt skip levels.
-
Overusing h1 β Reserve h1 for the main title; donβt use it multiple times on a page.
-
Styling Overload β Avoid excessive styling; CSS should handle the aesthetics, not headings.