Sub topic 3
Use Tables for Comparisons Across Attributes
This chapter assumes you know basic HTML elements (headings, paragraphs, lists, tables), have seen how search results display pages, and have edited web content before.
When a table beats prose
A table fits when several items share the same attributes, such as price, user limit, or setup time. AI answer systems split a page into passages and quote the passages that match a question. A table with a caption and header cells gives each value a clear label, so a passage can be quoted without its surrounding text.
<table>
<caption>Plan comparison</caption>
<thead>
<tr>
<th scope="col">Plan</th>
<th scope="col">Monthly price</th>
<th scope="col">Users</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Basic</th>
<td>$10</td>
<td>1</td>
</tr>
<tr>
<th scope="row">Team</th>
<td>$40</td>
<td>10</td>
</tr>
</tbody>
</table>Choosing between prose, lists, and tables
Add structured data that matches the visible page
Optional JSON-LD markup can describe a page to machines. Its text must repeat what readers already see. Markup that describes content hidden from readers can be ignored or penalized, and structured data does not guarantee a citation.
Avoid common structural mistakes
- Skipping heading levels, such as an h1 followed by an h3.
- Using two h1 elements on one page.
- Using tables for page layout instead of data.
- Leaving table header cells as plain td elements.
- Writing JSON-LD answers that differ from the page text.
Audit and test your page structure
The script below reports a missing or duplicate h1 and any skipped heading level.
from html.parser import HTMLParser
class HeadingAudit(HTMLParser):
def __init__(self):
super().__init__()
self.current = None
self.text = []
self.headings = []
def handle_starttag(self, tag, attrs):
if len(tag) == 2 and tag[0] == "h" and tag[1] in "123456":
self.current = int(tag[1])
self.text = []
def handle_data(self, data):
if self.current:
self.text.append(data)
def handle_endtag(self, tag):
if self.current and tag == f"h{self.current}":
self.headings.append((self.current, "".join(self.text).strip()))
self.current = None
def audit(html):
parser = HeadingAudit()
parser.feed(html)
problems = []
h1_count = sum(1 for level, _ in parser.headings if level == 1)
if h1_count != 1:
problems.append(f"expected 1 h1, found {h1_count}")
prev = 0
for level, text in parser.headings:
if prev and level > prev + 1:
problems.append(f"skipped level before '{text}' (h{prev} to h{level})")
prev = level
return problems
page = "<h1>Guide</h1><h3>Details</h3><h2>Next steps</h2>"
for problem in audit(page):
print(problem)Manual checks still matter. Read each section's first sentence and confirm it answers the heading's question.
Exercise
Exercise
A page lists three software plans with price, storage, and support hours. Should this be prose, a list, or a table, and why?
Show answer
A table. The plans share the same three attributes, so a table with a caption and header cells lets a reader or an AI system compare values directly.