Semantic HTML5 Elements: `<article>`, `<aside>`, `<nav>`
Improve your website's structure, SEO, and accessibility with Semantic HTML. This tutorial explains the meaning and usage of key semantic elements like `<article>`, `<aside>`, `<nav>`, `<header>`, `<footer>`, and more, providing code examples and best practices for modern web development.
Understanding and Using Semantic HTML Elements
Semantic HTML uses elements that clearly describe their meaning, making your code more understandable, maintainable, and accessible. This improves SEO and makes your website more user-friendly for everyone, including assistive technologies.
What are Semantic Elements?
Semantic elements convey meaning beyond just visual presentation. For example, <p>
(paragraph) and <h1>
(heading) are semantic because they tell the browser and developers the *purpose* of the enclosed content. Non-semantic elements, like <div>
and <span>
, are generic containers without inherent meaning.
Key Semantic Elements
HTML5 introduced several semantic elements to improve web page structure and meaning. Let's explore some key ones:
`<section>` Element
The <section>
element represents a thematic grouping of content, often with a heading. It's useful for dividing a page into logical sections (e.g., introduction, main content, contact information).
Example: `<section>`
<section>
<h2>WWF</h2>
<p>The World Wide Fund for Nature (WWF)...</p>
</section>
`<article>` Element
The <article>
element defines self-contained content that can stand alone. Examples include blog posts, news articles, forum posts.
Example: `<article>`
<article>
<h3>Google Chrome</h3>
<p>Google Chrome is a web browser...</p>
</article>
(Further examples showing styling with CSS would be added here.)
`<header>` Element
The <header>
element introduces a section or page. It typically contains headings, a logo, navigation, or author information. You can't nest a <header>
inside another <header>
, <footer>
, or <article>
.
Example: `<header>`
<header>
<h1>What Does WWF Do?</h1>
</header>
`<footer>` Element
The <footer>
element contains closing information for a document or section (copyright, contact details, links, etc.).
Example: `<footer>`
<footer>
<p>Author: Hege Refsnes</p>
</footer>
`<nav>` Element
The <nav>
element contains navigation links. It's intended for major navigation blocks, not every link on a page.
Example: `<nav>`
<nav>
<a href="#">Home</a> | <a href="#">About</a>
</nav>
`<aside>` Element
The <aside>
element contains content tangentially related to the main content (like a sidebar).
Example: `<aside>`
<aside>
<p>Related Information...</p>
</aside>
(Example showing CSS styling would be added here.)
`<figure>` and `<figcaption>` Elements
The <figure>
element groups self-contained content like illustrations, diagrams, photos, code snippets, etc. The <figcaption>
element provides a caption for the <figure>
content.
Example: `<figure>` and `<figcaption>`
<figure>
<img src="image.jpg" alt="Image Description">
<figcaption>Fig. 1 - Image Caption</figcaption>
</figure>
Why Use Semantic Elements?
Semantic HTML makes your code more understandable, improves SEO, enhances accessibility for users with disabilities, and promotes better data sharing and reuse across applications. It's a best practice for modern web development.
Summary Table
Element | Description |
---|---|
<article> |
Self-contained content |
<aside> |
Content aside from the main content |
<details> |
Details that can be shown/hidden |
<figcaption> |
Caption for a figure |
<figure> |
Self-contained content (illustration, diagram, etc.) |
<footer> |
Footer for a document or section |
<header> |
Header for a document or section |
<main> |
Main content of a document |
<mark> |
Highlighted text |
<nav> |
Navigation links |
<section> |
Thematic grouping of content |
<summary> |
Visible heading for a details element |
<time> |
Date/Time |