Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guideline for labeling and describing #994

Merged
merged 137 commits into from
Jun 28, 2019
Merged
Changes from 6 commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
de49b61
Guideline for labeling and describing
zcorpan Feb 28, 2019
713aa1f
Write about roles that don't get name from content
zcorpan Mar 4, 2019
ae9a5ed
Say accessible name instead of label; flesh out accessible name calcu…
zcorpan Mar 7, 2019
ce15b81
Rewrite and expand on labels
zcorpan Mar 12, 2019
f0ddc15
First draft for descriptions
zcorpan Mar 12, 2019
3e08581
Flesh out remaining text
zcorpan Mar 13, 2019
801539f
Try to address Matt's comments
zcorpan Apr 25, 2019
61f20ae
Guideline for labeling and describing
zcorpan Feb 28, 2019
8792871
Write about roles that don't get name from content
zcorpan Mar 4, 2019
c3ec1e9
Say accessible name instead of label; flesh out accessible name calcu…
zcorpan Mar 7, 2019
6b45492
Rewrite and expand on labels
zcorpan Mar 12, 2019
5727205
First draft for descriptions
zcorpan Mar 12, 2019
07cd850
Flesh out remaining text
zcorpan Mar 13, 2019
78e912c
Try to address Matt's comments
zcorpan Apr 25, 2019
a8651d1
Move draft into aria-practices.html
zcorpan Apr 29, 2019
7773aae
Fix typo
zcorpan Apr 29, 2019
54e551b
partially revised intro in markdown; will continue in aria-practices.…
mcking65 Apr 30, 2019
1bf0f40
Incomplete and rough draft of revised outline
mcking65 May 6, 2019
16008f5
more rough draft work on intro content and overall structure
mcking65 May 7, 2019
0f0524f
edits to cardinal rules
mcking65 May 9, 2019
e131ba5
Adjust IA
mcking65 May 11, 2019
a40f81b
Editorial revisions to name from content
mcking65 May 12, 2019
93c9ec7
Editorial revisions to aria-label section
mcking65 May 12, 2019
9276759
Editorial revision to aria-labelledby section
mcking65 May 12, 2019
0f48fdb
complete outline for naming techniques
mcking65 May 13, 2019
c686c11
Partial revision of name calculation section
mcking65 May 13, 2019
6574f8a
Merge branch 'master' into zcorpan/labelling-describing
mcking65 May 13, 2019
746b200
fix/change with feedback
a11ydoer May 17, 2019
490eaed
lint testing and one typo fix
a11ydoer May 17, 2019
0536ec8
fix typo
a11ydoer May 17, 2019
b4a87d8
Remove outdated markdown file
zcorpan May 20, 2019
b596c68
Skeleton table for all concrete roles
zcorpan May 20, 2019
edf4be5
Fill out name from content in the table
zcorpan May 20, 2019
7eb5d5d
Fill in parts of the table
zcorpan May 20, 2019
bdb67d6
Fix capitalization and structure of intro list
mcking65 May 28, 2019
fb4f995
Editorial revisions to clarity in naming rule 5
mcking65 May 28, 2019
82a8e82
fix typo in aria-labelledby guidance section
mcking65 May 28, 2019
702837a
remove explicit URIs from name and role guidance table
mcking65 May 28, 2019
6c64491
Provide intro to guidance by role table
mcking65 May 28, 2019
0612ba8
Add class role-reference to role links in guidance by role table
mcking65 May 28, 2019
1fd6368
Revise name guidance by role table
mcking65 Jun 1, 2019
b2e2067
Fix name on name guidance by role table
mcking65 Jun 1, 2019
c229c76
More name guidance by role
mcking65 Jun 1, 2019
8e8ec74
Update to-do description for label encapsulation
mcking65 Jun 3, 2019
6451e91
Update to-do description for labeling with legend
mcking65 Jun 3, 2019
ab90611
Introduce naming guidance by role table
mcking65 Jun 3, 2019
e2138b9
The label element
zcorpan Jun 4, 2019
66f945b
Merge branch 'master' into zcorpan/labelling-describing
mcking65 Jun 4, 2019
aa068f6
Draft effective naming guidance section
mcking65 Jun 4, 2019
5046495
Revise intro to naming guidance by role table
mcking65 Jun 4, 2019
b977ba5
More updates to naming guidance by role
mcking65 Jun 4, 2019
cccb053
Revise aria-labelledby guidance
mcking65 Jun 4, 2019
87179dc
Fieldset and legend
zcorpan Jun 5, 2019
1743094
Fix everything raised in review by @carmacleod on June 4
mcking65 Jun 9, 2019
3a005b1
Merge branch 'master' into zcorpan/labelling-describing
mcking65 Jun 10, 2019
7fb3244
More minor revisions and to-do updates
mcking65 Jun 10, 2019
32c5ca0
Add stub section for fallback descriptions
mcking65 Jun 10, 2019
7806b3e
Editorial revisions to labeling form elements section
mcking65 Jun 10, 2019
b530fea
Editorial revisions to labeling with legends section.
mcking65 Jun 10, 2019
16964ba
First draft of table and figure captions
zcorpan Jun 10, 2019
9fd5cb4
Add placeholder for section about describing with captions.
mcking65 Jun 10, 2019
892ccff
Revised based on June 10 review comments from @carmacleod.
mcking65 Jun 11, 2019
9f8aab4
Fallback names
zcorpan Jun 11, 2019
9604f46
Mention that caption/figcaption satisfy rule 2 and 3
zcorpan Jun 11, 2019
5717568
Add examples for aria-labelledby referencing a hidden element, and ad…
zcorpan Jun 11, 2019
06cc073
Replace img with input in Examples of non-recursive accessible name c…
zcorpan Jun 12, 2019
03efdcc
Expand on the accessible name calculation
zcorpan Jun 12, 2019
ae90ce1
Discourage the use of fallback naming techniques
zcorpan Jun 13, 2019
2cfd46e
Address some feedback
zcorpan Jun 13, 2019
df4bab3
Use a button instead of an alert in an example for aria-labelledby
zcorpan Jun 18, 2019
ac301c6
Write the accessible description algorithm
zcorpan Jun 18, 2019
a1bd62f
Describing Tables and Figures with Captions
zcorpan Jun 18, 2019
1e56e16
Descriptions Derived from Titles
zcorpan Jun 18, 2019
26a4b1c
Move to-dos that depend on resolution of other issues into github issues
zcorpan Jun 18, 2019
5602d9f
Merge branch 'master' into zcorpan/labelling-describing
mcking65 Jun 20, 2019
7e9e68c
Remove the Content Can Name table column
zcorpan Jun 20, 2019
66a46fc
More editorial revisions to naming guidance table
mcking65 Jun 24, 2019
1097ac6
Combobox role can be used on HTML select and input
zcorpan Jun 24, 2019
47f75ca
Avoid all-caps
zcorpan Jun 24, 2019
063a631
Recommendations for definition and term roles
zcorpan Jun 24, 2019
261a261
Recommendation for document role
zcorpan Jun 24, 2019
3e406d2
Recommendations for feed, form, navigation
zcorpan Jun 24, 2019
b87ad08
Fix markup errors
zcorpan Jun 24, 2019
3d1f8d3
Fix markup typo
zcorpan Jun 24, 2019
cd01400
Recommendation for figure
zcorpan Jun 24, 2019
73df64e
Fix a ReSpec link error
zcorpan Jun 24, 2019
dab3706
Recommendation for none/presentation
zcorpan Jun 24, 2019
6bf004f
Recommendation for rowheader
zcorpan Jun 24, 2019
014d0d8
Recommendation for menuitemcheckbox, menuitemradio, radio, switch
zcorpan Jun 24, 2019
1a25bf3
Recommendation for tab; use consistent wording for menuitemcheckbox, …
zcorpan Jun 24, 2019
6b0984b
Recommendation for tooltip (copied button, NOT alert)
zcorpan Jun 24, 2019
0a87de0
Recommendation for menu (change from Discretionary to Recommended) an…
zcorpan Jun 24, 2019
5e39a2f
Recommendation for grid, tree, treegrid, treeitem
zcorpan Jun 24, 2019
37e7136
Recommendation for gridcell
zcorpan Jun 24, 2019
66095e4
Recommendation for listbox
zcorpan Jun 24, 2019
50c9880
Recommendation for group
zcorpan Jun 24, 2019
7443aa1
Link to issue 26 for role=math
zcorpan Jun 24, 2019
4d990cc
Address feedback: necessity; remove spaces before punctuation
zcorpan Jun 24, 2019
c59cc43
Address feedback: <code> around title and placeholder
zcorpan Jun 24, 2019
774b26c
Address feedback: aria-label is not rendered visually; mention hidden…
zcorpan Jun 24, 2019
8a832bd
Address feedback: alert → button
zcorpan Jun 24, 2019
7f17265
Address feedback: Browsers → browsers
zcorpan Jun 24, 2019
8fb9dbe
Address feedback: labeling → labelling, labeled → labelled
zcorpan Jun 24, 2019
a16cf6b
Address feedback: move a paragraph in fieldset section
zcorpan Jun 24, 2019
972fe21
Address feedback: remove duplicate area alt
zcorpan Jun 24, 2019
47887c0
Address feedback: fix typo falback
zcorpan Jun 24, 2019
8de8e44
Address feedback: clarify aria-labelledby recursion is not chaining
zcorpan Jun 24, 2019
1d38d3b
Address feedback: fix typo an label; fix consistency in aria-label ex…
zcorpan Jun 24, 2019
debb672
Revise description of aria-label to clarify that the string is not vi…
mcking65 Jun 25, 2019
82f3b2f
Minor editorial revision to aria-labelledby feature list
mcking65 Jun 25, 2019
1ee6b09
Change labelled and labelling to labeled and labeling except in aria-…
mcking65 Jun 25, 2019
0797c1e
Change 'necessity' tto 'necessary' in table column description
mcking65 Jun 25, 2019
03f1ee2
Revise naming guidance for document role
mcking65 Jun 25, 2019
be8ed01
Address feedback: typo
zcorpan Jun 25, 2019
bed7986
Recommendation for note
zcorpan Jun 25, 2019
ae5938c
Recommendation for option
zcorpan Jun 25, 2019
f1b5a93
Recommendation for progressbar
zcorpan Jun 25, 2019
0e10d37
Recommendation for radiogroup
zcorpan Jun 26, 2019
50fc11d
Recommendation for region, search
zcorpan Jun 26, 2019
ffc6261
Recommendation for scrollbar
zcorpan Jun 26, 2019
788130a
Recommendation for searchbox, textbox
zcorpan Jun 26, 2019
ef3d1f9
Recommendation for table
zcorpan Jun 26, 2019
a0f4104
Recommendation for tablist
zcorpan Jun 26, 2019
a735dc8
Recommendation for tabpanel
zcorpan Jun 26, 2019
ef6c098
Recommendation for rowgroup (WIP)
zcorpan Jun 26, 2019
9ffece9
Change visible title to visible label
zcorpan Jun 26, 2019
ab3f3cc
Recommendation for scrollbar
zcorpan Jun 26, 2019
9704274
Recommendation for separator
zcorpan Jun 26, 2019
2badb95
Recommendation for status
zcorpan Jun 26, 2019
875a294
Recommendation for toolbar
zcorpan Jun 26, 2019
dee5cec
Notes on how name from content works for treeitem and menuitem
zcorpan Jun 26, 2019
45f39da
Add text and examples for how name from content excludes stuff for tr…
zcorpan Jun 26, 2019
f55702a
Move the example with a hidden element referenced from aria-labelledby
zcorpan Jun 26, 2019
1db2ced
Add math guidance and some editorial revisions
mcking65 Jun 27, 2019
826e12b
Add link to feedback issue 1050
mcking65 Jun 27, 2019
299cab5
Typos
zcorpan Jun 27, 2019
af5793c
Merge branch 'master' into zcorpan/labelling-describing
mcking65 Jun 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
298 changes: 298 additions & 0 deletions draft-labelling-describing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
Labeling and Describing

