DEV Community

Cover image for HTML5 Semantic Elements
Muhammad Azhar Iqbal
Muhammad Azhar Iqbal

Posted on

HTML5 Semantic Elements

Hey there, Web Enthusiasts! 🎉

Today, let's talk about HTML5 Semantic Elements. Semantic elements are HTML tags that inherently carry meaning both for the browser and for the developer. Using them appropriately makes your code easier to read and accessible.

Common HTML5 Semantic Elements

Here are some of the widely-used semantic elements in HTML5:

  • <header>: The top area usually containing a logo, site title, and main navigation.
  • <footer>: The bottom part of the page usually containing copyright info, social media links, etc.
  • <article>: Represents a self-contained composition.
  • <section>: A stand-alone section that should make sense on its own.
  • <nav>: A section of a page that contains the navigation links.

Code Example

Here is a sample HTML layout using semantic elements:

<!DOCTYPE html>
<html>
<head>
  <title>Semantic Elements</title>
</head>
<body>

  <header>
    <h1>My Cool Website</h1>
  </header>

  <nav>
    <ul>
      <li><a href="#">Home</a></li>
      <li><a href="#">About</a></li>
      <li><a href="#">Contact</a></li>
    </ul>
  </nav>

  <section>
    <h2>About Us</h2>
    <p>This is the about section.</p>
  </section>

  <article>
    <h2>Blog Post Title</h2>
    <p>This is a fantastic blog post.</p>
  </article>

  <footer>
    <p>Copyright 2023, My Cool Website</p>
  </footer>

</body>
</html>
Enter fullscreen mode Exit fullscreen mode

As you can see, using these elements makes the code easier to understand compared to non-semantic elements like <div> and <span>.

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay