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

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️