@@ -5,35 +5,58 @@ <h2>Why is this an issue?</h2>
5
5
< ul >
6
6
< li > The image can no longer be found </ li >
7
7
< li > Visually impaired users using a screen reader software </ li >
8
- < li > Images loading is disabled, to reduce data consumption on mobile phones </ li >
8
+ < li > Image loading is disabled, to reduce data consumption on mobile phones </ li >
9
9
</ ul >
10
- < p > It is also very important to not set an < code > alt</ code > attribute to a non-informative value. For example < code > <img ... alt="logo"></ code >
10
+ < p > It is also very important not to set an < code > alt</ code > attribute to a non-informative value. For example, < code > <img ... alt="logo"></ code >
11
11
is useless as it doesn’t give any information to the user. In this case, as for any other decorative image, it is better to use a CSS background image
12
- instead of an < code > <img></ code > tag. If using CSS background-image is not possible, an empty < code > alt=""</ code > is tolerated. See Exceptions
13
- bellow .</ p >
14
- < p > This rule raises an issue when</ p >
12
+ instead of an < code > <img></ code > tag. If using CSS < code > background-image</ code > is not possible, an empty < code > alt=""</ code > is tolerated. See
13
+ Exceptions below .</ p >
14
+ < p > This rule raises an issue when: </ p >
15
15
< ul >
16
- < li > an < code > <input type="image"></ code > tag or an < code > <area></ code > tag have no < code > alt</ code > attribute or their
17
- < code > alt </ code > attribute has an empty string value. </ li >
18
- < li > an < code > <img></ code > tag has no < code > alt</ code > attribute. </ li >
16
+ < li > An < code > <input type="image"></ code > or < code > <area></ code > element has no < code > alt</ code > attribute or it holds an empty string
17
+ value. </ li >
18
+ < li > An < code > <img></ code > element has no < code > alt</ code > attribute. </ li >
19
19
</ ul >
20
- < h3 > Noncompliant code example</ h3 >
20
+ < h3 > Exceptions</ h3 >
21
+ < p > < code > <img></ code > elements with an empty string < code > alt=""</ code > attribute won’t raise any issue. However, this way should be used
22
+ in two cases only:</ p >
23
+ < p > When the image is decorative and it is not possible to use a CSS background image. For example, when the decorative < code > <img></ code > is
24
+ generated via javascript with a source image coming from a database, it is better to use an < code > <img alt=""></ code > tag rather than generate
25
+ CSS code.</ p >
21
26
< pre >
22
- <img src="foo.png" /> <!-- Noncompliant -->
23
- <input type="image" src="bar.png" /> <!-- Noncompliant -->
24
- <input type="image" src="bar.png" alt="" /> <!-- Noncompliant -->
27
+ <li *ngFor="let image of images">
28
+ <img [src]="image" alt="">
29
+ </li>
30
+ </ pre >
31
+ < p > When the image is not decorative but its < code > alt</ code > text would repeat a nearby text. For example, images contained in links should not
32
+ duplicate the link’s text in their < code > alt</ code > attribute, as it would make the screen reader repeat the text twice.</ p >
33
+ < pre >
34
+ <a href="flowers.html">
35
+ <img src="tulip.gif" alt="" />
36
+ A blooming tulip
37
+ </a>
38
+ </ pre >
39
+ < p > In all other cases you should use CSS background images.</ p >
40
+ < h2 > How to fix it</ h2 >
41
+ < p > Add an alternative text to the HTML element.</ p >
42
+ < h3 > Code examples</ h3 >
43
+ < h4 > Noncompliant code example</ h4 >
44
+ < pre data-diff-id ="1 " data-diff-type ="noncompliant ">
45
+ <img src="foo.png" /> <!-- missing `alt` attribute -->
46
+ <input type="image" src="bar.png" /> <!-- missing `alt` attribute -->
47
+ <input type="image" src="bar.png" alt="" /> <!-- empty `alt` attribute on <input> -->
25
48
26
49
<img src="house.gif" usemap="#map1"
27
50
alt="rooms of the house." />
28
51
<map id="map1" name="map1">
29
52
<area shape="rect" coords="0,0,42,42"
30
- href="bedroom.html"/> <!-- Noncompliant -->
53
+ href="bedroom.html"/> <!-- missing `alt` attribute -->
31
54
<area shape="rect" coords="0,0,21,21"
32
- href="lounge.html" alt=""/> <!-- Noncompliant -->
55
+ href="lounge.html" alt=""/> <!-- empty `alt` attribute on <area> -->
33
56
</map>
34
57
</ pre >
35
- < h3 > Compliant solution</ h3 >
36
- < pre >
58
+ < h4 > Compliant solution</ h4 >
59
+ < pre data-diff-id =" 1 " data-diff-type =" compliant " >
37
60
<img src="foo.png" alt="Some textual description of foo.png" />
38
61
<input type="image" src="bar.png" alt="Textual description of bar.png" />
39
62
@@ -46,38 +69,18 @@ <h3>Compliant solution</h3>
46
69
href="lounge.html" alt="Lounge"/>
47
70
</map>
48
71
</ pre >
49
- < h3 > Exceptions</ h3 >
50
- < p > < code > <img></ code > tags with empty string < code > alt=""</ code > attributes won’t raise any issue. However this technic should be used in
51
- two cases only:</ p >
52
- < p > When the image is decorative and it is not possible to use a CSS background image. For example, when the decorative < code > <img></ code > is
53
- generated via javascript with a source image coming from a database, it is better to use an < code > <img alt=""></ code > tag rather than generate
54
- CSS code.</ p >
55
- < pre >
56
- <li *ngFor="let image of images">
57
- <img [src]="image" alt="">
58
- </li>
59
- </ pre >
60
- < p > When the image is not decorative but it’s < code > alt</ code > text would repeat a nearby text. For example, images contained in links should not
61
- duplicate the link’s text in their < code > alt</ code > attribute, as it would make the screen reader repeat the text twice.</ p >
62
- < pre >
63
- <a href="flowers.html">
64
- <img src="tulip.gif" alt="" />
65
- A blooming tulip
66
- </a>
67
- </ pre >
68
- < p > In all other cases you should use CSS background images.</ p >
69
- < p > See < a href ="https://www.w3.org/WAI/tutorials/images/decision-tree/ "> W3C WAI Web Accessibility Tutorials</ a > for more
70
- information.</ p >
71
72
< h2 > Resources</ h2 >
73
+ < h3 > Documentation</ h3 >
72
74
< ul >
73
- < li > < a href ="https://www.w3.org/TR/WCAG20-TECHS/H24.html "> WCAG2, H24</ a > - Providing text alternatives for the area elements of image maps </ li >
74
- < li > < a href ="https://www.w3.org/TR/WCAG20-TECHS/H36.html "> WCAG2, H36</ a > - Using alt attributes on images used as submit buttons </ li >
75
- < li > < a href ="https://www.w3.org/TR/WCAG20-TECHS/H37.html "> WCAG2, H37</ a > - Using alt attributes on img elements </ li >
76
- < li > < a href ="https://www.w3.org/TR/WCAG20-TECHS/H67.html "> WCAG2, H67</ a > - Using null alt text and no title attribute on img elements for images
77
- that AT should ignore </ li >
78
- < li > < a href ="https://www.w3.org/TR/WCAG20-TECHS/H2.html "> WCAG2, H2</ a > - Combining adjacent image and text links for the same resource </ li >
79
- < li > < a href ="https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-text-equiv-all "> WCAG2, 1.1.1</ a > - Non-text Content </ li >
80
- < li > < a href ="https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-navigation-mechanisms-refs "> WCAG2, 2.4.4</ a > - Link Purpose (In Context) </ li >
81
- < li > < a href ="https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-navigation-mechanisms-link "> WCAG2, 2.4.9</ a > - Link Purpose (Link Only) </ li >
75
+ < li > W3C - < a href ="https://www.w3.org/WAI/tutorials/images/decision-tree/ "> W3C WAI Web Accessibility Tutorials</ a > </ li >
76
+ < li > W3C - < a href ="https://www.w3.org/TR/WCAG20-TECHS/H24.html "> Providing text alternatives for the area elements of image maps</ a > </ li >
77
+ < li > W3C - < a href ="https://www.w3.org/TR/WCAG20-TECHS/H36.html "> Using alt attributes on images used as submit buttons</ a > </ li >
78
+ < li > W3C - < a href ="https://www.w3.org/TR/WCAG20-TECHS/H37.html "> Using alt attributes on img elements</ a > </ li >
79
+ < li > W3C - < a href ="https://www.w3.org/TR/WCAG20-TECHS/H67.html "> Using null alt text and no title attribute on img elements for images that AT
80
+ should ignore</ a > </ li >
81
+ < li > W3C - < a href ="https://www.w3.org/TR/WCAG20-TECHS/H2.html "> Combining adjacent image and text links for the same resource</ a > </ li >
82
+ < li > W3C - < a href ="https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-text-equiv-all "> Non-text Content</ a > </ li >
83
+ < li > W3C - < a href ="https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-navigation-mechanisms-refs "> Link Purpose (In Context)</ a > </ li >
84
+ < li > W3C - < a href ="https://www.w3.org/WAI/WCAG21/quickref/?versions=2.0#qr-navigation-mechanisms-link "> Link Purpose (Link Only)</ a > </ li >
82
85
</ ul >
83
86
0 commit comments