@schalkneethling/toolkit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +292 -0
- package/dist/index.mjs.map +1 -0
- package/hooks/block-dangerous-commands/hook.js +120 -0
- package/hooks/block-dangerous-commands/settings-fragment.json +15 -0
- package/package.json +35 -0
- package/skills/semantic-html/SKILL.md +603 -0
- package/skills/semantic-html/references/element-decision-trees.md +111 -0
- package/skills/semantic-html/references/heading-patterns.md +275 -0
|
@@ -0,0 +1,603 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: semantic-html
|
|
3
|
+
description: Write well-considered semantic HTML that serves all users. Use when creating components, page structures, or reviewing markup. Emphasizes native HTML elements over ARIA. Treats proper document structure and accessibility as foundations rather than afterthoughts.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Semantic HTML
|
|
7
|
+
|
|
8
|
+
Write HTML that conveys meaning, serves all users, and respects the web platform.
|
|
9
|
+
|
|
10
|
+
## When to Use This Skill
|
|
11
|
+
|
|
12
|
+
Use this skill when:
|
|
13
|
+
|
|
14
|
+
- Creating new components or page sections
|
|
15
|
+
- Reviewing markup for accessibility and semantics
|
|
16
|
+
- Deciding between native HTML elements and ARIA attributes
|
|
17
|
+
- Structuring documents with proper heading hierarchy
|
|
18
|
+
- Making interactive elements accessible
|
|
19
|
+
- Building forms with proper labelling and error handling
|
|
20
|
+
- Creating responsive tables
|
|
21
|
+
|
|
22
|
+
## Core Principles
|
|
23
|
+
|
|
24
|
+
### Content Realism
|
|
25
|
+
|
|
26
|
+
Design content is idealized. Real content is messy. Always account for:
|
|
27
|
+
|
|
28
|
+
- Long sentences and long words
|
|
29
|
+
- Images with varying aspect ratios and sizes
|
|
30
|
+
- Multi-language support (even if not planned—users can translate via browser)
|
|
31
|
+
- Dynamic content that changes in length and structure
|
|
32
|
+
|
|
33
|
+
Build components that handle real-world content gracefully, not just what looks good in design tools.
|
|
34
|
+
|
|
35
|
+
### Landmarks-First Planning
|
|
36
|
+
|
|
37
|
+
Before diving into individual components, consider the full page structure. This allows you to:
|
|
38
|
+
|
|
39
|
+
- Identify key landmarks for assistive technology users
|
|
40
|
+
- Plan heading hierarchy across the document
|
|
41
|
+
- Make informed decisions about element choice
|
|
42
|
+
- Avoid overusing landmarks (which diminishes their usefulness)
|
|
43
|
+
|
|
44
|
+
### Native Over ARIA
|
|
45
|
+
|
|
46
|
+
Follow the first rule of ARIA: if a native HTML element provides the semantics and behaviour you need, use it instead of adding ARIA to a generic element.
|
|
47
|
+
|
|
48
|
+
**Red flag:** High div count combined with high ARIA count on non-complex components signals reaching for patches rather than foundations.
|
|
49
|
+
|
|
50
|
+
#### Redundant ARIA
|
|
51
|
+
|
|
52
|
+
Adding ARIA to elements that already carry the correct semantics is noise—it clutters the code, can confuse assistive technology, and obscures genuine intent:
|
|
53
|
+
|
|
54
|
+
```html
|
|
55
|
+
<!-- Redundant: <ul> already has list semantics -->
|
|
56
|
+
<ul role="list">
|
|
57
|
+
...
|
|
58
|
+
</ul>
|
|
59
|
+
|
|
60
|
+
<!-- Redundant: alt="" already suppresses the accessible name -->
|
|
61
|
+
<img src="avatar.png" alt="" role="presentation" />
|
|
62
|
+
|
|
63
|
+
<!-- Redundant: aria-label duplicates visible text the AT will already read -->
|
|
64
|
+
<span aria-label="Most Popular">Most Popular</span>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### Don't Override Native Semantics with role
|
|
68
|
+
|
|
69
|
+
ARIA `role` changes how assistive technology interprets an element. Applying a role that changes a native element's semantics introduces inconsistency—native behaviour (keyboard interaction, states, events) stays the same while the announced role changes:
|
|
70
|
+
|
|
71
|
+
```html
|
|
72
|
+
<!-- Wrong: role="switch" changes what AT announces, but the element still
|
|
73
|
+
behaves like a checkbox. Use the native checkbox if switch toggle
|
|
74
|
+
semantics aren't needed, or build a proper switch widget. -->
|
|
75
|
+
<input type="checkbox" role="switch" />
|
|
76
|
+
|
|
77
|
+
<!-- Right: native checkbox, no role override needed -->
|
|
78
|
+
<input type="checkbox" />
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Only add a `role` attribute to a native element when you deliberately need different semantics and the element's behaviour genuinely matches that role.
|
|
82
|
+
|
|
83
|
+
### Separation of Visual and Semantic Hierarchy
|
|
84
|
+
|
|
85
|
+
Visual styling and semantic meaning are related but not coupled. CSS classes bridge the gap:
|
|
86
|
+
|
|
87
|
+
- Use the appropriate heading level based on document structure
|
|
88
|
+
- Apply CSS classes to control visual appearance (size, weight, colour)
|
|
89
|
+
- Create utility classes like `.u-Heading-XXL` for consistent visual treatment regardless of semantic level
|
|
90
|
+
|
|
91
|
+
## Document Structure
|
|
92
|
+
|
|
93
|
+
### Skip Navigation Links
|
|
94
|
+
|
|
95
|
+
Skip links let keyboard and screen reader users bypass repeated navigation blocks and jump directly to meaningful content. They are required on any page with a navigation block or other repeated content before the main content.
|
|
96
|
+
|
|
97
|
+
Place skip links as the **first focusable element** in `<body>`. They can be visually hidden and revealed on focus:
|
|
98
|
+
|
|
99
|
+
```html
|
|
100
|
+
<body>
|
|
101
|
+
<a href="#main-content" class="skip-link">Skip to main content</a>
|
|
102
|
+
<!-- optional additional skip targets -->
|
|
103
|
+
<a href="#search" class="skip-link">Skip to search</a>
|
|
104
|
+
|
|
105
|
+
<header>...</header>
|
|
106
|
+
<nav>...</nav>
|
|
107
|
+
|
|
108
|
+
<main id="main-content" tabindex="-1">...</main>
|
|
109
|
+
</body>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
```css
|
|
113
|
+
.skip-link {
|
|
114
|
+
position: absolute;
|
|
115
|
+
transform: translateY(-100%);
|
|
116
|
+
}
|
|
117
|
+
.skip-link:focus {
|
|
118
|
+
transform: translateY(0);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Why `tabindex="-1"` on `<main>`:** The `<main>` element is not natively focusable. Without `tabindex="-1"`, activating the skip link scrolls to the element but does not move keyboard focus there in all browsers. Adding `tabindex="-1"` makes it programmatically focusable (reachable via the skip link or `.focus()`) without adding it to the natural tab order.
|
|
123
|
+
|
|
124
|
+
**When to add more skip links:** If the page has a prominent search bar, a sidebar, or a long secondary navigation, consider skip links to those targets too. The goal is reducing the number of Tab presses to reach primary content.
|
|
125
|
+
|
|
126
|
+
**Sidebar layouts need a "skip to navigation" link:** When a sidebar navigation is placed away from the top of the DOM (e.g., after `<main>` in source order, or deep within the layout), add a skip link pointing to the `<nav>` so keyboard users can reach it without tabbing through all main content first.
|
|
127
|
+
|
|
128
|
+
**The primary skip link should target `<main>`:** The first skip link should always point to `<main id="main-content">`. Additional skip links can target other meaningful landmarks or controls—a `<search>` element, a sidebar `<nav>`, or a prominent form—depending on the page's complexity.
|
|
129
|
+
|
|
130
|
+
**Why this matters:** Without skip links, keyboard users must tab through every navigation item on every page load. On a nav with 12 links, that's 12 extra keystrokes — on every page.
|
|
131
|
+
|
|
132
|
+
### Landmark Elements
|
|
133
|
+
|
|
134
|
+
Use landmark elements to convey page structure:
|
|
135
|
+
|
|
136
|
+
| Element | Use When | Notes |
|
|
137
|
+
| --------- | ---------------------------- | -------------------------------------------------------------------------------- |
|
|
138
|
+
| `header` | Page or section header | Can appear multiple times in different contexts |
|
|
139
|
+
| `footer` | Page or section footer | Contact info, copyright, related links |
|
|
140
|
+
| `nav` | Navigation sections | Must be labelled; avoid "navigation" in the label (screen readers announce this) |
|
|
141
|
+
| `main` | Primary content | Only one per page; must contain the primary `<h1>` |
|
|
142
|
+
| `aside` | Tangentially related content | Content removable without changing the page's main story (sidebars, ads) |
|
|
143
|
+
| `search` | Search functionality | Contains the search form, not the results |
|
|
144
|
+
| `form` | User input | Only becomes a landmark when labelled via `aria-labelledby` or `aria-label` |
|
|
145
|
+
| `article` | Self-contained content | Would make sense syndicated or standalone |
|
|
146
|
+
| `section` | Thematic grouping | Only becomes a landmark when labelled |
|
|
147
|
+
|
|
148
|
+
#### `<main>` must contain the primary `<h1>`
|
|
149
|
+
|
|
150
|
+
Screen reader users often jump directly to `<main>`. If the page `<h1>` sits in a `<div>` between `<header>` and `<main>`, these users land after the title and lose essential context. The `<h1>` (and any subtitle or intro copy introducing the page) belongs inside `<main>`:
|
|
151
|
+
|
|
152
|
+
```html
|
|
153
|
+
<!-- Wrong: h1 is outside main -->
|
|
154
|
+
<header>...</header>
|
|
155
|
+
<div class="page-header"><h1>FAQ</h1></div>
|
|
156
|
+
<main>
|
|
157
|
+
<!-- screen reader users start here, after the title -->
|
|
158
|
+
</main>
|
|
159
|
+
|
|
160
|
+
<!-- Right: h1 is the first heading inside main -->
|
|
161
|
+
<header>...</header>
|
|
162
|
+
<main id="main-content" tabindex="-1">
|
|
163
|
+
<h1>FAQ</h1>
|
|
164
|
+
...
|
|
165
|
+
</main>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### The Section Element
|
|
169
|
+
|
|
170
|
+
A `section` without an accessible name behaves like a `div` semantically. When using `section`:
|
|
171
|
+
|
|
172
|
+
- Associate it with a heading via `aria-labelledby`
|
|
173
|
+
- This transforms it into a valid landmark region
|
|
174
|
+
- If you cannot provide a meaningful label, question whether `section` is the right choice
|
|
175
|
+
|
|
176
|
+
### The Article Element
|
|
177
|
+
|
|
178
|
+
Think beyond blog posts. Use `article` for any self-contained content that would make sense on its own:
|
|
179
|
+
|
|
180
|
+
- Blog posts and news articles
|
|
181
|
+
- Comments on a post
|
|
182
|
+
- Product cards in a listing
|
|
183
|
+
- Social media posts in a feed
|
|
184
|
+
- Forum posts
|
|
185
|
+
|
|
186
|
+
**Test:** Would this content make sense if extracted and placed elsewhere with no surrounding context?
|
|
187
|
+
|
|
188
|
+
### The Address Element
|
|
189
|
+
|
|
190
|
+
Often misunderstood. From the HTML specification:
|
|
191
|
+
|
|
192
|
+
> The address element represents the contact information for its nearest article or body element ancestor.
|
|
193
|
+
|
|
194
|
+
Use for contact information about the author or owner—not for generic postal addresses. For postal addresses, use a standard `<p>` or structured markup appropriate to the context.
|
|
195
|
+
|
|
196
|
+
### `<aside>` vs `<section>`
|
|
197
|
+
|
|
198
|
+
**The test for `<aside>`:** Would this content make sense if it were removed from the page entirely? Would the main content still be complete?
|
|
199
|
+
|
|
200
|
+
- An advertisement, a related article link, or a biographical note about the author → `<aside>` (removing it doesn't change the main message)
|
|
201
|
+
- A "Still need help?" CTA on an FAQ page, a summary of key findings in an article, or a prominent signup prompt → `<section>` (removing it leaves the page feeling incomplete or breaks the intended flow)
|
|
202
|
+
|
|
203
|
+
When in doubt: if the content serves the primary purpose of the page, it belongs in a labelled `<section>`, not `<aside>`.
|
|
204
|
+
|
|
205
|
+
### The Aside Element and Pull Quotes
|
|
206
|
+
|
|
207
|
+
`<aside>` is appropriate for pull quotes—a typographic device that highlights text from the article. However, do not use `<blockquote>` for a pull quote drawn from the page's own content. `<blockquote>` signals an external or distinct quotation. For a pull quote that restates something from the same article, use `<p>` (or styled text) inside `<aside>`:
|
|
208
|
+
|
|
209
|
+
```html
|
|
210
|
+
<!-- Correct: pull quote from the article's own content -->
|
|
211
|
+
<aside aria-label="Pull quote">
|
|
212
|
+
<p>
|
|
213
|
+
"The biggest gains came not from new features, but from removing old ones."
|
|
214
|
+
</p>
|
|
215
|
+
</aside>
|
|
216
|
+
|
|
217
|
+
<!-- Use blockquote for genuine external quotations -->
|
|
218
|
+
<blockquote cite="https://example.com/source">
|
|
219
|
+
<p>Quote from an external source.</p>
|
|
220
|
+
</blockquote>
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Headings
|
|
224
|
+
|
|
225
|
+
### Heading Hierarchy
|
|
226
|
+
|
|
227
|
+
Maintain a logical heading structure:
|
|
228
|
+
|
|
229
|
+
- One `h1` per page (typically the main title)
|
|
230
|
+
- Don't skip levels (h1 → h3)
|
|
231
|
+
- Headings create an outline—ensure it makes sense when read in sequence
|
|
232
|
+
|
|
233
|
+
### Headings in Components
|
|
234
|
+
|
|
235
|
+
For reusable components containing headings:
|
|
236
|
+
|
|
237
|
+
1. **Make heading level configurable** — Components may appear in different contexts
|
|
238
|
+
2. **Provide sensible defaults** — Not all content authors understand heading hierarchy
|
|
239
|
+
3. **Consider inheritance** — Generic components become specific ones; heading config should flow through
|
|
240
|
+
|
|
241
|
+
**Example pattern:**
|
|
242
|
+
|
|
243
|
+
```
|
|
244
|
+
Card (generic) → heading level configurable, default h3
|
|
245
|
+
└─ ProductCard (specific) → inherits config, may set default based on known context
|
|
246
|
+
└─ Used in section with h2 → heading level set to h3
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Visual Heading Without Semantic Heading
|
|
250
|
+
|
|
251
|
+
Sometimes text looks like a heading but shouldn't be one semantically. Use CSS classes to apply heading-like styling without affecting document outline:
|
|
252
|
+
|
|
253
|
+
```html
|
|
254
|
+
<p class="u-Heading-L">This looks like a heading</p>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Lists
|
|
258
|
+
|
|
259
|
+
### When to Use Lists
|
|
260
|
+
|
|
261
|
+
Lists are most useful when **knowing the number of items helps the user**:
|
|
262
|
+
|
|
263
|
+
- Navigation menus (how many options?)
|
|
264
|
+
- Search results (how many matches?)
|
|
265
|
+
- Image galleries (how many images?)
|
|
266
|
+
- Steps in a process
|
|
267
|
+
|
|
268
|
+
**Questions to ask:**
|
|
269
|
+
|
|
270
|
+
- Are these items genuinely peers?
|
|
271
|
+
- Would removing one make the others feel incomplete?
|
|
272
|
+
- Is there an implicit "here are N things" being communicated?
|
|
273
|
+
|
|
274
|
+
### List Types
|
|
275
|
+
|
|
276
|
+
| Type | Use When | Example |
|
|
277
|
+
| ------ | ---------------------------------------- | ------------------------------------- |
|
|
278
|
+
| `ul` | Unordered collection where count matters | Nav items, search results |
|
|
279
|
+
| `ol` | Sequential steps or ranked items | Recipes, instructions, top-10 lists |
|
|
280
|
+
| `dl` | Term-description pairs | Glossaries, metadata, key-value pairs |
|
|
281
|
+
| `menu` | Toolbar commands | Action buttons, not navigation |
|
|
282
|
+
|
|
283
|
+
**Ordered list attributes:** Use `reversed` for countdown-style lists (e.g., a top 10 listed from 10 to 1). Use `start` to begin numbering from a specific value. Both are native HTML—no JavaScript required.
|
|
284
|
+
|
|
285
|
+
### Definition Lists
|
|
286
|
+
|
|
287
|
+
Often overlooked or confused with `details`/`summary`. Use `dl` for:
|
|
288
|
+
|
|
289
|
+
- Glossary definitions
|
|
290
|
+
- Metadata display (label: value pairs)
|
|
291
|
+
- Any term with one or more descriptions
|
|
292
|
+
|
|
293
|
+
Note: A single `dt` can have multiple `dd` elements for multiple related descriptions.
|
|
294
|
+
|
|
295
|
+
### Decorative List Separators
|
|
296
|
+
|
|
297
|
+
When using CSS `::before` or `::after` to inject visual separators (e.g., breadcrumb `›`), browsers automatically exclude generated content from the accessibility tree—no extra markup is required. Do **not** try to hide it with `aria-hidden: "true"` as a CSS property; that is invalid and has no effect. If injecting separators via HTML (not CSS), use `<span aria-hidden="true">` on the HTML element.
|
|
298
|
+
|
|
299
|
+
## Interactive Elements
|
|
300
|
+
|
|
301
|
+
### Buttons vs Links
|
|
302
|
+
|
|
303
|
+
**Traditional rule:** Buttons do things, links go places.
|
|
304
|
+
|
|
305
|
+
**Progressive enhancement lens:** If a URL provides a meaningful fallback when JavaScript fails, a link is valid even for action-like interactions.
|
|
306
|
+
|
|
307
|
+
| Interaction | Default Choice | Consider Link When |
|
|
308
|
+
| ----------------------- | -------------- | --------------------------------------------- |
|
|
309
|
+
| Show more content | `button` | URL params could load the content server-side |
|
|
310
|
+
| Toggle view (grid/list) | `button` | URL could preserve view preference |
|
|
311
|
+
| Copy to clipboard | `button` | Copied content is a shareable URL |
|
|
312
|
+
| Tab selection | `button` | URL could load specific tab content |
|
|
313
|
+
|
|
314
|
+
**Key question:** What happens when JavaScript fails? If a URL provides graceful degradation, a link may be the better choice.
|
|
315
|
+
|
|
316
|
+
### Unique Accessible Names for Repeated Buttons
|
|
317
|
+
|
|
318
|
+
When the same action appears multiple times on a page (e.g., "Add to cart" on each product card, "Read more" on each article), each button needs a unique accessible name so screen reader users understand which item it acts on.
|
|
319
|
+
|
|
320
|
+
Approaches (choose the simplest):
|
|
321
|
+
|
|
322
|
+
```html
|
|
323
|
+
<!-- Option 1: aria-label with full context -->
|
|
324
|
+
<button aria-label="Add Nike Pegasus 41 to cart">Add to cart</button>
|
|
325
|
+
|
|
326
|
+
<!-- Option 2: visually hidden text -->
|
|
327
|
+
<button>
|
|
328
|
+
Add to cart
|
|
329
|
+
<span class="visually-hidden">Nike Pegasus 41</span>
|
|
330
|
+
</button>
|
|
331
|
+
|
|
332
|
+
<!-- Option 3: aria-describedby pointing to the product heading -->
|
|
333
|
+
<article>
|
|
334
|
+
<h3 id="product-42">Nike Pegasus 41</h3>
|
|
335
|
+
...
|
|
336
|
+
<button aria-describedby="product-42">Add to cart</button>
|
|
337
|
+
</article>
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
The visible label should stay as "Add to cart" (sighted users understand context from position); the accessible name adds the product name for users who navigate by button list.
|
|
341
|
+
|
|
342
|
+
### Disabling Controls
|
|
343
|
+
|
|
344
|
+
`aria-disabled="true"` communicates disabled state but does **not** prevent interaction. For buttons, `disabled` both communicates state and suppresses clicks and keyboard activation. For links, `aria-disabled="true"` alone is insufficient—it still receives focus and activates. Options:
|
|
345
|
+
|
|
346
|
+
- Use a `<button disabled>` instead of a link when the action is truly unavailable
|
|
347
|
+
- Remove the `href` attribute to prevent activation (link becomes non-interactive)
|
|
348
|
+
- Handle `keydown`/`click` events explicitly if you must keep the element focusable
|
|
349
|
+
|
|
350
|
+
### The Popover API for Lightweight Overlays
|
|
351
|
+
|
|
352
|
+
For user dropdowns, action menus, and non-modal overlays, the **Popover API** (`popover` attribute) is the preferred modern approach — not custom ARIA widget patterns.
|
|
353
|
+
|
|
354
|
+
```html
|
|
355
|
+
<!-- Trigger: button with popovertarget -->
|
|
356
|
+
<button popovertarget="user-menu">
|
|
357
|
+
<img src="avatar.png" alt="" />
|
|
358
|
+
<span>Alice</span>
|
|
359
|
+
</button>
|
|
360
|
+
|
|
361
|
+
<!-- Popover: browser manages show/hide, focus, and light-dismiss -->
|
|
362
|
+
<ul id="user-menu" popover>
|
|
363
|
+
<li><a href="/profile">Profile</a></li>
|
|
364
|
+
<li><a href="/settings">Settings</a></li>
|
|
365
|
+
<li><button>Sign out</button></li>
|
|
366
|
+
</ul>
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
The browser automatically handles `aria-expanded` on the invoking button and `aria-details` when the popover isn't immediately adjacent in the DOM. No manual ARIA attributes are needed on the trigger.
|
|
370
|
+
|
|
371
|
+
**Why this is better than the ARIA menu pattern:**
|
|
372
|
+
|
|
373
|
+
- Browser handles keyboard interaction, focus management, and light-dismiss natively
|
|
374
|
+
- No `role="menu"`, `role="menuitem"`, or `role="none"` needed — the list remains a semantic `<ul>` of links and buttons
|
|
375
|
+
- ARIA menu patterns have strict interaction requirements (`Home`, `End`, character navigation) that are easy to implement incorrectly and unfamiliar to many users
|
|
376
|
+
|
|
377
|
+
**When ARIA menu patterns are appropriate:** Only when you are building a true application menu (menubar, menuitem, submenu) that mirrors desktop application behaviour. Most website navigation and user dropdowns should use the Popover API or a simple disclosure pattern instead.
|
|
378
|
+
|
|
379
|
+
### The Details/Summary Pattern
|
|
380
|
+
|
|
381
|
+
Use for progressive disclosure:
|
|
382
|
+
|
|
383
|
+
- FAQ sections
|
|
384
|
+
- Expandable content sections
|
|
385
|
+
- Collapsible navigation
|
|
386
|
+
|
|
387
|
+
**Not** a replacement for a `<button>`-controlled disclosure widget when ARIA roles (e.g., `role="menu"`, `role="dialog"`) are required. User dropdowns, menus, and modal triggers need `<button>` so that the correct ARIA pattern can be applied. `<details>/<summary>` has its own implicit semantics and cannot carry `aria-expanded` or menu roles meaningfully.
|
|
388
|
+
|
|
389
|
+
## Forms
|
|
390
|
+
|
|
391
|
+
### Grouping with Fieldset/Legend
|
|
392
|
+
|
|
393
|
+
Use `fieldset` and `legend` for **thematic grouping**, not layout:
|
|
394
|
+
|
|
395
|
+
- Address fields
|
|
396
|
+
- Personal information sections
|
|
397
|
+
- Privacy/consent checkboxes
|
|
398
|
+
- Payment details
|
|
399
|
+
- Settings sections (Profile, Notifications, Privacy)
|
|
400
|
+
|
|
401
|
+
**When section+heading isn't enough:** For groups of form controls, `<fieldset>/<legend>` provides grouping context to assistive technology that `<section>/<h2>` does not. Screen readers announce the legend before each field in the group, giving users persistent context. Use `<section>/<h2>` for non-form content regions; use `<fieldset>/<legend>` whenever the region contains a group of inputs.
|
|
402
|
+
|
|
403
|
+
Benefits:
|
|
404
|
+
|
|
405
|
+
- Enables progressive disclosure (reveal sections as user completes others)
|
|
406
|
+
- Reduces overwhelm (avoids "wall of form fields")
|
|
407
|
+
- Provides context for screen reader users
|
|
408
|
+
|
|
409
|
+
Legends can be visually hidden while still providing accessible names.
|
|
410
|
+
|
|
411
|
+
### Grouping Search and Filter Controls
|
|
412
|
+
|
|
413
|
+
`<search>` wraps the entire search/filter interface—not just the text input. If a toolbar contains a search input plus related filter selects, they belong together in one `<search>` or labelled `<form>`:
|
|
414
|
+
|
|
415
|
+
```html
|
|
416
|
+
<!-- Correct: all filter controls share a single search landmark -->
|
|
417
|
+
<search aria-label="Filter employees">
|
|
418
|
+
<label for="q">Search</label>
|
|
419
|
+
<input type="search" id="q" name="q" />
|
|
420
|
+
|
|
421
|
+
<label for="dept">Department</label>
|
|
422
|
+
<select id="dept" name="dept">
|
|
423
|
+
...
|
|
424
|
+
</select>
|
|
425
|
+
|
|
426
|
+
<label for="status">Status</label>
|
|
427
|
+
<select id="status" name="status">
|
|
428
|
+
...
|
|
429
|
+
</select>
|
|
430
|
+
|
|
431
|
+
<button type="submit">Apply filters</button>
|
|
432
|
+
</search>
|
|
433
|
+
|
|
434
|
+
<!-- Wrong: only the text input is wrapped -->
|
|
435
|
+
<search>
|
|
436
|
+
<input type="search" />
|
|
437
|
+
</search>
|
|
438
|
+
<select>
|
|
439
|
+
...
|
|
440
|
+
</select>
|
|
441
|
+
<!-- orphaned filter control -->
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### Labels
|
|
445
|
+
|
|
446
|
+
**Always use a `label` element.** No exceptions.
|
|
447
|
+
|
|
448
|
+
- Visually hidden labels are acceptable when design requires it
|
|
449
|
+
- Never rely on placeholder text as a label substitute
|
|
450
|
+
- Never use `aria-label` when a proper `label` element works
|
|
451
|
+
|
|
452
|
+
**Why placeholders fail:**
|
|
453
|
+
|
|
454
|
+
- Disappear on input (problematic for cognitive challenges, stress, or distraction)
|
|
455
|
+
- Often have poor contrast
|
|
456
|
+
- Don't provide persistent identification
|
|
457
|
+
|
|
458
|
+
### Required Fields
|
|
459
|
+
|
|
460
|
+
HTML's `required` attribute communicates required state to assistive technology, but sighted users need a visual convention too. Always pair `required` with a visible indicator:
|
|
461
|
+
|
|
462
|
+
```html
|
|
463
|
+
<!-- Pattern: asterisk with legend explaining it -->
|
|
464
|
+
<fieldset>
|
|
465
|
+
<legend>
|
|
466
|
+
Contact details <span aria-hidden="true">*</span> required fields
|
|
467
|
+
</legend>
|
|
468
|
+
|
|
469
|
+
<label for="name">Full name <span aria-hidden="true">*</span></label>
|
|
470
|
+
<input type="text" id="name" required />
|
|
471
|
+
</fieldset>
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
The `aria-hidden` on the asterisk prevents screen readers from announcing "asterisk"—they already get the required state from the `required` attribute. The legend or a page-level note explains the convention to sighted users.
|
|
475
|
+
|
|
476
|
+
### Hint Text
|
|
477
|
+
|
|
478
|
+
When inputs have format hints or helper text, associate them with the input via `aria-describedby`. This ensures screen readers announce the hint after the label, giving users the context they need before typing:
|
|
479
|
+
|
|
480
|
+
```html
|
|
481
|
+
<label for="email">Email address</label>
|
|
482
|
+
<p id="email-hint" class="hint">We'll only use this to send your receipt.</p>
|
|
483
|
+
<input type="email" id="email" aria-describedby="email-hint" />
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
Multiple associations are allowed—comma-separated IDs work for both hint and error:
|
|
487
|
+
|
|
488
|
+
```html
|
|
489
|
+
<input
|
|
490
|
+
type="email"
|
|
491
|
+
id="email"
|
|
492
|
+
aria-invalid="true"
|
|
493
|
+
aria-describedby="email-hint email-error"
|
|
494
|
+
/>
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
### Error Messages
|
|
498
|
+
|
|
499
|
+
Current best practice (due to browser support gaps with `aria-errormessage`):
|
|
500
|
+
|
|
501
|
+
1. Set `aria-invalid="true"` on the invalid input
|
|
502
|
+
2. Associate error message via `aria-describedby`
|
|
503
|
+
3. Ensure error message is actionable (state the problem AND guide the fix)
|
|
504
|
+
4. For dynamic errors (shown on blur), consider `aria-live` on the error container
|
|
505
|
+
|
|
506
|
+
```html
|
|
507
|
+
<label for="email">Email</label>
|
|
508
|
+
<input
|
|
509
|
+
type="email"
|
|
510
|
+
id="email"
|
|
511
|
+
aria-invalid="true"
|
|
512
|
+
aria-describedby="email-error"
|
|
513
|
+
/>
|
|
514
|
+
<p id="email-error" class="error">
|
|
515
|
+
Enter a valid email address, like name@example.com
|
|
516
|
+
</p>
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
## Tables
|
|
520
|
+
|
|
521
|
+
### When to Use Tables
|
|
522
|
+
|
|
523
|
+
Use a table when data has **meaningful relationships in both dimensions**:
|
|
524
|
+
|
|
525
|
+
- Data must be presented as rows AND columns
|
|
526
|
+
- Clear association between headers and data
|
|
527
|
+
- Each row has the same columns
|
|
528
|
+
- Within each column, data is of the same type
|
|
529
|
+
|
|
530
|
+
### When NOT to Use Tables
|
|
531
|
+
|
|
532
|
+
- Simple lists (one dimension)
|
|
533
|
+
- Key-value pairs (use `dl`)
|
|
534
|
+
- Form layouts
|
|
535
|
+
- Hierarchical data (use nested lists)
|
|
536
|
+
|
|
537
|
+
### Table Semantics Baseline
|
|
538
|
+
|
|
539
|
+
Always include:
|
|
540
|
+
|
|
541
|
+
- `caption` — Describes the table's purpose
|
|
542
|
+
- `thead`, `tbody`, `tfoot` — Structural grouping
|
|
543
|
+
- `th` with `scope` — Identifies header cells and their direction
|
|
544
|
+
|
|
545
|
+
### Responsive Tables
|
|
546
|
+
|
|
547
|
+
In order of preference:
|
|
548
|
+
|
|
549
|
+
1. **Hide non-essential columns** — User still gets main takeaways; offer button to show full table
|
|
550
|
+
2. **Horizontal scroll** — Preserves semantics but may challenge users with motor difficulties
|
|
551
|
+
3. **Component duplication (cards on mobile)** — Last resort; maintain accessibility in both versions
|
|
552
|
+
|
|
553
|
+
Note: Modern browsers (including Safari) no longer strip table semantics when applying `display: grid` or `display: flex`, opening new responsive possibilities.
|
|
554
|
+
|
|
555
|
+
## Code Review Checklist
|
|
556
|
+
|
|
557
|
+
When reviewing markup, look for:
|
|
558
|
+
|
|
559
|
+
### Positive Signals
|
|
560
|
+
|
|
561
|
+
- [ ] Skip navigation link(s) present as first focusable element(s)
|
|
562
|
+
- [ ] Landmark elements used appropriately
|
|
563
|
+
- [ ] Logical heading hierarchy
|
|
564
|
+
- [ ] Native interactive elements (buttons, links) used correctly
|
|
565
|
+
- [ ] Repeated action buttons have unique accessible names
|
|
566
|
+
- [ ] Forms have proper labels, fieldsets, and hint associations
|
|
567
|
+
- [ ] Required fields visually indicated with a legend explaining the convention
|
|
568
|
+
- [ ] Tables have full semantic structure
|
|
569
|
+
- [ ] ARIA used sparingly and correctly
|
|
570
|
+
|
|
571
|
+
### Warning Signs
|
|
572
|
+
|
|
573
|
+
- [ ] No skip navigation link before a `<nav>` or repeated header content
|
|
574
|
+
- [ ] High div count in non-complex components
|
|
575
|
+
- [ ] ARIA attributes compensating for missing native semantics
|
|
576
|
+
- [ ] Redundant ARIA roles on native elements (`role="list"` on `<ul>`, `role="presentation"` on `<img alt="">`)
|
|
577
|
+
- [ ] `role` attribute changing a native element's semantics without matching behaviour
|
|
578
|
+
- [ ] `aria-label` duplicating visible text (AT would read it twice or render it confusing)
|
|
579
|
+
- [ ] ARIA menu pattern (`role="menu"`, `role="menuitem"`) used for a simple user dropdown (use Popover API instead)
|
|
580
|
+
- [ ] Placeholders used as labels
|
|
581
|
+
- [ ] Heading levels chosen for visual size rather than structure
|
|
582
|
+
- [ ] Generic elements with click handlers instead of buttons/links
|
|
583
|
+
- [ ] Tables used for layout
|
|
584
|
+
- [ ] Missing form labels
|
|
585
|
+
- [ ] Repeated buttons with identical accessible names ("Add to cart" × 6)
|
|
586
|
+
- [ ] `aria-disabled` on `<a>` elements without preventing keyboard activation
|
|
587
|
+
- [ ] Filter/search controls scattered outside a `<search>` or `<form>` grouping
|
|
588
|
+
- [ ] Settings form sections using `<section>/<h2>` instead of `<fieldset>/<legend>`
|
|
589
|
+
|
|
590
|
+
## Resources
|
|
591
|
+
|
|
592
|
+
- [HTML Living Standard: Sections](https://html.spec.whatwg.org/dev/sections.html)
|
|
593
|
+
- [HTML Living Standard: Grouping Content](https://html.spec.whatwg.org/dev/grouping-content.html)
|
|
594
|
+
- [HTML Living Standard: Forms](https://html.spec.whatwg.org/dev/forms.html)
|
|
595
|
+
- [HTML Living Standard: Tables](https://html.spec.whatwg.org/dev/tables.html)
|
|
596
|
+
- [MDN: ARIA](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA)
|
|
597
|
+
|
|
598
|
+
## References
|
|
599
|
+
|
|
600
|
+
See the `references/` directory for detailed guidance on specific topics:
|
|
601
|
+
|
|
602
|
+
- `element-decision-trees.md` — Quick decision frameworks for element selection
|
|
603
|
+
- `heading-patterns.md` — Component heading patterns and configuration strategies
|