Sub topic 1
What “Semantic” Means in HTML
Prerequisites
You should know basic HTML syntax, including tags, attributes, and nesting. Familiarity with browser developer tools is useful. CSS knowledge is helpful but not required.
Meaning Before Appearance
Semantic HTML uses elements according to their meaning, not their default appearance. A nav element means “navigation,” while a main element identifies the page’s primary content. CSS can change how either element looks without changing its meaning.
Meaning helps browsers, search engines, developers, and assistive technology interpret a document. The accessibility tree is the browser’s structured representation of a page that tools such as screen readers use.
When `div` and `span` Are Right
div and span are generic containers. Use them when no more specific element describes the content.
- Use
divfor a block-level grouping, such as a layout wrapper. - Use
spanfor a phrase or other inline grouping. - Do not use them as substitutes for
button,nav,article, or other meaningful elements.
<div class="card">
<h2>Release notes</h2>
<p>Version <span class="version">2.4</span> is available.</p>
</div>The class names help CSS and scripts, but they do not give the containers semantic meaning.
Structuring a Page with Landmarks
Landmarks are major page regions that assistive technology can expose for quick navigation. Use one main region for the page’s primary content. A nav region contains navigation links. header, footer, and aside describe supporting page areas.
<header>
<a href="/">Example Site</a>
<nav aria-label="Primary">
<a href="/articles">Articles</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<h1>Latest articles</h1>
<p>Choose an article to read.</p>
</main>
<footer>Copyright Example Site</footer>Headings and Document Outline
Headings create a navigable hierarchy. Use one h1 for the page’s main topic, followed by h2 headings for major sections and h3 headings for subsections. Choose a heading because of its level, not its font size. Use CSS for visual styling.
section can group a thematic part of a page and normally has a heading. article represents content that could stand alone, such as a post or news item.
Exercise
What should replace a clickable <div class="btn">Save</div>?
Show answer
Use <button type="button">Save</button>, because a native button provides the correct meaning, focus behavior, and keyboard activation.