DEV Community

Sidra Maqbool
Sidra Maqbool

Posted on

Mastering Semantic HTML: A Guide to Using All 16 Semantic Tags with Example

Semantic HTML refers to the use of HTML elements that convey meaning beyond just the presentation of the content. This means using HTML tags that accurately describe the content they contain. For example, using the <header> tag to indicate the header section of a page, the <nav> tag to indicate a navigation menu, and the <article> tag to indicate a standalone piece of content. By using semantic HTML, you provide a clear and meaningful structure to your content that can be easily understood by both humans and machines, such as search engines and screen readers.

Semantic HTML helps search engines and assistive technologies better understand the content of a web page, making it more accessible and improving its ranking in search results.

There are a variety of semantic HTML tags that can be used to mark up different types of content on a web page. Here is a list of the most commonly used semantic HTML tags:

<header>: Defines a header for a document or section
<nav>: Defines a navigation section
<main>: Defines the main content of a document
<article>: Defines an article or independent piece of content within a document
<section>: Defines a section of a document
<aside>: Defines content that is related to the surrounding content but not central to the overall meaning
<footer>: Defines a footer for a document or section
<h1> to <h6>: Defines headings of different levels
<p>: Defines a paragraph
<ul>: Defines an unordered list
<ol>: Defines an ordered list
<li>: Defines a list item
<figure>: Defines self-contained content, such as an image, diagram, or code snippet, that is referenced in the main content of the document
<figcaption>: Defines a caption for a element
<time>: Defines a specific time or range of time
<address>: Defines contact information for the author or owner of a document or article.

Here's an example that includes all of the semantic HTML tags:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Example of Semantic HTML Tags</title>
  </head>
  <body>
    <header>
      <nav>
        <ul>
          <li><a href="#">Home</a></li>
          <li><a href="#">About</a></li>
          <li><a href="#">Contact</a></li>
        </ul>
      </nav>
      <h1>Welcome to our website</h1>
      <p>We provide the best services to our customers.</p>
    </header>
    <main>
      <section>
        <h2>Our Services</h2>
        <article>
          <h3>Service 1</h3>
          <p>We offer a wide range of services to meet your needs.</p>
          <ul>
            <li>Service 1a</li>
            <li>Service 1b</li>
            <li>Service 1c</li>
          </ul>
        </article>
        <article>
          <h3>Service 2</h3>
          <p>We have the best professionals in the field to provide you with top-quality service.</p>
          <ul>
            <li>Service 2a</li>
            <li>Service 2b</li>
            <li>Service 2c</li>
          </ul>
        </article>
      </section>
      <aside>
        <h2>About Us</h2>
        <p>We are a team of dedicated professionals committed to providing the best services to our customers.</p>
        <img src="team.jpg" alt="Our team">
      </aside>
    </main>
    <footer>
      <p>Copyright &copy; 2023</p>
      <address>
        123 Main St<br>
        Anytown, USA<br>
        12345
      </address>
    </footer>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

You can also check the live example on GitHub.
These tags help to provide more meaning to the content of a webpage, making it easier for search engines and screen readers to understand the structure and purpose of the content.

In conclusion, using semantic HTML tags is an important aspect of modern web development. It not only helps search engines better understand and index your content, but also improves accessibility and overall user experience. By using semantic tags correctly, you can create a more organized and understandable structure for your web page, making it easier to maintain and update. So next time you create a web page, remember to use semantic HTML tags for a more efficient and effective markup.

Thanks for reading! I hope you found this post informative and helpful. If you have any questions or feedback, please feel free to leave a comment below!

Top comments (1)

Collapse
 
rojblake1978 profile image
rojblake1978

Great Post!! Thanks for effort putting this information together...