BeginnerLesson 2 of 15
Semantic HTML & Page Structure – HTML & CSS
The right elements for header, navigation, content and footer – for people, search engines and screen readers.
Semantics means: an element describes its meaning, not its appearance. Instead of writing <div> everywhere, you use <header>, <nav>, <main>, <article>, <section>, <aside> and <footer>. Screen readers recognize these "landmarks" and allow jumping between regions; search engines understand the structure better.
<!DOCTYPE html>
<style>body{font:16px system-ui,sans-serif;margin:12px;background:#fff;color:#222}
:is(header,nav,main,article,aside,footer,section){border:2px dashed #999;margin:6px;padding:6px}
:is(header,nav,main,article,aside,footer,section)::before{display:block;font:12px monospace;color:#c33}
header::before{content:"<header>"} nav::before{content:"<nav>"} main::before{content:"<main>"}
article::before{content:"<article>"} aside::before{content:"<aside>"} footer::before{content:"<footer>"}
</style>
<header><h1>My Blog</h1></header>
<nav><a href="#a">Home</a> | <a href="#b">About Me</a></nav>
<main>
<article><h2>First Post</h2><p>Content of the post …</p></article>
<aside>Ads or extra info</aside>
</main>
<footer>© 2024 Blog</footer>Important rules: there is exactly one <main> per page. <article> is self-contained content (a post, a product card), <section> a thematic section that usually has its own heading. <div> and <span> are neutral containers without meaning – they are fine when no more fitting element exists.
<!DOCTYPE html>
<style>body{font:16px system-ui,sans-serif;margin:12px;background:#fff;color:#222}
figure{margin:0;padding:8px;background:#f4f4f4;display:inline-block}
figcaption{font-size:.85rem;color:#555}
blockquote{margin:10px 0;padding-left:12px;border-left:4px solid #e34f26}
</style>
<figure>
<svg width="120" height="60" role="img" aria-label="Blue rectangle"><rect width="120" height="60" fill="#3178c6"/></svg>
<figcaption>Fig. 1: A rectangle as <code>figure</code></figcaption>
</figure>
<blockquote>Programs must be written for people to read.
<cite>– Abelson & Sussman</cite></blockquote>
<p>Published on <time datetime="2024-05-01">May 1, 2024</time>,
keyword: <mark>semantic</mark></p>TipA good test: can you understand the page if you only read the headings and landmarks? Then the structure is clean. Buttons are
<button>, links are <a href> – never a <div onclick>, because then keyboard operation and role are missing.WarningDo not choose heading levels because of size (that is what CSS is for) and do not skip levels (h1 straight to h4). Screen reader users navigate via the heading structure.