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: files/en-us/learn_web_development/howto/design_and_accessibility/html_features_for_accessibility/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,7 @@ To aid tabbing, you can supply a [skip link](/en-US/docs/Web/HTML/Reference/Elem
58
58
59
59
## Alt attribute for image
60
60
61
-
Every image should have an [`alt`](/en-US/docs/Web/HTML/Reference/Elements/img#alt) attribute. If the image is purely decoration and adds no meaning to the content or context of the document, the `alt` attribute should be present, but empty. You can optionally also add [`role="presentation"`](/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/presentation_role). All other images should include an `alt` attribute providing [alternative text describing the image](/en-US/docs/Web/API/HTMLImageElement/alt#usage_notes) in a way that is helpful to users who can read the rest of the content but can't see the image. Think about how you would describe the image to someone who can't load your image: that's the information you should include as the value of the `alt` attribute.
61
+
Every image should have an [`alt`](/en-US/docs/Web/HTML/Reference/Elements/img#alt) attribute. If the image is purely decoration and adds no meaning to the content or context of the document, the `alt` attribute should be present, but empty. You can optionally also add [`role="presentation"`](/en-US/docs/Web/Accessibility/ARIA/Reference/Roles/presentation_role). All other images should include an `alt` attribute providing [alternative text describing the image](/en-US/docs/Web/HTML/Reference/Elements/img#accessibility) in a way that is helpful to users who can read the rest of the content but can't see the image. Think about how you would describe the image to someone who can't load your image: that's the information you should include as the value of the `alt` attribute.
property of the {{domxref("HTMLImageElement")}} interface is a string which indicates
15
-
how to position the image relative to its container.
13
+
The _deprecated_**`align`** property of the {{domxref("HTMLImageElement")}} interface is a string which indicates how to position the image relative to its container. It reflects the `<img>` element's [`align`](/en-US/docs/Web/HTML/Reference/Elements/img#align) content attribute.
16
14
17
-
You should instead use the
18
-
CSS property {{cssxref("vertical-align")}}, which does in fact also work on images
19
-
despite its name. You can also use the {{cssxref("float")}} property to float the image
20
-
to the left or right margin.
21
-
22
-
The `align` property reflects the HTML [`align`](/en-US/docs/Web/HTML/Reference/Elements/img#align)
23
-
content attribute.
15
+
You should instead use the CSS property {{cssxref("vertical-align")}}, which does in fact also work on images despite its name. You can also use the {{cssxref("float")}} property to float the image to the left or right margin.
24
16
25
17
## Value
26
18
27
-
A string specifying one of the following strings which set the
28
-
alignment mode for the image.
29
-
30
-
### Baseline alignment
31
-
32
-
These three values specify the alignment of the element relative to the text baseline.
33
-
These should be replaced by using the CSS {{cssxref("vertical-align")}} property.
19
+
A string. For the permitted values, see the HTML [`<img>`](/en-US/docs/Web/HTML/Reference/Elements/img#align) reference.
34
20
35
-
-`bottom`
36
-
- : The bottom edge of the image is to be aligned vertically with the current text
37
-
baseline. **Default value.**
38
-
-`middle`
39
-
- : The center of the object should be aligned vertically with the current baseline.
40
-
-`top`
41
-
- : The top edge of the object should be aligned vertically with the current baseline.
21
+
## Examples
42
22
43
-
It may be worth noting that {{cssxref("vertical-align")}} offers several additional
44
-
options for its value; you may wish to consider these when changing your code to use it.
23
+
### Setting the align attribute
45
24
46
-
### Floating images horizontally
25
+
```js
26
+
constimg=newImage();
27
+
img.src="example.png";
28
+
img.align="top";
29
+
```
47
30
48
-
The `left` and `right` properties don't affect the
49
-
baseline-relative alignment. Instead, they cause the image to "float" to the left or
50
-
right margin, allowing the following text to flow around the image. You should instead
51
-
use the CSS {{cssxref("float")}} property, specifying as the value
52
-
either `left` or `right`.
31
+
Instead of doing this, consider:
53
32
54
-
-`left`
55
-
- : Floats the image over to place the left edge flush against the current margin. Any
56
-
text that follows will flow against the image's right edge.
57
-
-`right`
58
-
- : Floats the image to place its right edge flush against the right margin. Subsequent
The {{domxref("HTMLImageElement")}} property **`alt`**provides fallback (alternate) text to display when the image specified by the {{HTMLElement("img")}} element is not loaded.
11
+
The **`alt`** property of the {{domxref("HTMLImageElement")}} interface provides fallback (alternate) text to display when the image specified by the {{HTMLElement("img")}} element is not displayed, whether because of an error, because the user has disabled the loading of images, or because the image hasn't finished loading yet. It reflects the `<img>` element's [`alt`](/en-US/docs/Web/HTML/Reference/Elements/img#alt) content attribute.
12
12
13
-
This may be the case because of an error, because the user has disabled the loading of images, or because the image hasn't finished loading yet.
14
-
15
-
Perhaps the most important reason to use the `alt` property is to support [accessibility](/en-US/docs/Web/Accessibility), as the `alt` text may be used by screen readers and other assistive technologies to help people with a disability make full use of your content.
16
-
It will be read aloud or sent to a braille output device, for example, to support blind or visually impaired users.
17
-
18
-
> **Think of it like this:** When choosing `alt` strings for your images, imagine what you would say when reading the page to someone over the phone without mentioning that there's an image on the page.
19
-
20
-
The alternate text is displayed in the space the image would occupy and should be able to take the place of the image _without altering the meaning of the page_.
13
+
There are important accessibility implications of providing appropriate alt text, and the requirements may differ based on the purpose of the image. See the HTML [`<img>`](/en-US/docs/Web/HTML/Reference/Elements/img#authoring_meaningful_alternate_descriptions) reference for more information.
21
14
22
15
## Value
23
16
24
-
A string which contains the alternate text to display when the image is not loaded or for use by assistive devices.
25
-
26
-
The `alt` attribute is officially mandatory; it's meant to always be specified.
27
-
If the image doesn't require a fallback (such as for an image which is decorative or an advisory icon of minimal importance), you may specify an empty string (`""`).
28
-
For compatibility reasons, browsers generally will accept an image without an `alt` attribute, but you should try to get into the habit of using it.
29
-
30
-
## Usage notes
31
-
32
-
The fundamental guideline for the `alt` attribute is that every image's alternate text should be able to replace the image _without altering the meaning of the page_. You should never use `alt` for text that could be construed as a caption or title.
33
-
There are separate attributes and elements designed for those purposes.
17
+
A string.
34
18
35
19
## Examples
36
20
37
-
Beyond that, there are additional guidelines for using `alt` appropriately which vary depending on what the image is being used for.
38
-
These are shown in the examples below.
39
-
40
-
### Decorative images
41
-
42
-
Images with no semantic meaning—such as those which are solely decorative—or of limited informational value, should have their `alt` attributes set to the empty string (`""`).
43
-
This is shown in the example below.
44
-
45
-
#### HTML
46
-
47
-
In the HTML for this example, shown below, the {{HTMLElement("img")}} element includes the `alt` property, which will prevent the image from having any alternate text, since it's a decorative detail.
48
-
49
-
```html
50
-
<divclass="container">
51
-
<divclass="left-margin">
52
-
<imgsrc="margin-flourish.svg"alt="" />
53
-
</div>
54
-
<divclass="contents">
55
-
<p>
56
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque quis orci
57
-
ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ac
58
-
neque libero. Vivamus consectetur rhoncus elit eget porta. Etiam pulvinar
59
-
ex id sapien laoreet, quis aliquet odio lobortis. Nam ac mauris at risus
60
-
laoreet cursus vitae et sapien. Etiam molestie auctor eros, ac porta risus
61
-
scelerisque sit amet. Ut nunc neque, porta eu auctor at, tempor et arcu.
62
-
</p>
63
-
</div>
64
-
</div>
65
-
```
66
-
67
-
#### CSS
68
-
69
-
The CSS for this example sets up the styles for the layout as shown in the result below.
When using an image as a button (by using it as the only visible child of an {{HTMLElement("a")}} element representing a hyperlink), the `alt` attribute must be used to convey the purpose of the button.
126
-
In other words, it should be the same text you would use in a textual button to serve the same purpose.
127
-
128
-
For example, in the snippet of HTML below, a toolbar which uses icon images as link labels provides `alt` attributes for each giving a textual label to use instead of the icon when the icons cannot be or are intentionally not used.
129
-
130
-
```html
131
-
<liclass="toolbar"role="toolbar">
132
-
<ahref="songs.html"role="button">
133
-
<imgsrc="songicon.svg"alt="Songs" />
134
-
</a>
135
-
<ahref="albums.html"role="button">
136
-
<imgsrc="albumicon.svg"alt="Albums"
137
-
/></a>
138
-
<ahref="artists.html"role="button">
139
-
<imgsrc="artisticon.svg"alt="Artists" />
140
-
</a>
141
-
<ahref="playlists.html"role="button">
142
-
<imgsrc="playlisticon.svg"alt="Playlists" />
143
-
</a>
144
-
</li>
145
-
```
146
-
147
-
### Images containing diagrams or maps
148
-
149
-
When an image contains information presented as a diagram, chart, graph, or map, the `alt` text should provide the same information, at least in summary form.
150
-
This is true whether the /me image is in a bitmapped format such as [PNG](/en-US/docs/Web/Media/Guides/Formats/Image_types#png_portable_network_graphics) or [JPEG](/en-US/docs/Web/Media/Guides/Formats/Image_types#jpeg_joint_photographic_experts_group_image) or in a vector format like [SVG](/en-US/docs/Web/Media/Guides/Formats/Image_types#svg_scalable_vector_graphics).
151
-
152
-
- For a map, the `alt` text could be directions to the place indicated by the map, similarly to how you would explain it verbally.
153
-
- For a chart, the text could describe the items in the chart and their values.
154
-
- For a diagram, the text could be an explanation of the concept presented by the diagram.
155
-
156
-
Keep in mind that any text included in diagrams and charts presented in {{Glossary("SVG")}} format may be read by screen readers.
157
-
This may impact the decisions you make when writing the `alt` text for the diagram.
158
-
159
-
### Icons or logos
160
-
161
-
Logos (such as corporate or brand logos) and informational icons should use the corresponding text in their `alt` strings.
162
-
That is, if an image is a corporate logo, the `alt` text should be the name of the company.
163
-
If the image is an icon representing a status or other information, the text should be the name of that state.
164
-
165
-
For example, if an image is a badge that's shown on a page to indicate that the content of the page is new and has been updated recently, the corresponding `alt` text might be `"Updated Recently"` or even `"Updated on 27 August 2019"`.
166
-
167
-
In this example, a starburst image with the word "New!" is used to indicate that an article is about something new (and probably supposedly also exciting).
168
-
The `alt` attribute is set to `New Page!` to allow that text to be displayed in place of the image if the image isn't available.
169
-
It is also available to be read by screen readers.
170
-
171
-
#### HTML
172
-
173
-
The HTML below creates a snippet of content from a site using the described icon.
174
-
Note the use of the `alt` attribute on the {{HTMLElement("img")}}, providing a good substitution string to use in case the image doesn't load.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque quis orci
184
-
ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In ac neque
185
-
libero. Vivamus consectetur rhoncus elit eget porta. Etiam pulvinar ex id
186
-
sapien laoreet, quis aliquet odio lobortis. Nam ac mauris at risus laoreet
187
-
cursus vitae et sapien. Etiam molestie auctor eros, ac porta risus
188
-
scelerisque sit amet. Ut nunc neque, porta eu auctor at, tempor et arcu.
189
-
</p>
190
-
</div>
191
-
```
192
-
193
-
#### CSS
194
-
195
-
The main feature of the CSS here is the use of {{cssxref("clip-path")}} and {{cssxref("shape-outside")}} to wrap the text around the icon in an appealing way.
196
-
197
-
```css
198
-
.container {
199
-
max-width: 500px;
200
-
}
201
-
202
-
.page-info-badge {
203
-
width: 9em;
204
-
padding-right: 1em;
205
-
float: left;
206
-
clip-path: polygon(
207
-
100%0,
208
-
100%50%,
209
-
90%70%,
210
-
80%80%,
211
-
70%90%,
212
-
50%100%,
213
-
0100%,
214
-
00
215
-
);
216
-
shape-outside: polygon(
217
-
100%0,
218
-
100%50%,
219
-
90%70%,
220
-
80%80%,
221
-
70%90%,
222
-
50%100%,
223
-
0100%,
224
-
00
225
-
);
226
-
}
227
-
228
-
.contents {
229
-
margin-top: 1em;
230
-
font:
231
-
16pxArial,
232
-
Helvetica,
233
-
Verdana,
234
-
sans-serif;
235
-
}
23
+
```js
24
+
constimg=newImage();
25
+
img.src="example.png";
26
+
img.alt="An example picture";
236
27
```
237
28
238
-
#### Result
239
-
240
-
{{EmbedLiveSample("Icons_or_logos", 640,400)}}
241
-
242
-
### Other images
243
-
244
-
Images showing objects or scenes should have `alt` text describing what's seen in the image.
245
-
A photo of a yellow teapot might literally have its `alt` attribute set to `"A yellow teapot"`.
0 commit comments