## Introduction

A label, also known as accessible name, is a name or a label used to identify the element for users of assistive technology. For example, a button’s label can be "OK".
carmacleod marked this conversation as resolved.
Show resolved Hide resolved

An accessible description complements the label with a description. An accessible description is always optional, and if present it does not need to be as brief as a label.

## Labels

There are two different ways to get the label for an element, depending on the element’s role.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While implicit/explicit depends on the role, I don't think that is enough info to help the user grasp the important concept here.

The important concept is that there are, broadly speaking, two kinds of labels. One kind of label labels the element and completely represents that element; essentially you could say the label is the element from the user's perspective, e.g., image, heading, link, button, checkbox, radio, menuitem, treeitem. Another kind of label labels another thing, e.g., the label is not the element, e.g., textbox, combobox, toolbar, grid, article, region, table.

One kind of label essentially represents the element and the other kind tells the user here is the purpose of all the junk in here, or here is the kind of junk in here. It labels a input, composite widget, or container.

While These two kinds roughly correspond to implicit (content) and explicit (author), this concept isn't explained well enough for the reader to get a sense of the difference between elements where the label overrides or the label augments.

I think it would be worthwhile if we could help users develop an intuitive understanding of these different kinds of labels/roles/elements.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've tried to address this, although possibly the new text is repeating things a bit.

