headers属性を使用する<table>要素内のすべてのセルは、同じ<table>の他のセルのみを参照する必要があります。
修正方法
問題を修正するには、テーブル内の headers
を使用している各セルが、scope
属性値を tr
要素内の 各 th
要素に使用することで同じテーブル内の他のセルを参照していることを確認します。このルールは、ヘッダー列と行に対する参照が特定の td
要素に関連していることを確認します。
scope
属性はブラウザーとスクリーン・リーダーに列以下のすべてが上部のヘッダーに関連していること、そして行ヘッダーの右側にあるすべてがそのヘッダーに関連していることを伝えます。
scope 属性を次のテーブルに適用した場合のマークアップはこのようになります:
例
<table>
<caption><strong>Greensprings Running Club Personal Bests</strong></caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">1 mile</th>
<th scope="col">5 km</th>
<th scope="col">10 km</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Mary</th>
<td>8:32</td>
<td>28:04</td>
<td>1:01:16</td>
</tr>
<tr>
<th scope="row">Betsy</th>
<td>7:43</td>
<td>26:47</td>
<td>55:38</td>
</tr>
<tr>
<th scope="row">Matt</th>
<td>7:55</td>
<td>27:29</td>
<td>57:04</td>
</tr>
<tr>
<th scope="row">Todd</th>
<td>7:01</td>
<td>24:21</td>
<td>50:35</td>
</tr>
</tbody>
</table>
データテーブル内で、データセルと1つもしくはそれ以上のヘッダーセルを関連付けるための特定の例については、Using id
and headers
attributes to associate data cells with header cells in data tables をご参照ください。
Name、1 mile、5 km そして 10 km という上部のヘッダー、Mary、Betsy、Matt そして Todd という行ヘッダーがすべて th
要素でマークアップされていることに注意してください。また、これらの各ヘッダーセルは列ヘッダーか行ヘッダーかに応じて col
または row
という scope
属性値を指定されています。
ヘッダーセルとデータセルを関連づけるもう1つの方法は、scope
属性の colgroup
と rowgroup
値を使用する方法です。このマークアップのテクニックは、複数の列と行にまたがるヘッダーを指定するために使用します。Mozilla's Learn HTML Developer Docs にある次の表を見てみましょう:
Clothes | Accessories | |||||
---|---|---|---|---|---|---|
Trousers | Skirts | Dresses | Bracelets | Rings | ||
Belgium | Antwerp | 56 | 22 | 43 | 72 | 23 |
Gent | 46 | 18 | 50 | 61 | 15 | |
Brussels | 51 | 27 | 38 | 69 | 28 | |
The Netherlands | Amsterdam | 89 | 34 | 69 | 85 | 38 |
Utrecht | 80 | 12 | 43 | 36 | 19 |
scope="colgroup"
と scope="rowgroup"
値が th
要素に含まれる例
<table>
<caption>Items Sold August 2016</caption>
<tbody>
<tr>
<td></td>
<td></td>
<th colspan="3" scope="colgroup">Clothes</th>
<th colspan="2" scope="colgroup">Accessories</th>
</tr>
<tr>
<td></td>
<td></td>
<th scope="col">Trousers</th>
<th scope="col">Skirts</th>
<th scope="col">Dresses</th>
<th scope="col">Bracelets</th>
<th scope="col">Rings</th>
</tr>
<tr>
<th rowspan="3" scope="rowgroup">Belgium</th>
<th scope="row">Antwerp</th>
<td>56</td>
<td>22</td>
<td>43</td>
<td>72</td>
<td>23</td>
</tr>
<tr>
<th scope="row">Gent</th>
<td>46</td>
<td>18</td>
<td>50</td>
<td>61</td>
<td>15</td>
</tr>
<tr>
<th scope="row">Brussels</th>
<td>51</td>
<td>27</td>
<td>38</td>
<td>69</td>
<td>28</td>
</tr>
<tr>
<th rowspan="2" scope="rowgroup">The Netherlands</th>
<th scope="row">Amsterdam</th>
<td>89</td>
<td>34</td>
<td>69</td>
<td>85</td>
<td>38</td>
</tr>
<tr>
<th scope="row">Utrecht</th>
<td>80</td>
<td>12</td>
<td>43</td>
<td>36</td>
<td>19</td>
</tr>
</tbody>
</table>
なぜ重要なのか
スクリーン・リーダーはテーブルを特定の方法で読み上げます。テーブルが正確にマークアップされていない場合、混乱させるような、あるいは不正確なスクリーン・リーダーの読み上げ内容になる可能性があります。
通常、目の見えるユーザーはテーブルのヘッダーとデータとの関係性をぱっと判断できます。目の見えないユーザーには、これをマークアップで表現する必要があります。
データテーブルがアクセシビリティを考慮して設計されている場合、ユーザーはテーブル移動モードに入り、スクリーン・リーダーがデータセルに対応するテーブルヘッダーを読み上げるのを聞きながら、ユーザーがテーブル内のセル間を移動できるようにします。テーブルヘッダーを聞くことは、大きなテーブル内を移動する際、あるいはセルに似たようなデータがあり混乱しやすい場合に特に役に立ちます。
しかし、テーブルのアクセシビリティ機能が不足している場合、テーブル移動モードは役に立ちません。
ルールの説明
データテーブルのマークアップは長く複雑になりやすいです。テーブルは正しい見出し構造で、セマンティックにマークアップされなければなりません。スクリーン・リーダーにはテーブル移動を楽にする機能がありますが、これらの機能が正しく動作するには、テーブルは正しくマークアップされていなければなりません。
仕組みについて (簡単に言うと)
データテーブルがセマンティックにマークアップされていて、正しいヘッダー構造であることを確認します。