CodesCompiler
πŸ”
HTMLCSSJavaScriptPythonSQLPHPSEOPostsBooksKids About Contact πŸš€ Get Started Free

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 βˆ’

Preview

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 βˆ’

Preview

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 βˆ’

Preview

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.

Preview

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.

Preview

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.

Preview

The <sup> and <sub> Tags

In heading, to include superscript or subscript text within a heading, use <sup> and <sub> .

Preview

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.

Preview

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.

Preview

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.

Preview

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.