Dremendo Tag Line

Semantic Elements in HTML

Types of Elements

In this lesson, we will learn about the semantic elements and how to use them in HTML document.

What are Semantic Elements in HTML

Semantic elements are HTML tags that describe the meaning of content on a web page to both the browser and the developer. They are essential for creating accessible, well-structured, and SEO-friendly web pages.

video-poster

Benefits of Using Semantic Elements

Using semantic elements has several benefits, including:

  • Improved accessibility for assistive technologies like screen readers.
  • Better search engine optimization (SEO).
  • Clearer and more concise HTML code.
  • More organized and maintainable code.

Examples of Semantic Elements

There are many semantic elements available in HTML that help web developers to create more meaningful and organized web pages. The most commonly used semantic elements are:

  • <header>
  • <nav>
  • <section>
  • <article>
  • <aside>
  • <footer>

The <header> Tag

The <header> tag is used to define the introductory or navigational content at the top of a webpage or a section within a webpage. It typically contains the site's logo, website title, main navigation menu, and other related elements.

Example

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Header Tag Example</title>
</head>

<body>
    <header>
        <h1>My Website</h1>
        <nav>
            <ul>
                <li><a href="#">Home</a></li>
                <li><a href="#">About</a></li>
                <li><a href="#">Contact</a></li>
            </ul>
        </nav>
    </header>
</body>

</html>

The <nav> Tag

The <nav> tag is used to define a section of navigation links within a webpage. It represents a block of content that contains various navigation options, such as menus, lists of links, or other navigation elements.

Example

<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>

The <section> Tag

The <section> tag is used to define a standalone section of content within a webpage. It allows you to divide your content into logical sections, making it easier for search engines, assistive technologies, and developers to understand the purpose and hierarchy of the content.

Example

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Section Tag Example</title>
</head>

<header>
    <h1>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>

<section>
    <h2>About Us</h2>
    <p>We are a company dedicated to providing high-quality products and services.</p>
</section>

<section>
    <h2>Our Services</h2>
    <ul>
        <li>Web Development</li>
        <li>Graphic Design</li>
        <li>Marketing Strategy</li>
    </ul>
</section>

</html>

The <article> Tag

The <article> tag is used to define an independent, self-contained piece of content within a webpage. It represents a standalone composition, such as a blog post, news article, forum post, or any other piece of content that can be shared separately from the rest of the page.

Example

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Article Tag Example</title>
</head>

<header>
    <h1>My Blog</h1>
    <nav>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
</header>

<section>
    <article>
        <h2>Introduction to HTML</h2>
        <p>HTML stands for HyperText Markup Language...</p>
        <p>...</p>
    </article>

    <article>
        <h2>Top 10 Web Design Trends of 2023</h2>
        <p>As we enter a new year, web design trends are evolving...</p>
        <p>...</p>
    </article>
</section>

</html>

Note: An article tag may contain multiple section tags and a section tag may contain multiple article tags.

The <aside> Tag

The <aside> tag is used to define content that is slightly related to the main content of a webpage. It represents a section of content that is considered secondary, supporting, or complementary to the primary content.

It is commonly used for sidebars, pull quotes, advertisements, related links, or any content that is not directly part of the main flow of the document.

Example

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Aside Tag Example</title>
</head>

<header>
    <h1>My Blog</h1>
    <nav>
        <ul>
            <li><a href="#">Home</a></li>
            <li><a href="#">About</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </nav>
</header>

<section>
    <article>
        <h2>Introduction to HTML</h2>
        <p>HTML stands for HyperText Markup Language...</p>
        <p>...</p>
    </article>

    <aside>
        <h3>Related Links</h3>
        <ul>
            <li><a href="#">HTML Basics</a></li>
            <li><a href="#">HTML Cheat Sheet</a></li>
            <li><a href="#">HTML Best Practices</a></li>
        </ul>
    </aside>
</section>

</html>

The <footer> Tag

The <footer> tag is used to define the footer section of a webpage. It represents the bottom part of the document and typically contains information such as copyright notices, contact information, navigation links, or any other content that is relevant to the entire page.

Example

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title>Footer Tag Example</title>
</head>

<header>
    <h1>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>

<section>
    <!-- Main content of the webpage -->
</section>

<footer>
    <p>© 2023 My Website. All rights reserved.</p>
    <nav>
        <ul>
            <li><a href="#">Privacy Policy</a></li>
            <li><a href="#">Terms of Service</a></li>
            <li><a href="#">Contact Us</a></li>
        </ul>
    </nav>
</footer>

</html>