Back to Top

How to use Semantic Tags in HTML

Updated 29 April 2024

Semantic HTML practices use HTML tags to convey content meaning, enhancing indexing and SEO by providing clarity to developers and search engines about webpage purposes.

Types of HTML Semantic Tags

We can define semantic tags into two categories.

For structure: A comprehensive list of semantic tags for structure along with their purposes:-

  • <header>: This tag defines introductory information or the top section of a page or section.
  • <nav>: The <nav> tag indicates navigation links, which one can place within the <header> or use independently for secondary navigation.
  • <main>: This tag specifies the main content or body of a page, and there should typically be only one <main> tag per page.
  • <section>: This tag groups nearby content with a similar theme, providing a way to organize content into meaningful chunks.
  • <aside>: Specifies content that is less important or tangentially related, often used for sidebars or additional information.
  • <article>: This tag symbolizes content capable of standing independently, ready for reuse or syndication across various contexts.
  • <footer>: Positioned at the bottom of a page, the <footer> typically includes contact information, copyright details, and additional site navigation.

For text: Some of the examples of semantic tags for text:-

  • <h1> (heading): This tag is used for the top-level heading, typically used for the main title of a page.
  • <h2> to <h6> (subheadings): Used for the subheading’s purpose, allowing for hierarchical organization of content.
  • <p> (paragraph): This tag denotes a paragraph of text, separating the content from other items.
  • <a> (anchor): Used to create hyperlinks from one page to another, enhancing navigation and connectivity.
  • <em> (emphasis): This tag indicates text that requires emphasis, usually presented in italics.
  • <strong>: This tag emphasizes text that requires strong emphasis, frequently appearing in bold.
  • <code>: Encloses a block of computer code, distinguishing it from regular text and preserving formatting.
  • <ul> (unordered list): Presents a list of items without a specific order, commonly using bullet points for each item.
  • <ol> (ordered list): Displays a list of items in a specific order, typically starting with numerical or alphabetical enumeration.
  • <dl> (description list): Displays a list of terms with its description. Here <dt> tag is used for defining the term and <dd> tag is used for describing the term.
  • <q>: Marks up quotations within the text, for shorter, inline quotes.
  • <blockquote>: Marks up quotations within the text, for longer, multi-line quotes.
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Semantic HTML Example</title>
</head>
<body>
    <header>
        <h1>Welcome to My Website</h1>
        <nav>
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Services</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </nav>
    </header>

    <main>
        <section>
            <article>
                <h2>About Us</h2>
                <p>We are a team of passionate individuals dedicated to creating meaningful web content.</p>
            </article>
        </section>
        <aside>
            <h3>Latest News</h3>
            <ul>
                <li><a href='#'>New Feature Released</a></li>
                <li><a href='#'>Upcoming Events</a></li>
            </ul>
        </aside>
    </main>

    <footer>
        <p>&copy; 2024 My Website. All rights reserved.</p>
    </footer>
</body>
</html>

Semantic Tags Best Practices

  1. Identify Content Structure: Before coding, analyze the content and identify its structural components, such as headers, navigation menus, main content, articles, and footers.
  2. Choose Appropriate Tags: After that Select the most fitting semantic HTML tags for each structural element based on its purpose.
    • For instance, use <header> for the top section containing logos and headings, <nav> for navigation menus, and <footer> for footnotes or copyright information.
  3. Nest Tags Correctly: Ensure proper nesting of semantic tags to reflect the hierarchical structure of the content.
    • For example, <header> and <footer> should be contained within the <body> tag, while <nav> and <article> should typically be inside <header> or <footer>.
  4. Avoid Overuse of Non-Semantic Tags: While <div> and <span> have their uses, try to minimize their usage in favor of semantic tags wherever possible to enhance code clarity and meaning.

Conclusion

Semantic HTML tags play a crucial role in creating well-structured, accessible, and SEO-friendly web pages.

Start your headless eCommerce
now.
Find out More

Additionally, by utilizing these tags effectively, developers can enhance the user experience, improve code readability, and ensure that their websites remain relevant and accessible in the ever-evolving digital landscape.

So, next time you’re coding a webpage, remember the power of semantics in HTML and make your content speak volumes with meaningful tags.

Start your Headless Development with Webkul.

. . .

Leave a Comment

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


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home