rspec/rules/S5256/html/rule.adoc

118 lines
2.6 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2023-10-11 10:52:18 +02:00
Table headers are essential to enhance the accessibility of a table's data, particularly for assistive technologies like screen readers.
These headers provide the necessary context to transform data into information.
Without headers, users get rapidly lost in the flow of data.
2021-04-28 16:49:39 +02:00
2023-10-11 10:52:18 +02:00
This rule raises an issue whenever a `<table>` does not contain any `<th>` elements.
2021-04-28 16:49:39 +02:00
2023-10-11 10:52:18 +02:00
=== Exceptions
2021-04-28 16:49:39 +02:00
2023-10-11 10:52:18 +02:00
No issue will be raised on `<table>` used for layout purpose, i.e. when it contains a `role` attribute set to `"presentation"` or `"none"`.
[source,html]
----
<table role="presentation">
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<tr>
<td>John Doe</td>
<td>42</td>
</tr>
</table>
----
Note that https://www.w3schools.com/html/html_layout.asp[using <table> for layout purpose is a bad practice].
2021-04-28 16:49:39 +02:00
2023-10-11 10:52:18 +02:00
No issue will be raised on `<table>` containing an `aria-hidden` attribute set to `"true"`.
[source,html]
----
<table aria-hidden="true">
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<tr>
<td>John Doe</td>
<td>42</td>
</tr>
</table>
----
2021-04-28 16:49:39 +02:00
2023-10-11 10:52:18 +02:00
== How to fix it
2023-10-11 10:52:18 +02:00
The first `<tr>` of the table should contain `<th>` elements, with the appropriate description of what the data in those columns represents.
2021-04-28 16:49:39 +02:00
2023-10-11 10:52:18 +02:00
=== Going the extra mile
Headers should be properly associated with the corresponding `<td>` cells by using either a `scope` attribute or `headers` and `id` attributes.
See https://www.w3.org/WAI/tutorials/tables/tips/[W3C WAI Web Accessibility Tutorials] for more information.
=== Code examples
==== Noncompliant code example
[source,html,diff-id=1,diff-type=noncompliant]
2021-04-28 16:49:39 +02:00
----
<table> <!-- Noncompliant -->
<tr>
<td>Name</td>
<td>Age</td>
</tr>
<tr>
<td>John Doe</td>
<td>24</td>
</tr>
<tr>
<td>Alice Doe</td>
<td>54</td>
</tr>
</table>
----
2023-10-11 10:52:18 +02:00
==== Compliant solution
2021-04-28 16:49:39 +02:00
2023-10-11 10:52:18 +02:00
[source,html,diff-id=1,diff-type=compliant]
2021-04-28 16:49:39 +02:00
----
<table>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
</tr>
<tr>
<td>John Doe</td>
<td>24</td>
</tr>
<tr>
<td>Alice Doe</td>
<td>54</td>
</tr>
</table>
----
== Resources
2021-04-28 16:49:39 +02:00
2023-10-11 10:52:18 +02:00
=== Documentation
2021-04-28 16:49:39 +02:00
* https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-content-structure-separation-programmatic[WCAG2, 1.3.1] - Info and Relationships
* https://www.w3.org/TR/WCAG20-TECHS/H51[WCAG2, H51] - Using table markup to present tabular information
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add "<th>" headers to this "<table>"
=== Highlighting
The opening <table> tag, without its content.
endif::env-github,rspecator-view[]