Information on order summary tables #
Description:
Order summary tables are an essential part of e-commerce checkout processes, providing users with a clear and organized view of the items they are purchasing, along with pricing, quantities, and any additional charges or discounts.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Accessible Order Summary Table</title>
<style>
/* Basic table styling */
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
border: 1px solid #ddd;
padding: 10px;
text-align: left;
}
th {
background-color: #f4f4f4;
}
th[scope="row"] {
background-color: #e9e9e9;
}
caption {
font-size: 1.2em;
margin-bottom: 10px;
text-align: left;
font-weight: bold;
}
tfoot td {
font-weight: bold;
}
/* Responsive design */
@media (max-width: 600px) {
table {
display: block;
overflow-x: auto;
white-space: nowrap;
}
}
</style>
</head>
<body>
<!-- Accessible Order Summary Table -->
<table aria-label="Order Summary">
<caption>Order Summary</caption>
<thead>
<tr>
<th scope="col">Item</th>
<th scope="col">Quantity</th>
<th scope="col">Unit Price</th>
<th scope="col">Total</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Eco-Friendly Leather Backpack</th>
<td>1</td>
<td>$120</td>
<td>$120</td>
</tr>
<tr>
<th scope="row">Sustainable Cotton T-Shirt</th>
<td>2</td>
<td>$35</td>
<td>$70</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">Subtotal</td>
<td>$190</td>
</tr>
<tr>
<td colspan="3">Shipping</td>
<td>$10</td>
</tr>
<tr>
<td colspan="3">Total</td>
<td>$200</td>
</tr>
</tfoot>
</table>
</body>
</html>
Explanation #
- Semantic Structure:
- The table is divided into
<thead>for headers,<tbody>for main data rows, and<tfoot>for summaries and totals, providing logical grouping for easier navigation. - Each section is clearly identified and structured for screen reader compatibility.
- The table is divided into
- Descriptive Headers:
- Column headers (e.g., “Item,” “Quantity”) use
<th scope="col">to define their role as column headers. - Row headers (e.g., product names) use
<th scope="row">to help screen readers associate each product’s details with its name.
- Column headers (e.g., “Item,” “Quantity”) use
- Responsive Design:
- On smaller screens, the table is scrollable to ensure all columns remain visible without breaking the layout.
- Clear Totals with
<tfoot>:- The
<tfoot>section organizes the subtotal, shipping, and total costs, making the table easy to scan for all users.
- The
- ARIA for Context:
- The
aria-label="Order Summary"attribute provides additional context for screen readers, describing the table’s purpose.
- The
Key Takeaways #
- Semantic HTML: Use
<thead>,<tbody>,<tfoot>,<th>, and<td>to structure the table for accessibility. - Descriptive Labels: Use
scope="col"andscope="row"to define relationships for screen readers. - Responsive Design: Ensure the table works well on all devices, especially smaller screens.
- Highlight Totals: Use
<tfoot>to group subtotal, shipping, and total rows, improving clarity.
Screen reader: NVDA
Video: