Sub topic 8
Semantic HTML: lists, tables and clean sections
This chapter assumes you know basic HTML (headings, paragraphs, lists, tables) and have already read the chapters on answer-first structure, question-led headings and self-contained passages. Here you will see how the markup itself helps retrieval systems split a page into clean passages and recognise lists, tables and sections for what they are.
Why markup matters for retrieval
A crawler or retrieval pipeline rarely feeds raw HTML to a language model. It usually converts the page to text or Markdown, splits that text into chunks, and indexes the chunks. Markup survives this conversion only when it carries meaning. A <h2> becomes a heading boundary. An <ol> becomes a numbered list. A <table> becomes rows and columns. A <div class="fancy-box"> becomes plain text with no signal at all.
Semantic HTML means using elements for what they mean, not for how they look. If you use a heading element, the text is a heading. If you use a list element, the items are a list. Retrieval systems cannot see your CSS, so meaning has to live in the elements.
No vendor publishes exactly how its pipeline parses pages, and those pipelines change. Treat semantic HTML as a way to remove ambiguity, not as a lever that guarantees a result. It is also good for accessibility and for classic search engines, so the effort pays off even if an AI system ignores it.
Sections and heading hierarchy
A clean section has one heading, an answer in the opening sentences, and content that stays on that topic. Chunkers often split at headings, so the heading hierarchy decides where one passage ends and the next begins.
Rules to follow:
- Use one
<h1>per page, for the page title. - Use
<h2>for each major question or topic, and<h3>for sub-points within it. - Never skip levels (an
<h2>followed directly by an<h4>) and never pick a level for its font size. - Wrap each question and its answer in a
<section>with anidand a heading, so the unit is explicit. - Keep one idea per section. If a section answers two questions, split it.
<article>
<h1>Caching API responses</h1>
<section id="how-long-to-cache">
<h2>How long should I cache API responses?</h2>
<p>Cache API responses for as long as the data can be stale without harming users. For data that changes a few times a day, a TTL of 5 to 15 minutes is a common starting point.</p>
</section>
<section id="when-to-invalidate">
<h2>When should I invalidate a cache early?</h2>
<p>Invalidate early when a write changes data that users must see immediately, such as a price or a stock count.</p>
</section>
</article>The id on each section also gives you a stable anchor URL such as /caching#how-long-to-cache. Some systems link to the specific fragment, and people can share it.
Lists for steps and sets
Use a list when the content is a sequence or a set. Use an ordered list (<ol>) when order matters, such as a procedure. Use an unordered list (<ul>) when it does not, such as a set of options.
A list works well as a quotable passage because each item is short and the boundaries are explicit. A good list has these properties:
- A lead-in sentence that states what the list contains, placed directly before it.
- Items that are parallel in form (all start with a verb, or all are noun phrases).
- Items that make sense without the lead-in where possible.
- No more than about seven to ten items. Longer lists should be grouped under subheadings.
Compare two versions of the same steps.
<!-- Weak: line breaks and manual numbers -->
<p>
1. Pick the URL you want people to land on.<br>
2. Use the full absolute URL.<br>
3. Add the same canonical link to every duplicate page.
</p>
<!-- Better: a real ordered list -->
<p>To set a canonical URL, follow these steps:</p>
<ol>
<li>Pick the URL you want people to land on.</li>
<li>Use the full absolute URL, including the protocol.</li>
<li>Add the same canonical link to every duplicate page.</li>
</ol>In the weak version, a converter sees one paragraph with numerals in it. It may keep the numbers, or it may merge the lines into one sentence. In the better version the structure is unambiguous.
Common list mistakes
- Using
<br>or<p>tags with typed bullets instead of<ul>and<li>. - Using a list for content that is really prose, such as one long sentence cut into fragments.
- Putting a whole paragraph in each
<li>. If an item needs several sentences, make it a subsection. - Nesting lists three or four levels deep. Flattened text loses the nesting.
Tables for comparisons
Use a table when you compare several things across the same attributes. A table gives a retrieval system a grid of facts that is hard to get from prose, and it suits questions such as "what is the difference between X and Y".
Use real table elements: <table>, <thead>, <tbody>, <tr>, <th> and <td>. Add a <caption> that says what the table shows. Put header cells in <th> with a scope attribute so that each data cell is tied to its row and column header.
<table>
<caption>Cache invalidation strategies compared</caption>
<thead>
<tr>
<th scope="col">Strategy</th>
<th scope="col">Freshness</th>
<th scope="col">Complexity</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Time-based expiry (TTL)</th>
<td>Stale until the TTL ends</td>
<td>Low</td>
</tr>
<tr>
<th scope="row">Event-based invalidation</th>
<td>Fresh right after a write</td>
<td>Higher</td>
</tr>
</tbody>
</table>When text conversion flattens this table, each row can still be read as "Time-based expiry (TTL): stale until the TTL ends, low complexity". That works only because every cell has a clear header.
Table rules for quotable content:
- Make every row and column header explicit. Do not leave the top-left cell or any header cell empty if you can avoid it.
- Avoid merged cells (
rowspan,colspan). Many converters cannot represent them and the grid breaks. - Keep cells short. A cell holding three paragraphs is a sign you need prose instead.
- Do not use tables for page layout. Layout tables produce nonsense when flattened.
- Do not put a table inside an image. Text in an image is often not read at all.
- Repeat the key finding in a sentence near the table. A table alone may be separated from its explanation by the chunker.
Definitions, emphasis and other elements
Several smaller elements add meaning at low cost.
| Element | Use it for | Avoid |
|---|---|---|
| `<dl>`, `<dt>`, `<dd>` | Term and definition pairs, such as a glossary | Using it for layout |
| `<strong>` | Marking text of real importance, such as a key term on first definition | Bolding whole paragraphs |
| `<code>` | Inline commands, element names and values | Styling ordinary words |
| `<pre><code>` | Multi-line code, with a language class | Code as a screenshot |
| `<time datetime="2026-11-29">` | Dates, such as a last-updated stamp | Free-text dates only |
| `<a href>` with descriptive text | Linking to a source | Link text such as "click here" |
A definition list is a good fit for a glossary:
<dl>
<dt>Canonical URL</dt>
<dd>The preferred address of a page when the same content is reachable at several URLs.</dd>
<dt>TTL</dt>
<dd>Time to live: how long a cached response may be reused before it must be fetched again.</dd>
</dl>Descriptive link text also matters for attribution. A link labelled "the 2024 HTTP caching specification" tells a reader and a parser what the target is. A link labelled "here" tells them nothing.
How markup becomes passages
The diagram below shows a simplified path from your HTML to a quoted passage. Real systems differ in the details, but the principle holds: structure that is explicit in the HTML is more likely to still be explicit after conversion and chunking.
Each stage can lose information. Conversion drops CSS and may drop script-rendered content. Splitting may cut a list from its lead-in or a table from its caption. Selection compares each passage with the question on its own. That is why the earlier chapters stressed self-contained passages, and why the markup rules here keep the pieces of one passage together: the heading, the lead-in sentence, the list or table, and the sentence that states the finding.
Validating your markup
Check the markup before you assume it works.
- Run the page through an HTML validator to catch unclosed tags and invalid nesting.
- View the page with CSS and JavaScript disabled, or fetch it with
curl, and confirm the answer text is present. - Convert the page to Markdown with a tool of your choice and read the output. Check that headings, lists and tables survive.
- Check the heading outline with a browser extension or accessibility tool. It should read like a table of contents with no gaps.
The following script gives a quick outline of the headings in a saved page. It needs Python 3 and no extra packages.
from html.parser import HTMLParser
class Outline(HTMLParser):
def __init__(self):
super().__init__()
self.level = None
self.text = ""
self.last = 0
self.problems = []
def handle_starttag(self, tag, attrs):
if len(tag) == 2 and tag[0] == "h" and tag[1] in "123456":
self.level = int(tag[1])
self.text = ""
def handle_data(self, data):
if self.level:
self.text += data
def handle_endtag(self, tag):
if self.level and tag == f"h{self.level}":
print(" " * (self.level - 1) + f"h{self.level}: {self.text.strip()}")
if self.last and self.level > self.last + 1:
self.problems.append(f"Skipped from h{self.last} to h{self.level}")
self.last = self.level
self.level = None
html = """
<h1>Caching API responses</h1>
<h2>How long should I cache API responses?</h2>
<h4>Choosing a TTL</h4>
"""
parser = Outline()
parser.feed(html)
for problem in parser.problems:
print("Problem:", problem)Running it prints the indented outline and then Problem: Skipped from h2 to h4. Replace the sample string with the contents of your own file to audit a real page.
Limits
Semantic HTML does not make a page get cited. It removes avoidable obstacles. A well-marked page with vague, unsupported content will still lose to a plainer page with a clear, specific answer. Equally, a clear answer inside a broken structure can be mangled. Treat markup as a supporting layer under the writing, not a replacement for it.
Exercise
A page has a comparison of three pricing plans built from <div> elements styled as a grid, with the plan names in bold text. Why might a retrieval system fail to quote it accurately, and what would you change?
Show answer
After conversion to text, the divs carry no row or column meaning, so the plan names and their features run together and cannot be matched. Replace the grid with a <table> that has a <caption>, <th scope="col"> headers for the plan attributes, and <th scope="row"> cells for the plan names. Add one sentence near the table that states the main difference between the plans.
Exercise
Your page shows a five-step setup procedure as paragraphs that begin with "Step 1:", "Step 2:" and so on, separated by <br> tags. Rewrite the markup so the sequence is explicit, and name one thing to add before the steps.
Show answer
Use an <ol> with one <li> per step, such as <ol><li>Install the package.</li><li>Create the config file.</li></ol> and so on for all five steps. Add a lead-in sentence before the list that says what the procedure achieves, for example "To set up the tool, follow these steps:", so the list keeps its context if it is lifted out.