diff --git a/files/en-us/learn/html/tables/advanced/index.md b/files/en-us/learn/html/tables/advanced/index.md index 6ce990309619997..a3cbe7965357087 100644 --- a/files/en-us/learn/html/tables/advanced/index.md +++ b/files/en-us/learn/html/tables/advanced/index.md @@ -159,10 +159,8 @@ th { Let's recap briefly on how we use data tables. A table can be a handy tool, for giving us quick access to data and allowing us to look up different values. For example, it takes only a short glance at the table below to find out how many rings were sold in Gent during August 2016. To understand its information we make visual associations between the data in this table and its column and/or row headers.
Clothes | @@ -175,6 +173,8 @@ Let's recap briefly on how we use data tables. A table can be a handy tool, forBracelets | Rings | |||||||
---|---|---|---|---|---|---|---|---|---|
Belgium | Antwerp | @@ -260,51 +260,84 @@ And each row could have a header defined like this (if we added row headers as w`), but "Clothes" is a heading that sits over the top and defines the other three subheadings. "Clothes" therefore should get an attribute of `scope="colgroup"`, whereas the others would get an attribute of `scope="col"`:
+
+```html
+
+ Clothes |
+ Trousers |
+ Skirts |
+ Dresses |
+ | `). You'll notice that the "The Netherlands" header, also marked up as a ` | ` element, spans both rows, being the heading for the other two subheadings. Therefore, `scope="rowgroup"` should be specified on this header cell to help screen readers create the correct associations: -`scope` has two more possible values — `colgroup` and `rowgroup`. These are used for headings that sit over the top of multiple columns or rows. If you look back at the "Items Sold August 2016" table at the start of this section of the article, you'll see that the "Clothes" cell sits above the "Trousers", "Skirts", and "Dresses" cells. All of these cells should be marked up as headers (` | `), but "Clothes" is a heading that sits over the top and defines the other three subheadings. "Clothes" therefore should get an attribute of `scope="colgroup"`, whereas the others would get an attribute of `scope="col"`. +```html + |
The Netherlands | +Amsterdam | +89 | +34 | +69 | +|||||
Utrecht | +80 | +12 | +43 | +` element. -2. You add a `headers` attribute to each ` | ` element. Each `headers` attribute has to contain a list of the `id`s of all the ` | ` elements that act as a header for that cell, separated by spaces. +The `headers` attribute takes a list of unordered, space-separated {{Glossary("string", "strings")}}, each corresponding to the unique `id` of the ` | ` elements that provide headings for either a data cell (` | ` element) or another header cell (` | ` element). This gives your HTML table an explicit definition of the position of each cell in the table, defined by the header(s) for each column and row it is part of, kind of like a spreadsheet. For it to work well, the table really needs both column and row headers. -Returning to our spending costs example, the previous two snippets could be rewritten like this: +Returning to our "Items Sold August 2016" example, we can use the `id` and `headers` attributes as follows: + +1. Add a unique `id` to each ` | ` element in the table. +2. Add a `headers` attribute to each ` | ` element that acts as a subheading, i.e., has a header element above it. The value is the `id` of the heading that sits over the top and defines the subheadings, which is `"clothes"` for the column headers and `"belgium"` for the row header in our example. +3. Add a `headers` attribute to each ` | ` element and add the `id`s of the associated ` | ` element(s) in form of a space-separated list. You can proceed as you would in a spreadsheet: Find the data cell and search for the corresponding headings for the row and column. The order of the specified `id`s doesn't matter, but you should be consistent to keep it organized.
```html
Purchase |
- Location |
- Date |
- Evaluation |
- Cost (€) |
+ Clothes |
+ Trousers |
+ Skirts |
+ Dresses |
|
Haircut | -Hairdresser | -12/09 | -Great idea | -30 | +Belgium | +Antwerp | +56 | +22 | +43 |