You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: semantic-html.md
+1-9Lines changed: 1 addition & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,12 +70,4 @@ function ListItem({ item }) {
70
70
71
71
## Headings Hierarchy
72
72
73
-
...
74
-
75
-
## Landmark Elements
76
-
77
-
Use landmark elements and roles, such as `<main>` and `<aside>`, to demarcate page regions as assistive technology allow the user to quickly navigate to these sections.
78
-
79
-
Read more about the use of these elements to enhance accessibility here:
Semantic structure is created with `<h1>`-`<h6>` headings, landmarks such as `<main>`, `<nav>`, `<footer>`, `<section>` (with unique labels), content markup including `<ul>` and `<ol>` lists, and more. These are incredibly important for people who rely on AT to understand the structure of a page.
Copy file name to clipboardExpand all lines: wai-aria.md
+69-2Lines changed: 69 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,9 @@ outline: "deep"
4
4
5
5
# WAI-ARIA
6
6
7
-
The[Web Accessibility Initiative - Accessible Rich Internet Applications](https://www.w3.org/WAI/intro/aria)document contains techniques for building fully accessible JavaScript widgets.
7
+
The[Web Accessibility Initiative - Accessible Rich Internet Applications](https://www.w3.org/WAI/intro/aria) (WAI-ARIA) document contains techniques for building fully accessible JavaScript widgets and web applications. It defines a set of attributes to help make web content and web applications more accessible to people with disabilities.
8
8
9
-
Note that all`aria-*`HTML attributes are fully supported in JSX. Whereas most DOM properties and attributes in React are camelCased, these attributes should be hyphen-cased (also known as kebab-case, lisp-case, etc) as they are in plain HTML:
9
+
Note that all`aria-*`HTML attributes are fully supported in JSX. Whereas most DOM properties and attributes in React are camelCased, these attributes should be hyphen-cased (also known as kebab-case, lisp-case, etc.) as they are in plain HTML:
10
10
11
11
```tsx
12
12
<input
@@ -18,3 +18,70 @@ Note that all `aria-*` HTML attributes are fully supported in JSX. Whereas mos
18
18
name="name"
19
19
/>
20
20
```
21
+
22
+
## How should we use these ARIA attributes?
23
+
24
+
While ARIA attributes are powerful tools for enhancing accessibility, it's important to use them correctly. The primary goal is to provide semantic information to assistive technologies, like screen readers, where native HTML might not be sufficient.
25
+
26
+
### Prioritize Native HTML Elements
27
+
28
+
Before resorting to ARIA, always try to use native HTML elements for their built-in semantics and accessibility features. For example, the `<label>` element is the best and preferred way to label form controls:
29
+
30
+
```html
31
+
<labelfor="nameInput">Name:</label>
32
+
<inputtype="text"id="nameInput"name="name" />
33
+
```
34
+
35
+
Linking a `label` to an input using the `for` attribute (pointing to the input's `id`) is the most robust way to ensure the input is properly labeled.
36
+
37
+
### When to Use ARIA Attributes
38
+
39
+
ARIA attributes should be used when native HTML doesn't provide the necessary semantics or when you are building custom widgets that don't have native HTML equivalents. Here are some common ARIA attributes and how to use them, inspired by insights from accessibility specialists:
40
+
41
+
1.**`aria-label`**:
42
+
43
+
-**Use Case**: Provides an accessible name for an element when there is no visible text label on the screen. This is common for icon buttons (e.g., a search button with only a magnifying glass icon) or other interactive elements where a visible label would be redundant or clunky.
44
+
-**Example (from above)**: `aria-label={labelText}` ensures that even if there's no visible label text directly associated with the input, a screen reader will announce the value of `labelText`.
45
+
-**Important**: The `aria-label` string will be announced by screen readers along with the element's role (e.g., "Search, button" or "Name, edit text").
46
+
47
+
2.**`aria-labelledby`**:
48
+
49
+
-**Use Case**: Provides an accessible name by referencing the `id`(s) of other elements on the page that serve as the label. This is useful when the labeling text is already present visually but isn't directly associated with the input using a `<label for="...">` tag, or when a label is composed of multiple text elements.
-**Don't override native semantics unless necessary**: If an HTML element already has the correct role, state, or property, you don'tneedtoaddARIAtoreiterateit.
0 commit comments