Careeroza
Semantic Elements
What are Semantic Elements?
A semantic element clearly describes its meaning to both the browser and the developer. <div> and <span> say nothing about their content; <form>, <table> and <article> clearly do.
| Element | Defines |
|---|---|
<header> | introductory content or a group of navigation links |
<nav> | a set of navigation links |
<main> | the main content of the page (one per page) |
<section> | a thematic group of content, usually with a heading |
<article> | self-contained content: a blog post, a news story, a comment |
<aside> | content aside from the main content: a sidebar |
<footer> | footer for a page or section: author, copyright, links |
<figure> / <figcaption> | an image or diagram with its caption |
<time> | a date or time, machine readable |
Why Use Semantic Elements?
- Accessibility: screen readers offer shortcuts to jump to
<nav>,<main>and headings. - SEO: search engines understand which part is the main content.
- Readable code:
<footer>is clearer than<div class="footer">.
Example
Example
A blog post marked up semantically:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<article>
<header>
<h2>Learning HTML in 30 days</h2>
<p>By Asha · <time datetime="2024-06-01">1 June 2024</time></p>
</header>
<p>Day one: understanding elements and attributes...</p>
<figure>
<img src="https://picsum.photos/id/0/200/100" alt="Laptop on a desk" width="200" height="100">
<figcaption>My study setup</figcaption>
</figure>
<footer>Tags: html, beginners</footer>
</article>
</body>
</html>Result