Sub topic 6
Anatomy of a comparison table
This chapter assumes you know basic HTML and CSS, understand how subscription products are sold, and have met responsive layout. You have already chosen tiers and decided which features to compare. Here you will see what a comparison table is made of, how its parts relate, and which mistakes make it hard to read or hard to use.
Why a table, and when not to use one
A comparison table answers one question: how do these plans differ on the things I care about? The visitor reads in two directions. Reading down a column tells them what one plan contains. Reading across a row tells them how every plan handles one feature. A table is the right structure because it holds both readings at once.
Use a table when you have at least three features and at least two plans, and when the same features apply to every plan. If you only have a short list of highlights per plan, plan cards are enough. If plans differ in kind rather than degree, a table with many empty cells is a sign that cards or a separate feature page would work better.
The parts of the table
Every comparison table has the same six parts. Naming them helps you discuss design choices and build the markup correctly.
| Part | What it is | Example |
|---|---|---|
| Caption | A short title for the whole table | "Compare plans" |
| Plan headers | One column heading per plan, usually with name, price, and a call to action | Starter, Team, Business |
| Corner cell | The top-left cell, above the feature labels | Empty, or a label such as "Feature" |
| Feature labels | One row heading per feature | Projects, Single sign-on |
| Value cells | The intersection of a plan and a feature | "3", "Unlimited", a check mark |
| Group rows | Optional rows that split features into sections | "Security", "Support" |
The plan headers are column headers. The feature labels are row headers. Value cells have meaning only in combination with both, so a value like "3" never stands alone.
Orientation: plans as columns
Put plans in columns and features in rows. Most pricing pages do this, for practical reasons:
- Features outnumber plans, often ten or more against three or four. Rows scroll naturally. Columns do not.
- Plan prices and call-to-action buttons sit together in one header row, where the eye lands first.
- Scores or highlights for one plan form a single vertical strip, which is easy to emphasize.
Plans as rows only makes sense for very few features. It also breaks the convention that visitors have already learned from other sites.
Order of plans and features
Order plans from lowest to highest price, left to right. Visitors expect that progression, and it makes "everything in Team, plus" language easy to understand. Place the recommended plan inside that order. Do not move it to the far left to give it prominence, because that breaks the progression. Chapter 7 covers how to highlight it.
Order features by the questions visitors ask first. Start with the value metric, such as projects or seats, because it explains the price. Then list the features that distinguish the plans most. Put shared features and rarely decisive items lower. Within each group, keep related features adjacent.
What goes in a value cell
A value cell should be quick to scan. Use a small, consistent set of forms:
- A check mark for "included" and a cross or dash for "not included".
- A number or short quantity for limits, such as "3" or "Unlimited".
- A short word for levels, such as "Email" or "Priority".
Avoid long sentences in cells. If a feature needs explanation, put a short note in the feature label, or link to a detail page. Keep the same form within a row. A row that mixes a check mark, a number, and a sentence forces the reader to switch reading modes.
Be careful with the cross. A row full of crosses on the lowest plan can feel punishing. A dash or lighter styling for "not included" keeps the table honest without shouting about what the plan lacks.
Building the markup
The markup must express the structure above, because screen readers, search engines, and your own CSS all depend on it. This example has a caption, a header row, a row header per feature, and symbols with text alternatives.
<div class="table-wrap">
<table class="plans">
<caption>Compare plans</caption>
<thead>
<tr>
<th scope="col"><span class="visually-hidden">Feature</span></th>
<th scope="col">Starter</th>
<th scope="col">Team</th>
<th scope="col">Business</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Projects</th>
<td>3</td>
<td>Unlimited</td>
<td>Unlimited</td>
</tr>
<tr>
<th scope="row">Single sign-on</th>
<td><span aria-hidden="true">✕</span><span class="visually-hidden">Not included</span></td>
<td><span aria-hidden="true">✕</span><span class="visually-hidden">Not included</span></td>
<td><span aria-hidden="true">✓</span><span class="visually-hidden">Included</span></td>
</tr>
</tbody>
</table>
</div>Key points about this markup:
<caption>gives the table an accessible name. It is better than a heading placed nearby, because assistive technology announces it with the table.<thead>and<tbody>separate headers from data. CSS can then target the header row, for example to make it sticky.scope="col"andscope="row"state which cells each header describes. Without them, some screen readers guess, and guesses fail in tables with group rows or merged cells.- The corner cell must still be a
<th>. An empty header cell is announced as blank. A visually hidden label gives it a name without changing the design. - Each symbol is split into a decorative part (
aria-hidden="true") and a hidden text part. A screen reader says "Included" rather than reading out a Unicode character name, or nothing at all. - The wrapper
<div>exists for the scroll behavior covered in a later chapter. It is not part of the table's meaning.
Group rows
When the table has more than about eight features, split it into sections such as "Core", "Security", and "Support". A group row is a single cell that spans all columns. Mark it as a header for the rows beneath it.
<tbody>
<tr>
<th scope="rowgroup" colspan="4">Security</th>
</tr>
<tr>
<th scope="row">Single sign-on</th>
<td>Not included</td>
<td>Not included</td>
<td>Included</td>
</tr>
<tr>
<th scope="row">Audit log</th>
<td>Not included</td>
<td>90 days</td>
<td>1 year</td>
</tr>
</tbody>Using scope="rowgroup" on a <th> inside a <tbody> is valid, but support varies. A more robust option is one <tbody> per group, with the group heading in the first row of that <tbody>. Test with a screen reader if group rows matter to your layout.
Sticky headers and the corner cell
Long tables lose their plan names once the reader scrolls past the header. A sticky header row keeps the plan names visible. A sticky first column does the same for feature labels on narrow screens.
.plans {
border-collapse: separate;
border-spacing: 0;
width: 100%;
}
.plans thead th {
position: sticky;
top: 0;
background: #fff;
}
.plans tbody th[scope="row"] {
position: sticky;
left: 0;
background: #fff;
text-align: left;
}Two details matter here. First, border-collapse: separate is needed because sticky cells and collapsed borders render poorly together, and borders can vanish while scrolling. Second, sticky cells need an opaque background, or content scrolls visibly behind them.
A sticky header also has a limit. position: sticky works relative to the nearest scrolling ancestor. If the wrapper has overflow-x: auto, it becomes that ancestor, and the header will stick inside the wrapper rather than to the page. Check this when you combine horizontal scrolling with a sticky header.
Common errors
| Mistake | Effect | Fix |
|---|---|---|
| Building the table from `<div>` elements | Screen readers announce no table structure | Use real `<table>` elements |
| Using `<td>` with bold styling for headers | No header relationships are exposed | Use `<th>` with `scope` |
| Check marks with no text alternative | Screen reader users cannot compare plans | Add visually hidden text |
| Merged cells across plans | Header associations break | Repeat the value in each cell |
| Different words for the same feature across rows | Visitors cannot match features to plans | Keep one name per feature |
| Hiding the table on mobile and showing cards only | Content drifts apart between layouts | Keep one data source, or scroll the table |
Check your understanding
Exercise
A designer wants to remove the empty top-left header cell from the table and start the header row with the "Starter" column, because "it looks cleaner". Why does this cause a problem, and what is a better way to keep the design clean?
Show answer
The first column of every body row holds a row header, so the header row needs a cell above it to keep the columns aligned. Removing the cell shifts the plan headers one column to the left, so each plan name sits over the wrong column and the markup no longer matches the grid. Keep the cell as a <th scope="col">, and give it a visually hidden label such as "Feature" so it looks empty on screen while still having an accessible name.
Exercise
Your table has a row labelled "Single sign-on" where the Business cell contains only a check mark glyph in a <td>. Describe what a screen reader user hears, and write the markup change that fixes it.
Show answer
The user may hear nothing, or a glyph name such as "check mark", with no meaning attached. Wrap the glyph in a span with aria-hidden="true" and add a second span with the class visually-hidden containing "Included". The cell then reads "Included" in the context of the row header "Single sign-on" and the column header "Business".