* Implicit label by default
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to say how this relates to "Name from content" in aria spec.


* Explicit label only

### Implicit label by default

For elements with certain roles, the label is taken from the element’s contents by default. In the following example, a link (with default role `link`) gets its label from the element’s contents ("Home").

```
<a href="/">Home</a>
```


The label also can be set explicitly by using the `aria-labelledby` or `aria-label` attributes. If the implicit label (from the element’s contents) is already good, then don’t use the `aria-labelledby` or `aria-label` attributes.

The following roles get the label from the contents by default:

* `button`

* `cell`

* `checkbox`

* `columnheader`

* `gridcell`

* `heading`

* `link`

* `menuitem`

* `menuitemcheckbox`

* `menuitemradio`

* `option`

* `radio`

* `row`

* `rowgroup`

* `rowheader`

* `switch`

* `tab`

* `tooltip`

* `treeitem`

If the element’s contents are not appropriate as a label, but there is an element that can be used as the label, then use the `aria-labelledby` attribute.

In the following example, an element with the "switch" role is labeled by a previous sibling element.

```
<span id="night-mode-label">Night mode</span>
<span role="switch" aria-checked="false" tabindex="0" aria-labelledby="night-mode-label"></span>
```


Because a `span` element is used for the switch control, the HTML `label` element cannot be used to label it, since it only works with HTML elements that are form controls. However, the `switch` role can be used on an `input` element with `type="checkbox”`, and then HTML `label` can be used.
carmacleod marked this conversation as resolved.
Show resolved Hide resolved

