Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

HTML CSS - Semantic HTML

Using semantic HTML tags for better structure

Semantic HTML tags provide meaning to the web content and improve the structure and accessibility of web pages. Using semantic tags helps search engines and other user devices to interpret the content of the page more accurately. This tutorial covers the usage of semantic HTML tags for better structure.

Key Points:

  • Semantic HTML tags provide meaning to the content.
  • Improves the structure and accessibility of web pages.
  • Helps search engines and other user devices to interpret the content more accurately.

Common Semantic HTML Tags

Here is a list of some common semantic HTML tags and their usage:

  • <header>: Defines a header for a document or section.
  • <nav>: Defines a container for navigation links.
  • <main>: Specifies the main content of a document.
  • <article>: Defines an independent, self-contained content.
  • <section>: Defines a section in a document.
  • <aside>: Defines content aside from the main content (e.g., sidebar).
  • <footer>: Defines a footer for a document or section.
  • <figure>: Specifies self-contained content, like illustrations or diagrams.
  • <figcaption>: Defines a caption for a <figure> element.
  • <time>: Represents a specific time or date.

Using Semantic Tags

Here is an example of using semantic HTML tags to create a well-structured web page:


<!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>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>
    <main>
        <article>
            <header>
                <h2>Article Title</h2>
                <time datetime="2023-01-01">January 1, 2023</time>
            </header>
            <p>This is the content of the article.</p>
            <figure>
                <img src="image.jpg" alt="Description of image">
                <figcaption>Caption for the image.</figcaption>
            </figure>
        </article>
        <section>
            <h2>Section Title</h2>
            <p>This is the content of the section.</p>
        </section>
        <aside>
            <h2>Sidebar</h2>
            <p>This is the sidebar content.</p>
        </aside>
    </main>
    <footer>
        <p>© 2023 My Website</p>
    </footer>
</body>
</html>
            

In this example, semantic tags are used to create a clear structure for the web page, including a header, navigation, main content area, articles, sections, aside, and footer.

Benefits of Semantic HTML

Using semantic HTML tags offers several benefits:

  • Improved Accessibility: Semantic tags help screen readers and other assistive technologies understand the content and structure of a web page.
  • Better SEO: Search engines use semantic tags to understand the content and context of a web page, which can improve search rankings.
  • Enhanced Readability: Semantic tags provide a clear and meaningful structure, making the HTML code easier to read and maintain.
  • Future-Proof: Using semantic tags ensures that your web pages adhere to current web standards and are more likely to be compatible with future technologies.

Additional Semantic Tags

In addition to the common semantic tags mentioned earlier, there are several other semantic tags that can be used to enhance the structure and meaning of your content:

  • <mark>: Highlights text for reference or notation.
  • <summary>: Defines a summary or caption for the <details> element.
  • <details>: Specifies additional details that the user can view or hide.
  • <output>: Represents the result of a calculation or user action.
  • <progress>: Represents the completion progress of a task.
  • <meter>: Represents a scalar measurement within a known range.

Summary

In this tutorial, you learned about the importance of semantic HTML and how to use semantic tags to create a well-structured web page. Using semantic HTML tags provides meaning to the content, improves accessibility, enhances SEO, and makes your HTML code more readable and maintainable. By incorporating semantic tags into your web development practices, you can create more robust and future-proof web pages.