Welcome to My Website
This is the main article content where information is presented.
Semantic elements in HTML are tags that clearly describe the meaning and purpose of the content they contain. Instead of relying only on generic containers like <div> and <span>, semantic tags tell browsers, developers, assistive technologies, and search engines what each part of the page represents.
Using semantic elements leads to well-structured, accessible, and SEO-friendly web pages. They give your layout a logical outline, which improves navigation and the overall user experience.
<header> — Top section of a page or section.<nav> — Navigation links.<main> — Main content of the document (only one per page).<section> — Thematic grouping of content.<article> — Self-contained content like posts or news items.<aside> — Related content such as sidebars or callouts.<footer> — Footer of the page or a section.A typical semantic layout uses landmark elements to describe the overall page structure. The example below shows how these pieces fit together.
<!-- Semantic HTML example -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Semantic Elements Example</title>
</head>
<body>
<header>
<h1>My Website</h1>
<nav aria-label="Primary" role="navigation">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h2>Welcome to My Website</h2>
<p>This is the main article content where information is presented.</p>
</article>
<aside>
<h3>Related Links</h3>
<ul>
<li><a href="#">Resource 1</a></li>
<li><a href="#">Resource 2</a></li>
</ul>
</aside>
</main>
<footer>
<p>© 2025 My Website</p>
</footer>
</body>
</html>
Below is a simplified visual rendering of the previous semantic HTML example. The structure is the same: header and navigation at the top, main content and sidebar in the middle, and a footer at the bottom.
This is the main article content where information is presented.
<div> into accessible semantic structures.<article> inside a larger <section>.<aside> for filters, tips, or related tools.<nav> and aria-label.<div> and <span> when a semantic element exists.<main> per page and do not nest it inside <header> or <footer>.<article> for self-contained content that could stand alone (blog posts, news stories, forum posts).<section> should generally start with a heading to keep the document outline meaningful.<nav> an accessible name with aria-label if you have multiple navigation regions.<div> into clear landmarks: <header>, <nav>, <main>, <aside>, and <footer>.aria-label="Footer". Try navigating with a screen reader or accessibility tool.<article> elements inside a <section>, each with its own heading and a <time> element.<h1> to <h6>) and ensure they form a logical outline without skipping levels unnecessarily.<header>, <nav>, <main>, <aside>, and <footer> improves accessibility and SEO.<article> and <section> help organise content into logical blocks with clear headings.<div> containers with semantic elements results in cleaner, easier-to-maintain HTML.