@schalkneethling/calavera-skill-frontend-engineering 0.2.0-next.1
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/calavera-artifact.json +11 -0
- package/package.json +24 -0
- package/payload/frontend-engineering/SKILL.md +24 -0
- package/payload/frontend-engineering/agents/openai.yaml +4 -0
- package/payload/frontend-engineering/references/css-authoring.md +90 -0
- package/payload/frontend-engineering/references/css-patterns.md +225 -0
- package/payload/frontend-engineering/references/semantic-html-element-decision-trees.md +109 -0
- package/payload/frontend-engineering/references/semantic-html-heading-patterns.md +279 -0
- package/payload/frontend-engineering/references/semantic-html.md +584 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Schalk Neethling
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://calavera.schalkneethling.com/schemas/calavera-artifact.schema.json",
|
|
3
|
+
"schemaVersion": 1,
|
|
4
|
+
"id": "skill-frontend-engineering",
|
|
5
|
+
"type": "skill",
|
|
6
|
+
"displayName": "Frontend engineering",
|
|
7
|
+
"payload": "payload/frontend-engineering",
|
|
8
|
+
"compatibility": {
|
|
9
|
+
"calavera": ">=2.2.0 <3"
|
|
10
|
+
}
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@schalkneethling/calavera-skill-frontend-engineering",
|
|
3
|
+
"version": "0.2.0-next.1",
|
|
4
|
+
"description": "Frontend engineering artifact for Calavera.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+ssh://git@github.com/schalkneethling/create-project-calavera.git",
|
|
9
|
+
"directory": "packages/artifacts/skill-frontend-engineering"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"calavera-artifact.json",
|
|
13
|
+
"payload"
|
|
14
|
+
],
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./calavera-artifact.json",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public",
|
|
22
|
+
"provenance": true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: frontend-engineering
|
|
3
|
+
description: Build, review, or refactor browser-facing frontend work across HTML templates, JSX/TSX, component frameworks, CSS, client-side behavior, forms, and API interaction. Use for frontend implementation that needs coordinated semantic markup, accessible styling, security-aware data handling, and appropriate frontend tests.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Frontend Engineering
|
|
7
|
+
|
|
8
|
+
Use this skill as the entry point for frontend work. Start with the relevant implementation context, then load only the guidance that applies.
|
|
9
|
+
|
|
10
|
+
## Routing
|
|
11
|
+
|
|
12
|
+
- For HTML, JSX/TSX, Twig, Astro, Vue, Svelte, Lit, MDX, or other markup-producing code, read `references/semantic-html.md`. Use `references/semantic-html-element-decision-trees.md` and `references/semantic-html-heading-patterns.md` for element or heading decisions.
|
|
13
|
+
- For CSS, Sass/Less, CSS modules, scoped styles, CSS-in-JS, layout, responsive behavior, motion, colors, focus states, or selectors, read `references/css-authoring.md` and `references/css-patterns.md`.
|
|
14
|
+
- For forms, authentication, untrusted input, browser storage, URLs, HTML injection, API calls, uploads, or other security-sensitive browser flows, load the `frontend-security` skill.
|
|
15
|
+
- For behavior changes, accessibility checks, visual changes, or regression coverage, load the `frontend-testing` skill.
|
|
16
|
+
- For a new or foundational custom-property system, load the `css-tokens` skill.
|
|
17
|
+
|
|
18
|
+
## Working Principles
|
|
19
|
+
|
|
20
|
+
1. Inspect the existing component, template, styles, and project conventions before changing them.
|
|
21
|
+
2. Prefer native HTML and browser capabilities over custom replacements.
|
|
22
|
+
3. Keep semantics, behavior, visual styling, and validation aligned without making them unnecessarily coupled.
|
|
23
|
+
4. Treat user-controlled and server-provided data as untrusted until the appropriate security guidance establishes otherwise.
|
|
24
|
+
5. Add focused tests that protect the changed user-visible behavior and accessibility contract.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# CSS Coder
|
|
2
|
+
|
|
3
|
+
Guidance for writing CSS that prioritizes web standards, accessibility, performance, and maintainability.
|
|
4
|
+
|
|
5
|
+
## Core Principles
|
|
6
|
+
|
|
7
|
+
1. **Web standards first** — Use native CSS features before reaching for libraries or frameworks. No Tailwind, no CSS-in-JS unless explicitly requested.
|
|
8
|
+
2. **Accessibility as a requirement** — Ensure styles support, never hinder, assistive technologies. Respect user preferences (motion, color scheme, contrast).
|
|
9
|
+
3. **Performance matters** — Minimize repaints, avoid layout thrashing, use efficient selectors.
|
|
10
|
+
4. **Readable over clever** — Future maintainers (including the author) should understand the code at a glance.
|
|
11
|
+
5. **Explicit over implicit** — Avoid magic numbers and unexplained values. Use custom properties for shared values.
|
|
12
|
+
|
|
13
|
+
## Workflow
|
|
14
|
+
|
|
15
|
+
1. **Check references first** — Before writing CSS, consult `css-patterns.md` for established patterns and snippets.
|
|
16
|
+
2. **Validate against specs** — When uncertain, reference MDN Web Docs or CSS specifications.
|
|
17
|
+
3. **Suggest alternatives** — Offer ideas beyond the skill's patterns when appropriate, but always aligned with the core principles above.
|
|
18
|
+
|
|
19
|
+
## Writing Guidelines
|
|
20
|
+
|
|
21
|
+
### Selectors
|
|
22
|
+
|
|
23
|
+
- Prefer class selectors over element or ID selectors for styling.
|
|
24
|
+
- Keep specificity low and predictable.
|
|
25
|
+
- Avoid deep nesting (aim for 2-3 levels maximum).
|
|
26
|
+
|
|
27
|
+
### Custom Properties
|
|
28
|
+
|
|
29
|
+
- Use `--` prefixed custom properties for colors, spacing, typography, and other repeated values.
|
|
30
|
+
- Define at `:root` or appropriate scope.
|
|
31
|
+
- Name descriptively: `--color-primary`, `--spacing-md`, `--font-size-body`.
|
|
32
|
+
|
|
33
|
+
### Logical Properties
|
|
34
|
+
|
|
35
|
+
- Always use logical properties (`margin-inline`, `padding-block`, `inset-inline-start`, `block-size`, etc.) instead of physical properties (`margin-left`, `padding-top`, `left`, `height`, etc.).
|
|
36
|
+
- Logical properties support internationalization and different writing modes automatically.
|
|
37
|
+
- Only fall back to physical properties where logical equivalents do not yet exist.
|
|
38
|
+
|
|
39
|
+
### Units
|
|
40
|
+
|
|
41
|
+
- Use `rem` for typography and spacing (respects user font-size preferences).
|
|
42
|
+
- Use `em` for component-relative sizing when appropriate.
|
|
43
|
+
- Use viewport units (`vw`, `vh`, `dvh`) thoughtfully, with fallbacks where needed.
|
|
44
|
+
- Avoid `px` for font sizes; acceptable for borders, shadows, and fine details.
|
|
45
|
+
|
|
46
|
+
### Colors
|
|
47
|
+
|
|
48
|
+
- Use modern space-separated syntax for all color functions (`rgb()`, `hsl()`, `oklch()`).
|
|
49
|
+
- Recommend `oklch()` for vibrant or wide-gamut colors.
|
|
50
|
+
- Use relative color syntax to derive hover states or transparent variants from existing variables.
|
|
51
|
+
- See `css-patterns.md` for syntax examples.
|
|
52
|
+
|
|
53
|
+
### Layout
|
|
54
|
+
|
|
55
|
+
- Use CSS Grid for two-dimensional layouts, or when vertical flow is needed without extra declarations.
|
|
56
|
+
- Use Flexbox for one-dimensional alignment, noting it defaults to `row` direction.
|
|
57
|
+
- Avoid floats for layout (legacy use only).
|
|
58
|
+
|
|
59
|
+
### Media Queries
|
|
60
|
+
|
|
61
|
+
- Use modern range syntax: `@media (width < 48rem)`, `@media (width >= 48rem)`.
|
|
62
|
+
- Prefer **Shared First** over mobile-first: define shared styles outside queries, scope viewport-specific styles with bounded queries.
|
|
63
|
+
- Keep breakpoints to a minimum — add more only when there's a clear need.
|
|
64
|
+
- See `css-patterns.md` for detailed examples.
|
|
65
|
+
|
|
66
|
+
### Accessibility
|
|
67
|
+
|
|
68
|
+
- Never use `display: none` or `visibility: hidden` to hide content that should remain accessible to screen readers. Use appropriate techniques from the references.
|
|
69
|
+
- Respect `prefers-reduced-motion`, `prefers-color-scheme`, and `prefers-contrast`.
|
|
70
|
+
- Ensure sufficient color contrast (WCAG AA minimum, AAA preferred).
|
|
71
|
+
- Maintain visible focus indicators — never remove `:focus` styles without replacement.
|
|
72
|
+
|
|
73
|
+
### Performance
|
|
74
|
+
|
|
75
|
+
- Avoid expensive properties in animations (prefer `transform` and `opacity`).
|
|
76
|
+
- Use `will-change` sparingly and only when needed.
|
|
77
|
+
- Minimize use of `*` selectors.
|
|
78
|
+
- Prefer `@layer` for managing cascade when working with larger codebases.
|
|
79
|
+
|
|
80
|
+
## References
|
|
81
|
+
|
|
82
|
+
Consult `css-patterns.md` for:
|
|
83
|
+
|
|
84
|
+
- Visually-hidden utility
|
|
85
|
+
- User preference queries (motion, color scheme, contrast)
|
|
86
|
+
- Modern color syntax and relative colors
|
|
87
|
+
- Shared First responsive patterns
|
|
88
|
+
- Any project-specific conventions
|
|
89
|
+
|
|
90
|
+
This file will grow as patterns are added. If a needed pattern doesn't exist, suggest one aligned with the core principles.
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# CSS Patterns and Snippets
|
|
2
|
+
|
|
3
|
+
This file contains reusable CSS patterns, snippets, and conventions. Consult before writing CSS.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Utility Patterns
|
|
8
|
+
|
|
9
|
+
### Visually Hidden (Screen Reader Only)
|
|
10
|
+
|
|
11
|
+
Use when content should be accessible to assistive technologies but not visible on screen.
|
|
12
|
+
|
|
13
|
+
```css
|
|
14
|
+
.visually-hidden {
|
|
15
|
+
position: absolute;
|
|
16
|
+
width: 1px;
|
|
17
|
+
height: 1px;
|
|
18
|
+
padding: 0;
|
|
19
|
+
margin: -1px;
|
|
20
|
+
overflow: hidden;
|
|
21
|
+
clip: rect(0, 0, 0, 0);
|
|
22
|
+
white-space: nowrap;
|
|
23
|
+
border: 0;
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## User Preference Queries
|
|
30
|
+
|
|
31
|
+
### Reduced Motion
|
|
32
|
+
|
|
33
|
+
Always wrap animations and transitions for users who prefer reduced motion.
|
|
34
|
+
|
|
35
|
+
```css
|
|
36
|
+
@media (prefers-reduced-motion: reduce) {
|
|
37
|
+
*,
|
|
38
|
+
*::before,
|
|
39
|
+
*::after {
|
|
40
|
+
animation-duration: 0.01ms !important;
|
|
41
|
+
animation-iteration-count: 1 !important;
|
|
42
|
+
scroll-behavior: auto !important;
|
|
43
|
+
transition-duration: 0.01ms !important;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Color Scheme
|
|
49
|
+
|
|
50
|
+
```css
|
|
51
|
+
@media (prefers-color-scheme: dark) {
|
|
52
|
+
:root {
|
|
53
|
+
/* dark mode custom properties */
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### High Contrast
|
|
59
|
+
|
|
60
|
+
```css
|
|
61
|
+
@media (prefers-contrast: more) {
|
|
62
|
+
:root {
|
|
63
|
+
/* increased contrast custom properties */
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Color Patterns
|
|
71
|
+
|
|
72
|
+
### Modern Color Syntax
|
|
73
|
+
|
|
74
|
+
Always use space-separated syntax for color functions. This is the current standard and required for modern color features.
|
|
75
|
+
|
|
76
|
+
```css
|
|
77
|
+
/* Legacy — avoid */
|
|
78
|
+
.legacy {
|
|
79
|
+
background-color: hsla(10, 100%, 50%, 0.75);
|
|
80
|
+
color: rgba(0, 0, 0, 0.9);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* Modern — preferred */
|
|
84
|
+
.modern {
|
|
85
|
+
background-color: hsl(10 100% 50% / 0.75);
|
|
86
|
+
color: rgb(0 0 0 / 0.9);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Key points:
|
|
91
|
+
|
|
92
|
+
- Use `rgb()` and `hsl()` — the `a` suffix (`rgba`, `hsla`) is no longer needed.
|
|
93
|
+
- Separate components with spaces, not commas.
|
|
94
|
+
- Use `/` before the alpha value for transparency.
|
|
95
|
+
|
|
96
|
+
### Wide Gamut Colors (oklch, oklab)
|
|
97
|
+
|
|
98
|
+
Use `oklch()` when users request "vibrant", "bright", or "punchy" colors. It supports a wider gamut than sRGB and is perceptually uniform, making adjustments more predictable.
|
|
99
|
+
|
|
100
|
+
```css
|
|
101
|
+
:root {
|
|
102
|
+
--color-accent: oklch(65% 0.25 340);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Note: `oklch()`, `oklab()`, and `color()` only support space-separated syntax.
|
|
107
|
+
|
|
108
|
+
### Relative Color Syntax
|
|
109
|
+
|
|
110
|
+
Use relative colors to derive variations (hover states, overlays, tints) from existing brand variables without defining new custom properties.
|
|
111
|
+
|
|
112
|
+
Syntax: `function(from [base-color] [components] / [alpha])`
|
|
113
|
+
|
|
114
|
+
```css
|
|
115
|
+
:root {
|
|
116
|
+
--color-brand: oklch(55% 0.2 250);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.button {
|
|
120
|
+
background-color: var(--color-brand);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.button:hover {
|
|
124
|
+
/* Lighten by adjusting the L channel */
|
|
125
|
+
background-color: oklch(from var(--color-brand) calc(l + 0.1) c h);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.overlay {
|
|
129
|
+
/* Apply 50% opacity to brand color */
|
|
130
|
+
background-color: oklch(from var(--color-brand) l c h / 0.5);
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Responsive Patterns
|
|
137
|
+
|
|
138
|
+
### Shared First (Preferred over Mobile First)
|
|
139
|
+
|
|
140
|
+
Avoid traditional mobile-first CSS where styles "bleed up" through open-ended `min-width` queries, requiring constant overrides. Instead, use a **Shared First** approach:
|
|
141
|
+
|
|
142
|
+
1. Define only truly shared styles outside media queries.
|
|
143
|
+
2. Use bounded media queries to scope styles to specific viewport ranges.
|
|
144
|
+
3. Keep breakpoints to a minimum — add more only when there's a clear need.
|
|
145
|
+
|
|
146
|
+
Use modern range syntax for all media queries:
|
|
147
|
+
|
|
148
|
+
```css
|
|
149
|
+
@media (width < 48rem) {
|
|
150
|
+
/* below breakpoint */
|
|
151
|
+
}
|
|
152
|
+
@media (width >= 48rem) {
|
|
153
|
+
/* at or above breakpoint */
|
|
154
|
+
}
|
|
155
|
+
@media (48rem <= width < 64rem) {
|
|
156
|
+
/* between breakpoints */
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Why Shared First?**
|
|
161
|
+
|
|
162
|
+
- **Fewer side effects** — Changes to one viewport don't accidentally affect others.
|
|
163
|
+
- **Easier debugging** — DevTools shows fewer overridden (struck-through) properties.
|
|
164
|
+
- **Clearer intent** — Each viewport's styles are self-contained.
|
|
165
|
+
|
|
166
|
+
```css
|
|
167
|
+
/* Mobile First — avoid */
|
|
168
|
+
body {
|
|
169
|
+
display: flex;
|
|
170
|
+
flex-direction: column;
|
|
171
|
+
gap: 1rem;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
@media (min-width: 48rem) {
|
|
175
|
+
body {
|
|
176
|
+
flex-direction: row;
|
|
177
|
+
gap: 2rem;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
```css
|
|
183
|
+
/* Shared First — preferred */
|
|
184
|
+
body {
|
|
185
|
+
display: flex;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@media (width < 48rem) {
|
|
189
|
+
body {
|
|
190
|
+
flex-direction: column;
|
|
191
|
+
gap: 1rem;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
@media (width >= 48rem) {
|
|
196
|
+
body {
|
|
197
|
+
flex-direction: row;
|
|
198
|
+
gap: 2rem;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
The Shared First approach may use more lines, but results in more maintainable, predictable CSS with fewer debugging headaches.
|
|
204
|
+
|
|
205
|
+
#### Using Custom Properties with Shared First
|
|
206
|
+
|
|
207
|
+
Custom properties can reduce repetition by keeping the property declaration shared while scoping only the value to each viewport. Use sparingly — overuse can make code harder to follow.
|
|
208
|
+
|
|
209
|
+
```css
|
|
210
|
+
.Dialog-container {
|
|
211
|
+
padding-block: var(--Dialog-block-padding);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
@media (width < 48rem) {
|
|
215
|
+
.Dialog-container {
|
|
216
|
+
--Dialog-block-padding: var(--size-16);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@media (width >= 48rem) {
|
|
221
|
+
.Dialog-container {
|
|
222
|
+
--Dialog-block-padding: var(--size-32);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
```
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# Element Decision Trees
|
|
2
|
+
|
|
3
|
+
Quick decision frameworks for selecting the right HTML element.
|
|
4
|
+
|
|
5
|
+
## Is It a List?
|
|
6
|
+
|
|
7
|
+
```text
|
|
8
|
+
Are the items related siblings?
|
|
9
|
+
├─ No → Consider plain elements with appropriate structure
|
|
10
|
+
└─ Yes → Are these term-description pairs?
|
|
11
|
+
├─ Yes → <dl>
|
|
12
|
+
└─ No → Are items sequential/ranked?
|
|
13
|
+
├─ Yes → <ol>
|
|
14
|
+
└─ No → <ul>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Is It a Table?
|
|
18
|
+
|
|
19
|
+
```text
|
|
20
|
+
Does data have meaningful rows AND columns?
|
|
21
|
+
├─ No → Not a table
|
|
22
|
+
│ ├─ One dimension only → List or plain elements
|
|
23
|
+
│ ├─ Key-value pairs → <dl>
|
|
24
|
+
│ └─ Hierarchical → Nested lists or other structure
|
|
25
|
+
└─ Yes → Does each row have the same columns?
|
|
26
|
+
├─ No → Reconsider data structure
|
|
27
|
+
└─ Yes → Use <table> with full semantics
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Button or Link?
|
|
31
|
+
|
|
32
|
+
```text
|
|
33
|
+
Does this navigate to a new URL?
|
|
34
|
+
├─ Yes → <a href="...">
|
|
35
|
+
└─ No → Does an action occur?
|
|
36
|
+
├─ Yes → Would a URL provide useful fallback if JS fails?
|
|
37
|
+
│ ├─ Yes → <a href="..."> with JS enhancement
|
|
38
|
+
│ └─ No → <button>
|
|
39
|
+
└─ No → Reconsider if interaction is needed
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Section or Div?
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
Does this content form a thematic grouping?
|
|
46
|
+
├─ No → <div>
|
|
47
|
+
└─ Yes → Can you provide a meaningful accessible name?
|
|
48
|
+
├─ Yes → <section aria-labelledby="...">
|
|
49
|
+
└─ No → <div> (section without label ≈ div semantically)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Article Candidate?
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
Would this content make sense standalone?
|
|
56
|
+
├─ Yes → Could it be syndicated or extracted?
|
|
57
|
+
│ ├─ Yes → <article>
|
|
58
|
+
│ └─ No → Use appropriate container (section, div, etc.)
|
|
59
|
+
└─ No → Use appropriate container (section, div, etc.)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Which Landmark?
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
What is this section's purpose?
|
|
66
|
+
├─ Site/section header → <header>
|
|
67
|
+
├─ Site/section footer → <footer>
|
|
68
|
+
├─ Navigation → <nav> (one may be unnamed; give multiple landmarks distinct names, preferably from visible text via aria-labelledby, without the word “navigation”)
|
|
69
|
+
├─ Primary page content → <main>
|
|
70
|
+
├─ Search/filter functionality → <search> (wrap ALL related controls, not just the text input)
|
|
71
|
+
├─ User input → <form> (must be labelled to be a landmark)
|
|
72
|
+
├─ Tangentially related → <aside>
|
|
73
|
+
├─ Self-contained content → <article>
|
|
74
|
+
└─ Thematic grouping with label → <section aria-labelledby="...">
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Form Field Grouping
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
Do these fields form a logical/thematic group?
|
|
81
|
+
├─ Yes → Are they form controls (inputs, selects, checkboxes)?
|
|
82
|
+
│ ├─ Yes → <fieldset> with <legend>
|
|
83
|
+
│ └─ No → <section aria-labelledby="...">
|
|
84
|
+
└─ No → Is visual grouping needed?
|
|
85
|
+
├─ Yes → <div> with appropriate styling
|
|
86
|
+
└─ No → Fields can exist without wrapper
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Interactive Disclosure
|
|
90
|
+
|
|
91
|
+
```text
|
|
92
|
+
Should content be expandable/collapsible?
|
|
93
|
+
├─ Yes → Does the disclosed content need ARIA roles (menu, dialog, etc.)?
|
|
94
|
+
│ ├─ Yes → <button> controlling visibility + appropriate ARIA
|
|
95
|
+
│ └─ No → Is it a single content section?
|
|
96
|
+
│ ├─ Yes → <details>/<summary>
|
|
97
|
+
│ └─ No → Consider tab pattern or custom disclosure
|
|
98
|
+
└─ No → Is it a list of definitions?
|
|
99
|
+
└─ Yes → <dl> (not details/summary)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Skip Navigation
|
|
103
|
+
|
|
104
|
+
```text
|
|
105
|
+
Does the page have a <nav> or repeated content before <main>?
|
|
106
|
+
└─ Yes → Add <a href="#main-content"> as the first element in <body>
|
|
107
|
+
Does the page have a prominent search bar or long sidebar?
|
|
108
|
+
└─ Yes → Add additional skip links to those targets
|
|
109
|
+
```
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# Heading Patterns in Component Systems
|
|
2
|
+
|
|
3
|
+
Strategies for maintaining proper heading hierarchy in component-based architectures.
|
|
4
|
+
|
|
5
|
+
## The Challenge
|
|
6
|
+
|
|
7
|
+
Component-based development creates a tension:
|
|
8
|
+
|
|
9
|
+
- Components should be reusable across contexts
|
|
10
|
+
- Heading levels depend on surrounding document structure
|
|
11
|
+
- Content authors may not understand heading hierarchy
|
|
12
|
+
- Hardcoded levels break in different contexts
|
|
13
|
+
|
|
14
|
+
## Pattern 1: Configurable Heading Level
|
|
15
|
+
|
|
16
|
+
Make heading level a prop/parameter with a sensible default.
|
|
17
|
+
|
|
18
|
+
```jsx
|
|
19
|
+
// React example
|
|
20
|
+
function Card({ title, headingLevel = 3, children }) {
|
|
21
|
+
const safeHeadingLevel = Math.min(6, Math.max(1, Number(headingLevel) || 3));
|
|
22
|
+
const Heading = `h${safeHeadingLevel}`;
|
|
23
|
+
return (
|
|
24
|
+
<article className="card">
|
|
25
|
+
<Heading>{title}</Heading>
|
|
26
|
+
{children}
|
|
27
|
+
</article>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```twig
|
|
33
|
+
{# Twig example #}
|
|
34
|
+
{% set requested_level = heading_level|default(3) %}
|
|
35
|
+
{% set heading_tag = requested_level < 1 ? 1 : requested_level > 6 ? 6 : requested_level %}
|
|
36
|
+
<article class="card">
|
|
37
|
+
<h{{ heading_tag }}>{{ title }}</h{{ heading_tag }}>
|
|
38
|
+
{{ content }}
|
|
39
|
+
</article>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### When to Use
|
|
43
|
+
|
|
44
|
+
- Generic components used in multiple contexts
|
|
45
|
+
- Components where nesting depth varies
|
|
46
|
+
- CMS-driven content where authors control usage
|
|
47
|
+
|
|
48
|
+
### Trade-offs
|
|
49
|
+
|
|
50
|
+
- Moves responsibility to component consumer
|
|
51
|
+
- Authors may not choose correctly
|
|
52
|
+
- Sensible default reduces but doesn't eliminate risk
|
|
53
|
+
|
|
54
|
+
## Pattern 2: Context-Aware Defaults
|
|
55
|
+
|
|
56
|
+
Set defaults based on known component relationships.
|
|
57
|
+
|
|
58
|
+
```jsx
|
|
59
|
+
// Section always starts a new heading context
|
|
60
|
+
function Section({ id, title, children }) {
|
|
61
|
+
const headingId = `${id}-section-title`;
|
|
62
|
+
return (
|
|
63
|
+
<section aria-labelledby={headingId}>
|
|
64
|
+
<h2 id={headingId}>{title}</h2>
|
|
65
|
+
{children}
|
|
66
|
+
</section>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Cards within sections default to h3
|
|
71
|
+
function CardList({ cards }) {
|
|
72
|
+
return (
|
|
73
|
+
<ul className="card-list">
|
|
74
|
+
{cards.map((card) => (
|
|
75
|
+
<li key={card.id}>
|
|
76
|
+
<Card title={card.title} headingLevel={3} />
|
|
77
|
+
</li>
|
|
78
|
+
))}
|
|
79
|
+
</ul>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### When to Use
|
|
85
|
+
|
|
86
|
+
- Known parent-child component relationships
|
|
87
|
+
- Design systems with predictable nesting patterns
|
|
88
|
+
- When you control both container and child components
|
|
89
|
+
|
|
90
|
+
### Trade-offs
|
|
91
|
+
|
|
92
|
+
- Less flexible
|
|
93
|
+
- Breaks if components are used outside expected context
|
|
94
|
+
- Requires documentation of expected usage
|
|
95
|
+
|
|
96
|
+
## Pattern 3: Heading Component Abstraction
|
|
97
|
+
|
|
98
|
+
Create a heading component that handles both semantic and visual concerns.
|
|
99
|
+
|
|
100
|
+
```jsx
|
|
101
|
+
function Heading({ level, visualLevel = level, children, className = "" }) {
|
|
102
|
+
const semanticLevel = Math.min(6, Math.max(1, Number(level) || 2));
|
|
103
|
+
const visualHeadingLevel = Math.min(6, Math.max(1, Number(visualLevel) || semanticLevel));
|
|
104
|
+
const Tag = `h${semanticLevel}`;
|
|
105
|
+
const visualClass = `u-heading-${visualHeadingLevel}`;
|
|
106
|
+
|
|
107
|
+
return <Tag className={`${visualClass} ${className}`}>{children}</Tag>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Usage: semantic h3, visual appearance of h2
|
|
111
|
+
<Heading level={3} visualLevel={2}>
|
|
112
|
+
Section Title
|
|
113
|
+
</Heading>;
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### When to Use
|
|
117
|
+
|
|
118
|
+
- Design requires visual hierarchy different from semantic
|
|
119
|
+
- Large headings needed at deep nesting levels
|
|
120
|
+
- Consistent visual treatment across varying semantic levels
|
|
121
|
+
|
|
122
|
+
### Benefits
|
|
123
|
+
|
|
124
|
+
- Separates concerns clearly
|
|
125
|
+
- Documents the distinction explicitly
|
|
126
|
+
- Enables correct semantics without design compromise
|
|
127
|
+
|
|
128
|
+
## Pattern 4: Inherited Configuration
|
|
129
|
+
|
|
130
|
+
Generic components inherit heading config when specialised.
|
|
131
|
+
|
|
132
|
+
```jsx
|
|
133
|
+
// Generic card
|
|
134
|
+
function Card({ title, headingLevel = 3, headingClass, children }) {
|
|
135
|
+
const safeHeadingLevel = Math.min(6, Math.max(1, Number(headingLevel) || 3));
|
|
136
|
+
const Heading = `h${safeHeadingLevel}`;
|
|
137
|
+
return (
|
|
138
|
+
<article className="card">
|
|
139
|
+
<Heading className={headingClass}>{title}</Heading>
|
|
140
|
+
{children}
|
|
141
|
+
</article>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Specialised product card - knows its context
|
|
146
|
+
function ProductCard({ product, headingLevel = 3 }) {
|
|
147
|
+
return (
|
|
148
|
+
<Card title={product.name} headingLevel={headingLevel} headingClass="product-card__title">
|
|
149
|
+
<p className="product-card__price">{product.price}</p>
|
|
150
|
+
<p className="product-card__description">{product.description}</p>
|
|
151
|
+
</Card>
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Page section - sets context for children
|
|
156
|
+
function FeaturedProducts({ id, products }) {
|
|
157
|
+
const headingId = `${id}-featured-heading`;
|
|
158
|
+
return (
|
|
159
|
+
<section aria-labelledby={headingId}>
|
|
160
|
+
<h2 id={headingId}>Featured Products</h2>
|
|
161
|
+
<ul className="product-grid">
|
|
162
|
+
{products.map((product) => (
|
|
163
|
+
<li key={product.id}>
|
|
164
|
+
<ProductCard product={product} headingLevel={3} />
|
|
165
|
+
</li>
|
|
166
|
+
))}
|
|
167
|
+
</ul>
|
|
168
|
+
</section>
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### When to Use
|
|
174
|
+
|
|
175
|
+
- Design systems with component inheritance
|
|
176
|
+
- When generic components are always wrapped by specific ones
|
|
177
|
+
- Clear ownership of heading level decision
|
|
178
|
+
|
|
179
|
+
## Visual-Only Headings
|
|
180
|
+
|
|
181
|
+
When text should look like a heading but not affect document outline:
|
|
182
|
+
|
|
183
|
+
```html
|
|
184
|
+
<!-- Looks like a heading, but isn't one semantically -->
|
|
185
|
+
<p class="u-heading-xl">Sale ends tomorrow!</p>
|
|
186
|
+
|
|
187
|
+
<!-- Compare to actual heading -->
|
|
188
|
+
<h2 class="u-heading-xl">Product Categories</h2>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### When to Use
|
|
192
|
+
|
|
193
|
+
- Promotional text that looks prominent but isn't structural
|
|
194
|
+
- Decorative typography
|
|
195
|
+
- Labels that don't introduce content sections
|
|
196
|
+
|
|
197
|
+
### CSS Utility Classes
|
|
198
|
+
|
|
199
|
+
```css
|
|
200
|
+
/* Size-based utilities separate from semantic level */
|
|
201
|
+
.u-heading-xs {
|
|
202
|
+
font-size: var(--font-size-xs);
|
|
203
|
+
}
|
|
204
|
+
.u-heading-s {
|
|
205
|
+
font-size: var(--font-size-s);
|
|
206
|
+
}
|
|
207
|
+
.u-heading-m {
|
|
208
|
+
font-size: var(--font-size-m);
|
|
209
|
+
}
|
|
210
|
+
.u-heading-l {
|
|
211
|
+
font-size: var(--font-size-l);
|
|
212
|
+
}
|
|
213
|
+
.u-heading-xl {
|
|
214
|
+
font-size: var(--font-size-xl);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/* All share heading-like properties */
|
|
218
|
+
.u-heading-xs,
|
|
219
|
+
.u-heading-s,
|
|
220
|
+
.u-heading-m,
|
|
221
|
+
.u-heading-l,
|
|
222
|
+
.u-heading-xl {
|
|
223
|
+
font-weight: var(--font-weight-bold);
|
|
224
|
+
line-height: var(--line-height-tight);
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Checklist for Component Headings
|
|
229
|
+
|
|
230
|
+
When building a component with a heading:
|
|
231
|
+
|
|
232
|
+
- [ ] Is the heading level configurable?
|
|
233
|
+
- [ ] Is there a sensible default?
|
|
234
|
+
- [ ] Is the default documented?
|
|
235
|
+
- [ ] Can visual appearance be controlled independently?
|
|
236
|
+
- [ ] Does the component work at all reasonable heading levels?
|
|
237
|
+
- [ ] Is the expected context documented?
|
|
238
|
+
|
|
239
|
+
## Common Mistakes
|
|
240
|
+
|
|
241
|
+
### Hardcoded Levels
|
|
242
|
+
|
|
243
|
+
```jsx
|
|
244
|
+
// Fragile: breaks when used outside expected context
|
|
245
|
+
function Card({ title }) {
|
|
246
|
+
return (
|
|
247
|
+
<article>
|
|
248
|
+
<h3>{title}</h3> {/* What if this is used at h2 level? */}
|
|
249
|
+
</article>
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
### Level Chosen for Appearance
|
|
255
|
+
|
|
256
|
+
```html
|
|
257
|
+
<!-- Wrong: h4 chosen because it's smaller -->
|
|
258
|
+
<h4 class="card-title">Product Name</h4>
|
|
259
|
+
|
|
260
|
+
<!-- Right: appropriate level with visual override -->
|
|
261
|
+
<h3 class="card-title u-heading-s">Product Name</h3>
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### Missing Defaults
|
|
265
|
+
|
|
266
|
+
```jsx
|
|
267
|
+
// Dangerous: undefined heading level
|
|
268
|
+
function Card({ title, headingLevel }) {
|
|
269
|
+
const Heading = `h${headingLevel}`; // h undefined if not passed
|
|
270
|
+
return <Heading>{title}</Heading>;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Safe: always has a valid level
|
|
274
|
+
function Card({ title, headingLevel = 3 }) {
|
|
275
|
+
const normalizedLevel = Math.min(6, Math.max(1, Number(headingLevel) || 3));
|
|
276
|
+
const Heading = `h${normalizedLevel}`;
|
|
277
|
+
return <Heading>{title}</Heading>;
|
|
278
|
+
}
|
|
279
|
+
```
|
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
# Semantic HTML
|
|
2
|
+
|
|
3
|
+
Write HTML that conveys meaning, serves all users, and respects the web platform.
|
|
4
|
+
|
|
5
|
+
## When to Use This Skill
|
|
6
|
+
|
|
7
|
+
Use this skill when:
|
|
8
|
+
|
|
9
|
+
- Creating new components or page sections
|
|
10
|
+
- Reviewing markup for accessibility and semantics
|
|
11
|
+
- Deciding between native HTML elements and ARIA attributes
|
|
12
|
+
- Structuring documents with proper heading hierarchy
|
|
13
|
+
- Making interactive elements accessible
|
|
14
|
+
- Building forms with proper labelling and error handling
|
|
15
|
+
- Creating responsive tables
|
|
16
|
+
|
|
17
|
+
## Core Principles
|
|
18
|
+
|
|
19
|
+
### Content Realism
|
|
20
|
+
|
|
21
|
+
Design content is idealized. Real content is messy. Always account for:
|
|
22
|
+
|
|
23
|
+
- Long sentences and long words
|
|
24
|
+
- Images with varying aspect ratios and sizes
|
|
25
|
+
- Multi-language support (even if not planned—users can translate via browser)
|
|
26
|
+
- Dynamic content that changes in length and structure
|
|
27
|
+
|
|
28
|
+
Build components that handle real-world content gracefully, not just what looks good in design tools.
|
|
29
|
+
|
|
30
|
+
### Landmarks-First Planning
|
|
31
|
+
|
|
32
|
+
Before diving into individual components, consider the full page structure. This allows you to:
|
|
33
|
+
|
|
34
|
+
- Identify key landmarks for assistive technology users
|
|
35
|
+
- Plan heading hierarchy across the document
|
|
36
|
+
- Make informed decisions about element choice
|
|
37
|
+
- Avoid overusing landmarks (which diminishes their usefulness)
|
|
38
|
+
|
|
39
|
+
### Native Over ARIA
|
|
40
|
+
|
|
41
|
+
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.
|
|
42
|
+
|
|
43
|
+
**Red flag:** High div count combined with high ARIA count on non-complex components signals reaching for patches rather than foundations.
|
|
44
|
+
|
|
45
|
+
#### Redundant ARIA
|
|
46
|
+
|
|
47
|
+
Adding ARIA to elements that already carry the correct semantics is noise—it clutters the code, can confuse assistive technology, and obscures genuine intent:
|
|
48
|
+
|
|
49
|
+
```html
|
|
50
|
+
<!-- Redundant: <ul> already has list semantics -->
|
|
51
|
+
<ul role="list">
|
|
52
|
+
...
|
|
53
|
+
</ul>
|
|
54
|
+
|
|
55
|
+
<!-- Redundant: alt="" already suppresses the accessible name -->
|
|
56
|
+
<img src="avatar.png" alt="" role="presentation" />
|
|
57
|
+
|
|
58
|
+
<!-- Redundant: aria-label duplicates visible text the AT will already read -->
|
|
59
|
+
<span aria-label="Most Popular">Most Popular</span>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
#### Don't Override Native Semantics with role
|
|
63
|
+
|
|
64
|
+
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:
|
|
65
|
+
|
|
66
|
+
```html
|
|
67
|
+
<!-- Wrong: role="switch" changes what AT announces, but the element still
|
|
68
|
+
behaves like a checkbox. Use the native checkbox if switch toggle
|
|
69
|
+
semantics aren't needed, or build a proper switch widget. -->
|
|
70
|
+
<input type="checkbox" role="switch" />
|
|
71
|
+
|
|
72
|
+
<!-- Right: native checkbox, no role override needed -->
|
|
73
|
+
<input type="checkbox" />
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Only add a `role` attribute to a native element when you deliberately need different semantics and the element's behaviour genuinely matches that role.
|
|
77
|
+
|
|
78
|
+
### Separation of Visual and Semantic Hierarchy
|
|
79
|
+
|
|
80
|
+
Visual styling and semantic meaning are related but not coupled. CSS classes bridge the gap:
|
|
81
|
+
|
|
82
|
+
- Use the appropriate heading level based on document structure
|
|
83
|
+
- Apply CSS classes to control visual appearance (size, weight, colour)
|
|
84
|
+
- Create utility classes like `.u-heading-xl` for consistent visual treatment regardless of semantic level
|
|
85
|
+
|
|
86
|
+
## Document Structure
|
|
87
|
+
|
|
88
|
+
### Skip Navigation Links
|
|
89
|
+
|
|
90
|
+
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.
|
|
91
|
+
|
|
92
|
+
Place skip links as the **first focusable element** in `<body>`. They can be visually hidden and revealed on focus:
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<body>
|
|
96
|
+
<a href="#main-content" class="skip-link">Skip to main content</a>
|
|
97
|
+
<!-- optional additional skip targets -->
|
|
98
|
+
<a href="#search" class="skip-link">Skip to search</a>
|
|
99
|
+
|
|
100
|
+
<header>...</header>
|
|
101
|
+
<nav>...</nav>
|
|
102
|
+
|
|
103
|
+
<main id="main-content" tabindex="-1">...</main>
|
|
104
|
+
</body>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```css
|
|
108
|
+
.skip-link {
|
|
109
|
+
position: absolute;
|
|
110
|
+
transform: translateY(-100%);
|
|
111
|
+
}
|
|
112
|
+
.skip-link:focus {
|
|
113
|
+
transform: translateY(0);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**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.
|
|
118
|
+
|
|
119
|
+
**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.
|
|
120
|
+
|
|
121
|
+
**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.
|
|
122
|
+
|
|
123
|
+
**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.
|
|
124
|
+
|
|
125
|
+
**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.
|
|
126
|
+
|
|
127
|
+
### Landmark Elements
|
|
128
|
+
|
|
129
|
+
Use landmark elements to convey page structure:
|
|
130
|
+
|
|
131
|
+
| Element | Use When | Notes |
|
|
132
|
+
| --------- | ---------------------------- | -------------------------------------------------------------------------------- |
|
|
133
|
+
| `header` | Page or section header | Can appear multiple times in different contexts |
|
|
134
|
+
| `footer` | Page or section footer | Contact info, copyright, related links |
|
|
135
|
+
| `nav` | Navigation sections | Must be labelled; avoid "navigation" in the label (screen readers announce this) |
|
|
136
|
+
| `main` | Primary content | Only one per page; must contain the primary `<h1>` |
|
|
137
|
+
| `aside` | Tangentially related content | Content removable without changing the page's main story (sidebars, ads) |
|
|
138
|
+
| `search` | Search functionality | Contains the search form, not the results |
|
|
139
|
+
| `form` | User input | Only becomes a landmark when labelled via `aria-labelledby` or `aria-label` |
|
|
140
|
+
| `article` | Self-contained content | Would make sense syndicated or standalone |
|
|
141
|
+
| `section` | Thematic grouping | Only becomes a landmark when labelled |
|
|
142
|
+
|
|
143
|
+
#### `<main>` must contain the primary `<h1>`
|
|
144
|
+
|
|
145
|
+
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>`:
|
|
146
|
+
|
|
147
|
+
```html
|
|
148
|
+
<!-- Wrong: h1 is outside main -->
|
|
149
|
+
<header>...</header>
|
|
150
|
+
<div class="page-header"><h1>FAQ</h1></div>
|
|
151
|
+
<main>
|
|
152
|
+
<!-- screen reader users start here, after the title -->
|
|
153
|
+
</main>
|
|
154
|
+
|
|
155
|
+
<!-- Right: h1 is the first heading inside main -->
|
|
156
|
+
<header>...</header>
|
|
157
|
+
<main id="main-content" tabindex="-1">
|
|
158
|
+
<h1>FAQ</h1>
|
|
159
|
+
...
|
|
160
|
+
</main>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### The Section Element
|
|
164
|
+
|
|
165
|
+
A `section` without an accessible name behaves like a `div` semantically. When using `section`:
|
|
166
|
+
|
|
167
|
+
- Associate it with a heading via `aria-labelledby`
|
|
168
|
+
- This transforms it into a valid landmark region
|
|
169
|
+
- If you cannot provide a meaningful label, question whether `section` is the right choice
|
|
170
|
+
|
|
171
|
+
### The Article Element
|
|
172
|
+
|
|
173
|
+
Think beyond blog posts. Use `article` for any self-contained content that would make sense on its own:
|
|
174
|
+
|
|
175
|
+
- Blog posts and news articles
|
|
176
|
+
- Comments on a post
|
|
177
|
+
- Product cards in a listing
|
|
178
|
+
- Social media posts in a feed
|
|
179
|
+
- Forum posts
|
|
180
|
+
|
|
181
|
+
**Test:** Would this content make sense if extracted and placed elsewhere with no surrounding context?
|
|
182
|
+
|
|
183
|
+
### The Address Element
|
|
184
|
+
|
|
185
|
+
Often misunderstood. From the HTML specification:
|
|
186
|
+
|
|
187
|
+
> The address element represents the contact information for its nearest article or body element ancestor.
|
|
188
|
+
|
|
189
|
+
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.
|
|
190
|
+
|
|
191
|
+
### `<aside>` vs `<section>`
|
|
192
|
+
|
|
193
|
+
**The test for `<aside>`:** Would this content make sense if it were removed from the page entirely? Would the main content still be complete?
|
|
194
|
+
|
|
195
|
+
- An advertisement, a related article link, or a biographical note about the author → `<aside>` (removing it doesn't change the main message)
|
|
196
|
+
- 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)
|
|
197
|
+
|
|
198
|
+
When in doubt: if the content serves the primary purpose of the page, it belongs in a labelled `<section>`, not `<aside>`.
|
|
199
|
+
|
|
200
|
+
### The Aside Element and Pull Quotes
|
|
201
|
+
|
|
202
|
+
`<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>`:
|
|
203
|
+
|
|
204
|
+
```html
|
|
205
|
+
<!-- Correct: pull quote from the article's own content -->
|
|
206
|
+
<aside aria-label="Pull quote">
|
|
207
|
+
<p>"The biggest gains came not from new features, but from removing old ones."</p>
|
|
208
|
+
</aside>
|
|
209
|
+
|
|
210
|
+
<!-- Use blockquote for genuine external quotations -->
|
|
211
|
+
<blockquote cite="https://example.com/source">
|
|
212
|
+
<p>Quote from an external source.</p>
|
|
213
|
+
</blockquote>
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Headings
|
|
217
|
+
|
|
218
|
+
### Heading Hierarchy
|
|
219
|
+
|
|
220
|
+
Maintain a logical heading structure:
|
|
221
|
+
|
|
222
|
+
- One `h1` per page (typically the main title)
|
|
223
|
+
- Don't skip levels (h1 → h3)
|
|
224
|
+
- Headings create an outline—ensure it makes sense when read in sequence
|
|
225
|
+
|
|
226
|
+
### Headings in Components
|
|
227
|
+
|
|
228
|
+
For reusable components containing headings:
|
|
229
|
+
|
|
230
|
+
1. **Make heading level configurable** — Components may appear in different contexts
|
|
231
|
+
2. **Provide sensible defaults** — Not all content authors understand heading hierarchy
|
|
232
|
+
3. **Consider inheritance** — Generic components become specific ones; heading config should flow through
|
|
233
|
+
|
|
234
|
+
**Example pattern:**
|
|
235
|
+
|
|
236
|
+
```text
|
|
237
|
+
Card (generic) → heading level configurable, default h3
|
|
238
|
+
└─ ProductCard (specific) → inherits config, may set default based on known context
|
|
239
|
+
└─ Used in section with h2 → heading level set to h3
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Visual Heading Without Semantic Heading
|
|
243
|
+
|
|
244
|
+
Sometimes text looks like a heading but shouldn't be one semantically. Use CSS classes to apply heading-like styling without affecting document outline:
|
|
245
|
+
|
|
246
|
+
```html
|
|
247
|
+
<p class="u-heading-l">This looks like a heading</p>
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## Lists
|
|
251
|
+
|
|
252
|
+
### When to Use Lists
|
|
253
|
+
|
|
254
|
+
Lists are most useful when **knowing the number of items helps the user**:
|
|
255
|
+
|
|
256
|
+
- Navigation menus (how many options?)
|
|
257
|
+
- Search results (how many matches?)
|
|
258
|
+
- Image galleries (how many images?)
|
|
259
|
+
- Steps in a process
|
|
260
|
+
|
|
261
|
+
**Questions to ask:**
|
|
262
|
+
|
|
263
|
+
- Are these items genuinely peers?
|
|
264
|
+
- Would removing one make the others feel incomplete?
|
|
265
|
+
- Is there an implicit "here are N things" being communicated?
|
|
266
|
+
|
|
267
|
+
### List Types
|
|
268
|
+
|
|
269
|
+
| Type | Use When | Example |
|
|
270
|
+
| ------ | ---------------------------------------- | ------------------------------------- |
|
|
271
|
+
| `ul` | Unordered collection where count matters | Nav items, search results |
|
|
272
|
+
| `ol` | Sequential steps or ranked items | Recipes, instructions, top-10 lists |
|
|
273
|
+
| `dl` | Term-description pairs | Glossaries, metadata, key-value pairs |
|
|
274
|
+
| `menu` | Toolbar commands | Action buttons, not navigation |
|
|
275
|
+
|
|
276
|
+
**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.
|
|
277
|
+
|
|
278
|
+
### Definition Lists
|
|
279
|
+
|
|
280
|
+
Often overlooked or confused with `details`/`summary`. Use `dl` for:
|
|
281
|
+
|
|
282
|
+
- Glossary definitions
|
|
283
|
+
- Metadata display (label: value pairs)
|
|
284
|
+
- Any term with one or more descriptions
|
|
285
|
+
|
|
286
|
+
Note: A single `dt` can have multiple `dd` elements for multiple related descriptions.
|
|
287
|
+
|
|
288
|
+
### Decorative List Separators
|
|
289
|
+
|
|
290
|
+
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.
|
|
291
|
+
|
|
292
|
+
## Interactive Elements
|
|
293
|
+
|
|
294
|
+
### Buttons vs Links
|
|
295
|
+
|
|
296
|
+
**Traditional rule:** Buttons do things, links go places.
|
|
297
|
+
|
|
298
|
+
**Progressive enhancement lens:** If a URL provides a meaningful fallback when JavaScript fails, a link is valid even for action-like interactions.
|
|
299
|
+
|
|
300
|
+
| Interaction | Default Choice | Consider Link When |
|
|
301
|
+
| ----------------------- | -------------- | --------------------------------------------- |
|
|
302
|
+
| Show more content | `button` | URL params could load the content server-side |
|
|
303
|
+
| Toggle view (grid/list) | `button` | URL could preserve view preference |
|
|
304
|
+
| Copy to clipboard | `button` | Copied content is a shareable URL |
|
|
305
|
+
| Tab selection | `button` | URL could load specific tab content |
|
|
306
|
+
|
|
307
|
+
**Key question:** What happens when JavaScript fails? If a URL provides graceful degradation, a link may be the better choice.
|
|
308
|
+
|
|
309
|
+
### Unique Accessible Names for Repeated Buttons
|
|
310
|
+
|
|
311
|
+
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.
|
|
312
|
+
|
|
313
|
+
Approaches (choose the simplest):
|
|
314
|
+
|
|
315
|
+
```html
|
|
316
|
+
<!-- Option 1: aria-label with full context -->
|
|
317
|
+
<button aria-label="Add Nike Pegasus 41 to cart">Add to cart</button>
|
|
318
|
+
|
|
319
|
+
<!-- Option 2: visually hidden text -->
|
|
320
|
+
<button>
|
|
321
|
+
Add to cart
|
|
322
|
+
<span class="visually-hidden">Nike Pegasus 41</span>
|
|
323
|
+
</button>
|
|
324
|
+
|
|
325
|
+
<!-- Option 3: aria-labelledby combines the action and product heading -->
|
|
326
|
+
<article>
|
|
327
|
+
<h3 id="product-42">Nike Pegasus 41</h3>
|
|
328
|
+
...
|
|
329
|
+
<button aria-labelledby="add-label-42 product-42">
|
|
330
|
+
<span id="add-label-42">Add to cart</span>
|
|
331
|
+
</button>
|
|
332
|
+
</article>
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
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.
|
|
336
|
+
|
|
337
|
+
### Disabling Controls
|
|
338
|
+
|
|
339
|
+
`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:
|
|
340
|
+
|
|
341
|
+
- Use a `<button disabled>` instead of a link when the action is truly unavailable
|
|
342
|
+
- Remove the `href` attribute to prevent activation (link becomes non-interactive)
|
|
343
|
+
- Handle `keydown`/`click` events explicitly if you must keep the element focusable
|
|
344
|
+
|
|
345
|
+
### The Popover API for Lightweight Overlays
|
|
346
|
+
|
|
347
|
+
For user dropdowns, action menus, and non-modal overlays, the **Popover API** (`popover` attribute) is the preferred modern approach — not custom ARIA widget patterns.
|
|
348
|
+
|
|
349
|
+
```html
|
|
350
|
+
<!-- Trigger: button with popovertarget -->
|
|
351
|
+
<button popovertarget="user-menu">
|
|
352
|
+
<img src="avatar.png" alt="" />
|
|
353
|
+
<span>Alice</span>
|
|
354
|
+
</button>
|
|
355
|
+
|
|
356
|
+
<!-- Popover: browser manages show/hide, focus, and light-dismiss -->
|
|
357
|
+
<ul id="user-menu" popover>
|
|
358
|
+
<li><a href="/profile">Profile</a></li>
|
|
359
|
+
<li><a href="/settings">Settings</a></li>
|
|
360
|
+
<li><button>Sign out</button></li>
|
|
361
|
+
</ul>
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
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.
|
|
365
|
+
|
|
366
|
+
**Why this is better than the ARIA menu pattern:**
|
|
367
|
+
|
|
368
|
+
- Browser handles keyboard interaction, focus management, and light-dismiss natively
|
|
369
|
+
- No `role="menu"`, `role="menuitem"`, or `role="none"` needed — the list remains a semantic `<ul>` of links and buttons
|
|
370
|
+
- ARIA menu patterns have strict interaction requirements (`Home`, `End`, character navigation) that are easy to implement incorrectly and unfamiliar to many users
|
|
371
|
+
|
|
372
|
+
**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.
|
|
373
|
+
|
|
374
|
+
### The Details/Summary Pattern
|
|
375
|
+
|
|
376
|
+
Use for progressive disclosure:
|
|
377
|
+
|
|
378
|
+
- FAQ sections
|
|
379
|
+
- Expandable content sections
|
|
380
|
+
- Collapsible navigation
|
|
381
|
+
|
|
382
|
+
**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.
|
|
383
|
+
|
|
384
|
+
## Forms
|
|
385
|
+
|
|
386
|
+
### Grouping with Fieldset/Legend
|
|
387
|
+
|
|
388
|
+
Use `fieldset` and `legend` for **thematic grouping**, not layout:
|
|
389
|
+
|
|
390
|
+
- Address fields
|
|
391
|
+
- Personal information sections
|
|
392
|
+
- Privacy/consent checkboxes
|
|
393
|
+
- Payment details
|
|
394
|
+
- Settings sections (Profile, Notifications, Privacy)
|
|
395
|
+
|
|
396
|
+
**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.
|
|
397
|
+
|
|
398
|
+
Benefits:
|
|
399
|
+
|
|
400
|
+
- Enables progressive disclosure (reveal sections as user completes others)
|
|
401
|
+
- Reduces overwhelm (avoids "wall of form fields")
|
|
402
|
+
- Provides context for screen reader users
|
|
403
|
+
|
|
404
|
+
Legends can be visually hidden while still providing accessible names.
|
|
405
|
+
|
|
406
|
+
### Grouping Search and Filter Controls
|
|
407
|
+
|
|
408
|
+
`<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>`:
|
|
409
|
+
|
|
410
|
+
```html
|
|
411
|
+
<!-- Correct: all filter controls share a single search landmark -->
|
|
412
|
+
<search aria-label="Filter employees">
|
|
413
|
+
<label for="q">Search</label>
|
|
414
|
+
<input type="search" id="q" name="q" />
|
|
415
|
+
|
|
416
|
+
<label for="dept">Department</label>
|
|
417
|
+
<select id="dept" name="dept">
|
|
418
|
+
...
|
|
419
|
+
</select>
|
|
420
|
+
|
|
421
|
+
<label for="status">Status</label>
|
|
422
|
+
<select id="status" name="status">
|
|
423
|
+
...
|
|
424
|
+
</select>
|
|
425
|
+
|
|
426
|
+
<button type="submit">Apply filters</button>
|
|
427
|
+
</search>
|
|
428
|
+
|
|
429
|
+
<!-- Wrong: only the text input is wrapped -->
|
|
430
|
+
<search>
|
|
431
|
+
<input type="search" />
|
|
432
|
+
</search>
|
|
433
|
+
<select>
|
|
434
|
+
...
|
|
435
|
+
</select>
|
|
436
|
+
<!-- orphaned filter control -->
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
### Labels
|
|
440
|
+
|
|
441
|
+
**Always use a `label` element.** No exceptions.
|
|
442
|
+
|
|
443
|
+
- Visually hidden labels are acceptable when design requires it
|
|
444
|
+
- Never rely on placeholder text as a label substitute
|
|
445
|
+
- Never use `aria-label` when a proper `label` element works
|
|
446
|
+
|
|
447
|
+
**Why placeholders fail:**
|
|
448
|
+
|
|
449
|
+
- Disappear on input (problematic for cognitive challenges, stress, or distraction)
|
|
450
|
+
- Often have poor contrast
|
|
451
|
+
- Don't provide persistent identification
|
|
452
|
+
|
|
453
|
+
### Required Fields
|
|
454
|
+
|
|
455
|
+
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:
|
|
456
|
+
|
|
457
|
+
```html
|
|
458
|
+
<!-- Pattern: asterisk with legend explaining it -->
|
|
459
|
+
<fieldset>
|
|
460
|
+
<legend>Contact details <span aria-hidden="true">*</span> required fields</legend>
|
|
461
|
+
|
|
462
|
+
<label for="name">Full name <span aria-hidden="true">*</span></label>
|
|
463
|
+
<input type="text" id="name" required />
|
|
464
|
+
</fieldset>
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
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.
|
|
468
|
+
|
|
469
|
+
### Hint Text
|
|
470
|
+
|
|
471
|
+
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:
|
|
472
|
+
|
|
473
|
+
```html
|
|
474
|
+
<label for="email">Email address</label>
|
|
475
|
+
<p id="email-hint" class="hint">We'll only use this to send your receipt.</p>
|
|
476
|
+
<input type="email" id="email" aria-describedby="email-hint" />
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
Multiple associations are allowed—space-separated IDs work for both hint and error:
|
|
480
|
+
|
|
481
|
+
```html
|
|
482
|
+
<input type="email" id="email" aria-invalid="true" aria-describedby="email-hint email-error" />
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Error Messages
|
|
486
|
+
|
|
487
|
+
Current best practice (due to browser support gaps with `aria-errormessage`):
|
|
488
|
+
|
|
489
|
+
1. Set `aria-invalid="true"` on the invalid input
|
|
490
|
+
2. Associate error message via `aria-describedby`
|
|
491
|
+
3. Ensure error message is actionable (state the problem AND guide the fix)
|
|
492
|
+
4. For dynamic errors (shown on blur), consider `aria-live` on the error container
|
|
493
|
+
|
|
494
|
+
```html
|
|
495
|
+
<label for="email">Email</label>
|
|
496
|
+
<input type="email" id="email" aria-invalid="true" aria-describedby="email-error" />
|
|
497
|
+
<p id="email-error" class="error">Enter a valid email address, like name@example.com</p>
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
## Tables
|
|
501
|
+
|
|
502
|
+
### When to Use Tables
|
|
503
|
+
|
|
504
|
+
Use a table when data has **meaningful relationships in both dimensions**:
|
|
505
|
+
|
|
506
|
+
- Data must be presented as rows AND columns
|
|
507
|
+
- Clear association between headers and data
|
|
508
|
+
- Each row has the same columns
|
|
509
|
+
- Within each column, data is of the same type
|
|
510
|
+
|
|
511
|
+
### When NOT to Use Tables
|
|
512
|
+
|
|
513
|
+
- Simple lists (one dimension)
|
|
514
|
+
- Key-value pairs (use `dl`)
|
|
515
|
+
- Form layouts
|
|
516
|
+
- Hierarchical data (use nested lists)
|
|
517
|
+
|
|
518
|
+
### Table Semantics Baseline
|
|
519
|
+
|
|
520
|
+
Always include:
|
|
521
|
+
|
|
522
|
+
- `caption` — Describes the table's purpose
|
|
523
|
+
- `thead`, `tbody`, `tfoot` — Structural grouping
|
|
524
|
+
- `th` with `scope` — Identifies header cells and their direction
|
|
525
|
+
|
|
526
|
+
### Responsive Tables
|
|
527
|
+
|
|
528
|
+
In order of preference:
|
|
529
|
+
|
|
530
|
+
1. **Hide non-essential columns** — User still gets main takeaways; offer button to show full table
|
|
531
|
+
2. **Horizontal scroll** — Preserves semantics but may challenge users with motor difficulties
|
|
532
|
+
3. **Component duplication (cards on mobile)** — Last resort; maintain accessibility in both versions
|
|
533
|
+
|
|
534
|
+
Note: Modern browsers (including Safari) no longer strip table semantics when applying `display: grid` or `display: flex`, opening new responsive possibilities.
|
|
535
|
+
|
|
536
|
+
## Code Review Checklist
|
|
537
|
+
|
|
538
|
+
When reviewing markup, look for:
|
|
539
|
+
|
|
540
|
+
### Positive Signals
|
|
541
|
+
|
|
542
|
+
- [ ] Skip navigation link(s) present as first focusable element(s)
|
|
543
|
+
- [ ] Landmark elements used appropriately
|
|
544
|
+
- [ ] Logical heading hierarchy
|
|
545
|
+
- [ ] Native interactive elements (buttons, links) used correctly
|
|
546
|
+
- [ ] Repeated action buttons have unique accessible names
|
|
547
|
+
- [ ] Forms have proper labels, fieldsets, and hint associations
|
|
548
|
+
- [ ] Required fields visually indicated with a legend explaining the convention
|
|
549
|
+
- [ ] Tables have full semantic structure
|
|
550
|
+
- [ ] ARIA used sparingly and correctly
|
|
551
|
+
|
|
552
|
+
### Warning Signs
|
|
553
|
+
|
|
554
|
+
- [ ] No skip navigation link before a `<nav>` or repeated header content
|
|
555
|
+
- [ ] High div count in non-complex components
|
|
556
|
+
- [ ] ARIA attributes compensating for missing native semantics
|
|
557
|
+
- [ ] Redundant ARIA roles on native elements (`role="list"` on `<ul>`, `role="presentation"` on `<img alt="">`)
|
|
558
|
+
- [ ] `role` attribute changing a native element's semantics without matching behaviour
|
|
559
|
+
- [ ] `aria-label` duplicating visible text (AT would read it twice or render it confusing)
|
|
560
|
+
- [ ] ARIA menu pattern (`role="menu"`, `role="menuitem"`) used for a simple user dropdown (use Popover API instead)
|
|
561
|
+
- [ ] Placeholders used as labels
|
|
562
|
+
- [ ] Heading levels chosen for visual size rather than structure
|
|
563
|
+
- [ ] Generic elements with click handlers instead of buttons/links
|
|
564
|
+
- [ ] Tables used for layout
|
|
565
|
+
- [ ] Missing form labels
|
|
566
|
+
- [ ] Repeated buttons with identical accessible names ("Add to cart" × 6)
|
|
567
|
+
- [ ] `aria-disabled` on `<a>` elements without preventing keyboard activation
|
|
568
|
+
- [ ] Filter/search controls scattered outside a `<search>` or `<form>` grouping
|
|
569
|
+
- [ ] Settings form sections using `<section>/<h2>` instead of `<fieldset>/<legend>`
|
|
570
|
+
|
|
571
|
+
## Resources
|
|
572
|
+
|
|
573
|
+
- [HTML Living Standard: Sections](https://html.spec.whatwg.org/dev/sections.html)
|
|
574
|
+
- [HTML Living Standard: Grouping Content](https://html.spec.whatwg.org/dev/grouping-content.html)
|
|
575
|
+
- [HTML Living Standard: Forms](https://html.spec.whatwg.org/dev/forms.html)
|
|
576
|
+
- [HTML Living Standard: Tables](https://html.spec.whatwg.org/dev/tables.html)
|
|
577
|
+
- [MDN: ARIA](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA)
|
|
578
|
+
|
|
579
|
+
## References
|
|
580
|
+
|
|
581
|
+
Read these companion references when needed:
|
|
582
|
+
|
|
583
|
+
- `semantic-html-element-decision-trees.md` — Quick decision frameworks for element selection
|
|
584
|
+
- `semantic-html-heading-patterns.md` — Component heading patterns and configuration strategies
|