HTML & CSSEasy
What are semantic tags?
Semantic tags are HTML elements whose names describe the meaning of their content, such as <header>, <nav>, <main>, <article>, <aside>, <footer>, <button> and <time>. Unlike generic <div> and <span>, they tell browsers, assistive technologies and search engines what each part of the page is.
Why they matter
- Accessibility: screen readers expose landmarks (
banner,navigation,main,contentinfo) and let users jump between them. Semantic controls like<button>are keyboard-focusable and announced correctly for free. - SEO: search engines understand page structure, main content and articles better.
- Maintainability: code reads like a document outline.
- Default behavior:
<details>toggles,<dialog>traps focus as a modal,<a href>navigates,<form>submits, all without JavaScript.
Semantic vs non-semantic
- Non-semantic:
<div>,<span>. They mean nothing; use them only for styling or grouping when no element fits. - Semantic: everything with a specific meaning, including inline ones like
<strong>,<em>,<code>,<abbr>,<mark>,<time datetime>.
Common mistakes
- Div soup:
<div class="button" onclick=...>instead of<button>. It is not focusable or announced as a button. - Using headings for size rather than structure; style headings with CSS instead.
- Multiple visible
<main>elements. - Using
<section>as a generic wrapper; a section should have a heading.
Rule of thumb
Pick the element that describes what the content is; if nothing fits, use a <div> or <span>.
Code example
html
1<style>2 body { font-family: system-ui; margin: 0; }3 header, footer { background: #eef2ff; padding: 8px 16px; }4 main { display: grid; grid-template-columns: 1fr 160px; gap: 16px; padding: 16px; }5 aside { background: #f8fafc; padding: 8px; }6</style>7<header>8 <strong>DevQnA</strong>9 <nav aria-label="Main"><a href="#">Home</a> · <a href="#">Topics</a></nav>10</header>11<main>12 <article>13 <h1>Understanding semantic HTML</h1>14 <p>Published <time datetime="2026-11-21">21 Nov 2026</time></p>15 <section>16 <h2>Why it matters</h2>17 <p>Screen readers announce <strong>landmarks</strong> and <em>headings</em>.</p>18 </section>19 <button type="button">Bookmark</button>20 </article>21 <aside><h2>Related</h2><a href="#">ARIA basics</a></aside>22</main>23<footer><small>© 2026 DevQnA</small></footer>
Practice this question
Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the HTML & CSS set.