```
<label for="night-mode">Night mode</label>
<input type="checkbox" role="switch" id="night-mode">
```


In some cases, the combination of the element’s contents and another element would be appropriate as a label. In such situations, use the `aria-labelledby` and reference both the element itself and the other element.

In the following example, a "read more" link is labeled by the element itself and the article’s heading, resulting in “Read more… 7 ways you can help save the bees”.

```
<h2 id="bees-heading">7 ways you can help save the bees</h2>
<p>Bees are disappearing rapidly.
Here are seven things you can do to help.</p>
<p><a id="bees-read-more aria-labelledby="bees-read-more bees-heading">Read more...</a></p>
```
zcorpan marked this conversation as resolved.
Show resolved Hide resolved


If there is no content that is appropriate to use as the label, then use the `aria-label` attribute to set the label for the element directly.

In the following example, a close button contains an "X" and is given the label “Close” using the `aria-label` attribute.
carmacleod marked this conversation as resolved.
Show resolved Hide resolved

```
<button type="button" aria-label="Close">X</button>
```


### Explicit label only

Some roles do not get the label from the contents of the element; a label can only be set explicitly using the `aria-labelledby` or `aria-label` attributes. An explicit label does not override the contents of such elements.

Examples of such roles are (note that this is not a complete list):

* `alertdialog`

