-
Notifications
You must be signed in to change notification settings - Fork 28
/
tables.html
85 lines (85 loc) · 2.82 KB
/
tables.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Accessible Tables</title>
<link rel="stylesheet" href="css/normalization.css" />
<link rel="stylesheet" href="css/base.css" />
<style>
table {
margin-bottom: 3.5ex;
}
</style>
</head>
<body>
<div class="container">
<a href="#main" class="skip-link">Skip to main content</a>
<div class="page-wrapper" id="main" role="main" tabindex="-1">
<h1>Accessible Tables</h1>
<p><a href="http://haltersweb.github.io/Accessibility/">View the full library of accessibility solutions.</a></p>
<p>First and foremost, tables should only be used to present data. Never use tables for layout, not even for forms. Leverage your CSS super-powers to get the layout you want.</p>
<h2>Rules for accessible tables</h2>
<ul class="bullet">
<li>Assign the scope attribute to your <th> (col or row).</li>
<li>Use proportional sizing. Size your <col> with percentages. Never style the <table> with absolute widths such as pixels.</li>
<li>Add a caption as the first child of the <table> (the summary attribute is depreated in HTML5).</li>
<li>Never use the rowspan. It confuses screen readers.</li>
<li>Never nest tables.</li>
<li>Follow the K.I.S.S. rule — If you find yourself trying to nest tables, using too many colspans, solving for multiple rows of headings, it may be time for a new column or even a new table.</li>
</ul>
<div id="a11yTable">
<table>
<caption>
<h2>Who likes what flavors?</h2>
</caption>
<thead>
<tr>
<th scope="col">Name</th>
<th scope="col">Chocolate</th>
<th scope="col">Vanilla</th>
<th scope="col">Strawberry</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Sally</th>
<td>yes</td>
<td>yes</td>
<td>yes</td>
</tr>
<tr>
<th scope="row">George</th>
<td>no</td>
<td>yes</td>
<td>no</td>
</tr>
<tr>
<th scope="row">Marian</th>
<td>no</td>
<td>yes</td>
<td>yes</td>
</tr>
<tr>
<th scope="row">Larry</th>
<td>yes</td>
<td>yes</td>
<td>no</td>
</tr>
</tbody>
</table>
</div>
<h2>Code sample</h2>
<div data-code="a11yTable"></div>
</div>
<div class="overlay"></div>
<div class="block-screen"></div>
<div aria-live="polite" class="screen-reader-text"></div>
<div role="alert" class="screen-reader-text"></div>
</div>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/namespacing.js"></script>
<script type="text/javascript" src="js/accessibility-helpers.js"></script>
<script type="text/javascript" src="js/show-code.js"></script>
</body>
</html>