Sub topic 2
Use Semantic HTML, Not Styling, to Express Structure
Why does semantic HTML help AI answer systems?
Semantic HTML names the role of each part of a page. A main element identifies the primary content, a nav element identifies navigation, and a table element identifies related values arranged in rows and columns. Retrieval systems can use these signals when they split a page into passages and decide which passage answers a question.
This chapter assumes that you know basic HTML, can edit a web page, and understand that search engines retrieve text before displaying search results.
What does semantic HTML communicate?
Semantic HTML communicates meaning through element names and relationships. CSS controls how elements look. For example, CSS can make a div look like a heading, but the div still has no heading meaning in the document structure.
| Element | Meaning | Typical use |
|---|---|---|
| `main` | Primary page content | The central tutorial or article |
| `section` | A related group of content | A topic with its own heading |
| `h2` | A second-level heading | A major subsection |
| `ol` | An ordered list | Steps where sequence matters |
| `table` | Data in rows and columns | Comparing plans or features |
A meaningful structure helps both machines and people. Screen readers can navigate headings and landmarks. Retrieval systems can associate a passage with the heading that introduces it.
How should you separate structure from styling?
Use semantic elements for meaning and CSS for appearance. The following page uses elements whose names describe their roles:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Router Reset Guide</title>
<style>
.warning {
border: 2px solid darkred;
padding: 1rem;
}
</style>
</head>
<body>
<main>
<article>
<h1>How to Reset a Router</h1>
<section>
<h2>What does a factory reset do?</h2>
<p>
A factory reset erases saved settings and restores the router
to its default configuration.
</p>
</section>
<section>
<h2>How do you reset the router?</h2>
<ol>
<li>Turn on the router and wait for it to start.</li>
<li>Hold the reset button for 10 seconds.</li>
<li>Wait for the router to restart.</li>
</ol>
</section>
<aside class="warning">
Save your network settings before resetting the router.
</aside>
</article>
</main>
</body>
</html>The class="warning" attribute lets CSS style the aside. It does not change the fact that aside represents related but secondary content. A page made from many div elements might look identical, but it gives fewer structural clues.
Which elements should you choose for content?
Choose the element that matches the content's job.
- Use
pfor a normal paragraph. - Use
sectionfor a thematic group with a heading. - Use
articlefor content that could stand on its own, such as a tutorial or review. - Use
ulwhen list order does not matter. - Use
olwhen readers must follow a sequence. - Use
tablefor data relationships, not for page layout. - Use
navfor a group of navigation links. - Use
asidefor supporting content that is related to the main content.
Do not use a heading only because its font size looks right. Do not use a table to position cards or columns. CSS layout tools such as Grid and Flexbox express visual arrangement; they do not replace semantic elements.
How does structure flow into retrieval?
A simplified retrieval process can be represented like this:
A heading alone is not enough. The content beneath it must answer the heading clearly, and the markup must reflect the relationship. A styled div with a large font may look like a heading to a visitor, but it does not create the same document outline for software.
What are common semantic HTML mistakes?
Common mistakes include:
- Using several
h1elements for visual emphasis instead of one page-level title. - Jumping from
h2toh4because the smaller text looks better. - Putting every passage inside unrelated
divelements. - Using bold text instead of a heading for a new topic.
- Using a table for layout.
- Adding ARIA roles to compensate for incorrect native elements when a correct HTML element is available.
When a generic element is unavoidable, add clear surrounding structure and use ARIA only when its semantics are needed. Native HTML usually provides the simplest and most reliable meaning.
Exercise
A page uses a styled div as a heading, then places a paragraph and an ordered list inside another div. What should you change first?
Show answer
Replace the heading div with the appropriate h1, h2, or h3, then use a semantic container such as section and keep the ordered list as ol.