* `application`

* `article`

* `banner`

* `complementary`

* `navigation`

* `radiogroup`

* `search`

* `status`

For example, the `navigation` landmark could be labeled with the purpose of the landmark. In the following snippet, a "breadcrumbs" navigation region is labeled explicitly using the `aria-labelledby` attribute. The HTML `nav` element has the `navigation` role by default.

```
<nav aria-labelledby="breadcrumbs-label">
<span id="breadcrumbs-label">You are here:</span>
<a href="/">Home</a> &gt;
<a href="/books/">Books</a> &gt;
<a>Children's books</a>
</nav>
```


### Accessible name calculation

User agents follow the accessible name calculation algorithm to get the label for an element. This is defined in [https://w3c.github.io/accname/](https://w3c.github.io/accname/) and [https://w3c.github.io/html-aam/](https://w3c.github.io/html-aam/) for HTML.

User agents attempt to formulate labels for elements by walking through a list of potential naming methods and use the first that generates a name. The algorithm is roughly like this:

1. First, the `aria-labelledby` attribute is used if present.

2. If the label is still empty, the `aria-label` attribute is used if present.

3. If the label is still empty, then host-language-specific attributes or elements (e.g., the `alt` attribute on HTML `img`) are used if present.

4. If the label is still empty, then for roles that can take implicit label by default, the element’s contents.

5. Finally, if the label is still empty, then host-langauge-specific tooltip attributes or elements (e.g., the `title` attribute in HTML) are used if present.

Steps 1-2 are explicit label, and steps 3-5 are implicit label. The final step is a fallback mechanism. Generally when labelling an element, use one of the non-fallback mechanisms.

For example, for the HTML `input` element, the `placeholder` attribute is used as a fallback labeling mechanism if nothing else results in a label. For an `input` element, it is better to use a `label` element, since it does not disappear visually when the user focuses the form control.

#### Examples of non-recursive accessible name calculation

For example, an img element with just a src attribute has no label (don’t do this):

```
<img src="photo.jpg">
```


If there is a `title` attribute, then that is used as the label (fallback mechanism; generally avoid doing this):

```
<img src="photo.jpg" title="The Queen, holding a pigeon.">
```


If there is also an `alt` attribute (using `alt` for images is recommended), then that is used as the label, and the `title` attribute is instead used as the accessible description:

```
<img src="photo.jpg" alt="The Queen, holding a pigeon." title="Photo: Rex Features">
```


If there is also an `aria-label` attribute, then that overrides the `alt` attribute:

```
<img src="photo.jpg" aria-label="The Queen, holding a pigeon." title="Photo: Rex Features" alt="Sorry, this image failed to load.">
```


If there is also an `aria-labelledby` attribute, that wins over the other attributes (the `aria-label` attribute ought to be removed if it is not used):

```
<img src="photo.jpg" aria-label="This is ignored." title="Photo: Established Depiction" alt="Sorry, this image failed to load." aria-labelledby="the-queen">
<span id="the-queen">The Queen, holding a pigeon.</span>
```


#### Examples of recursive accessible name calculation

The accessible name calculation algorithm will be invoked recursively when necessary. An `aria-labelledby` reference causes the algorithm to be invoked recursively, and when computing an accessible name from content the algorithm is invoked recursively for each child node.

In this example, the label for the button is computed by recursing into each child node, resulting in "Move to trash".

```
<button>Move to <img src="bin.svg" alt="trash"></button>
```


When following an `aria-labelledby` reference, the algorithm avoids following the same reference twice in order to not end up in infinite loops.

In this example, the label for the button is computed by first following the `aria-labelledby` reference to the parent element, and then computing the label for that element from the child nodes, first visiting the `button` element again but ignoring the `aria-labelledby` reference and instead using the `aria-label` attribute, and then visiting the next child (the text node). The resulting label is "Remove meeting: Daily status report".

```
<div id="meeting-1">
<button aria-labelledby="meeting-1"
aria-label="Remove meeting:">X</button>
Daily status report
</div>
```

It is also possible to reference an element using `aria-labelledby` even if that element is hidden. In the following example, the `span` element could be styled with CSS `display: none` and the `nav` element would still have the label "You are here:".

```
<nav aria-labelledby="breadcrumbs-label">
<span id="breadcrumbs-label">You are here:</span>
<a href="/">Home</a> &gt;
<a href="/books/">Books</a> &gt;
<a>Children's books</a>
</nav>
```

## Descriptions

An element can be given an accessible description using the `aria-describedby` attribute or the `aria-details` attribute.

The `aria-describedby` attribute works similarly to the `aria-labelledby` attribute. For example, a button could be described by a later paragraph.

```
<button aria-describedby="trash-desc">Move to trash</button>
...
<p id="trash-desc">Items in the trash
will be permanently removed after 30 days.</p>
```


This description will be presented to the user as plain text. For example, if the description contains an HTML `img` element, a text equivalent of the image is computed.

```
<button aria-describedby="trash-desc">
Move to <img src="bin.svg" alt="trash">
</button>
...
<p id="trash-desc">Items in <img src="bin.svg" alt="the trash">
will be permanently removed after 30 days.</p>
```


In some cases, a plain text description is insufficient. The `aria-details` attribute can be used in such situations. In this example, a text field for a passenger’s name (when booking a flight) has a description that is a list of three items, and contains a link to an external document with further details.

```
<ul id="full-name-desc">
<li>The passenger's name must match the name in their passport.</li>
<li>The name must consist of only characters in the A-Z range.</li>
<li><a href="faq.html#name">What if the name in the passport contains other characters?</a></li>
</ul>
<fieldset>
<legend>Passenger 1 (adult)</legend>
<p><label>Full name
<input name="full-name" aria-details="full-name-desc">
</label></p>
...
</fieldset>
```


If both `aria-details` and `aria-describedby` are specified on an element, only the `aria-details` attribute is used. This can be useful in order to provide a fallback for user agents that don’t support `aria-details`.

### Accessible description calculation

Like the accessible name calculation (see the earlier section), the accessible description calculation produces a plain text string for an element. This algorithm is not used for the `aria-details` attribute.

The accessible description calculation algorithm is the same algorithm as the accessible name calculation algorithm, but it branches off in some places depending on whether a name or a description is being calculated. In particular, when collecting an accessible description, the algorithm uses `aria-describedby` instead of `aria-labelledby`.

As with `aria-labelledby`, it is possible to reference an element using `aria-describedby` even if that element is hidden.

For example, a text field in a form could have a description that is hidden by default, but can be revealed on request using a disclosure widget. The description could also be referenced from the text field directly with `aria-describedby`. The accessible description for the `input` element is "Your username is the name that you use to log in to this service.".

```
<label for="username">Username</label>
<input id="username" name="username" aria-describedby="username-desc">
<button aria-expanded="false" aria-controls="username-desc" aria-label="Help about username">?</button>
<p id="username-desc" hidden>
Your username is the name that you use to log in to this service.
</p>
```