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: src/en/articles/accessible-hiding/index.njk
+40-19Lines changed: 40 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -3,44 +3,57 @@ title: "Accessible hiding and aria-hidden example"
3
3
abstract: "Elements not visible on the screen but accessible to assistive technology."
4
4
titleBeforeTag: true
5
5
date: "2018-01-12"
6
+
updateDate: "2026-01-16"
6
7
tags:
7
8
- component
8
9
---
9
10
10
11
11
12
<h2>Introduction</h2>
12
-
<p>Sometimes it is necessary to hide elements in a web page. The conventional way is to use <abbrtitle="Cascading Stylesheets">CSS</abbr> (<code>display:none;</code> and <code>visibility:hidden;</code>) or the <abbr>HTML</abbr>5 `hidden` attribute. These properties hide elements not only on the screen, but also for screen reader users. Thus, these elements will not be visible nor vocalized by Assistive technologies (AT).</p>
13
+
<p>Sometimes it is necessary to hide elements in a web page. The conventional way is to use <abbr>CSS</abbr> (<code>display:none;</code> and <code>visibility:hidden;</code>) or the <abbr>HTML</abbr>5 <code>hidden</code> attribute. These properties hide elements not only on the screen, but also for screen reader users. Thus, these elements will not be visible nor vocalized by Assistive technologies (AT).</p>
13
14
<p>In some cases, it may be useful to hide elements on the screen, but make sure they are still vocalised by screen readers. For this, an accessible hiding <abbr>CSS</abbr> class can be used.</p>
14
-
<p>Finally, you may want to display elements on the screen but make sure they are not vocalized. In this case, you can use an <abbrtitle="Accessible Rich Internet Applications">ARIA</abbr> attribute (<code>aria-hidden</code>).</p>
15
+
<p>Finally, you may want to display elements on the screen but make sure they are not vocalized. In this case, you can use <abbr>HTML</abbr>5 <code>inert</code> attribute or an <abbr>ARIA</abbr> attribute (<code>aria-hidden</code>).</p>
15
16
16
17
<h2>Accessible hiding</h2>
17
-
<p>Accessible hiding allows an element to disappear from the screen, while being accessible to screen reader users. Technically, the solution is to add a <abbr>CSS</abbr> class on the element that should not be visible.</p>
18
+
<p>Accessible hiding allows to hide an element from the screen, while keeping it available for assistive technologies, especially screen readers. Technically, the solution is to add a <abbr>CSS</abbr> class on the element that should not be visible.</p>
19
+
18
20
<p>There are several solutions for this type of <abbr>CSS</abbr> class:</p>
19
21
<ul>
20
-
<li>Setting the element’s size to 0.</li>
22
+
<li>Setting the element's size to 0.</li>
21
23
<li>Positioning the element off the screen (<code>left: -1000px; top: -1000px;</code>).</li>
22
24
<li>Using <code>text-indent</code> or <code>clip</code> properties.</li>
23
25
<li>…</li>
24
26
</ul>
25
27
<p>Ideally, it is best to combine all the solutions to make sure it is working properly in all browsers.</p>
26
28
27
29
28
-
<p>If you use a framework, it is very likely it already has a class for that. For example if you use <ahref="http://boosted.orange.com">Boosted</a> or <ahref="http://getbootstrap.com/">Bootstrap</a>, you can use the <code>visually-hidden</code> <abbr>CSS</abbr> class (“screen reader only”) which is defined as follows:</p>
30
+
<p>If you use a framework, it is very likely it already has a class for that. For example if you use <ahref="http://boosted.orange.com">Boosted</a> or <ahref="http://getbootstrap.com/">Bootstrap</a>, you can use the <code>visually-hidden</code> <abbr>CSS</abbr> class (or <code>sr-only</code> for older versions) which is defined as follows:</p>
<p>If you haven’t got an accessible hiding class yet, the easiest way is to copy and paste the code above.</p>
55
+
56
+
<p>If you haven't got an accessible hiding class yet, the easiest way is to copy and paste the code above.</p>
44
57
45
58
<h3>Implementation</h3>
46
59
<p>Accessible hiding class can be used in many cases. For example, to clarify a link label:</p>
@@ -49,35 +62,43 @@ tags:
49
62
<a href="…">Learn more<span <spanclass="important">class="visually-hidden"</span>> about our mobile plans</span></a>
50
63
</code></pre>
51
64
52
-
<strong>Example:</strong>
65
+
<strong>Example:</strong>
53
66
<p><ahref="#">Learn more<spanclass="visually-hidden"> about our mobile plans</span></a></p>
54
67
55
68
<p>We would have obtained the same result using the <code>aria-label</code> attribute on the link:</p>
56
69
<pre><codeclass="html">
57
70
<a href="…" aria-label="Learn more about our mobile plans">Learn more</a>
58
71
</code></pre>
59
-
<p>The accessible hiding class solution still offers an advantage compared to the <code>aria-label</code> solution. If the <abbr>CSS</abbr> is disabled (replaced with a custom <abbr>CSS</abbr> adapted to a certain disability, for example), the hidden accessibly text will be displayed.</p>
72
+
73
+
The accessible hiding class solution still offers several advantages compared to the <code>aria-label</code> solution. If the <abbr>CSS</abbr> is disabled (replaced with a custom <abbr>CSS</abbr> adapted to a certain disability, for example), the hidden accessibly text will be displayed. During automatic page translation, the <code>aria-label</code> will not be translated. Furthermore, since <code>aria-label</code> is not very visible in the code, developers may forget to update or modify it.
60
74
61
75
<h2><code>aria-hidden</code> attribute</h2>
62
76
<p>This attribute will hide an element (or group of elements) to screen readers. It has however no effect on the display.</p>
63
77
64
78
<h3>Implementation</h3>
65
79
<p>To hide an element to screen readers (and child elements), simply add the <code>aria-hidden="true"</code> attribute. Content can still be made accessible to ATs via <code>aria-describedby</code> or <code>aria-labelledby</code>.</p>
66
80
<h4>Warning</h4>
67
-
<p>If you put a focusable element in content (even on a parent node) with `aria-hidden ="true "`, it will be present in keyboard navigation but will be empty for <abbr>AT</abbr>. <em>So, don't do it.</em></p>
81
+
<p>If you put a focusable element in content (even on a parent node) with <code>aria-hidden ="true"</code>, it will be present in keyboard navigation but will be empty for <abbr>AT</abbr>. <em>So, don't do it.</em></p>
68
82
69
83
<strong>Example: </strong>
70
84
<p>The following screenshot shows a video player with a number of buttons (previous channel, next channel, pause…). This player is surrounded by two buttons also providing access to previous and next channels.</p>
71
-
<p>Visually this is not a problem. Although, when listening to the page with a screen reader, one can find it curious to hear an “Animals” button vocalized at the beginning of the page, and a “Hunting and Fishing” button vocalized at the end of page.</p>
85
+
<p>Visually this is not a problem. Although, when listening to the page with a screen reader, one can find it curious to hear an 'Animals' button vocalized at the beginning of the page, and a “Hunting and Fishing” button vocalized at the end of page.</p>
72
86
73
87
<imgsrc="../images/player.png"alt="screenshot showing a video player">
74
88
75
-
<br><br>
76
-
77
89
<p>To avoid disturbing the user unnecessarily, the easiest way is to hide these buttons (for screen readers) with the <code>aria-hidden</code> attribute.</p>
<li><ahref="https://www.stefanjudis.com/blog/the-inert-attribute-is-finally-coming-to-the-web/">The "inert" attribute is finally coming to the web</a></li>
102
+
<li><ahref="https://access42.net/attribut-aria-hidden-true-accessibilite/"lang="fr"href="fr">Comment utiliser l'attribut aria-hidden="true" de manière accessible ? (fr)</a></li>
103
+
<li><ahref="https://adrianroselli.com/2019/11/aria-label-does-not-translate.html">aria-label Does Not Translate</a></li>
0 commit comments