Focus – Hidden Elements
Hidden elements are the elements that are not visually available on the page. If the elements are not programmatically hidden – it might cause users to have to go through extra tab stops if it’s an interactive element while navigating using keyboard. Additionally, screen reader users may consider the element to be a part of the page by default.
NOTE:
- New to accessibility or uncertain of requirements, it will be helpful to review all sections below.
- Already familiar with requirements, skip to the “Working Example” section for sample HTML, CSS and JavaScript (when needed), along with a working demo.
- Ensure that any interactive elements hidden visually DO NOT receive focus when using a keyboard to tab through the page.
-
Use
tabindex="-1"
to remove the interactive elements from tab order that are visually hidden. - Elements CAN also be hidden using HTML hidden attribute or CSS display:none property.
- When hidden elements become visible, they SHOULD receive focus and follow appropriate tab order and reading order.
- In some cases, important instructions might be available on the page that are for screen reader users. These instructions SHOULD NOT be hidden using aria-hidden attribute.
For example,
<!-- When the accordion content is visible -->
<div id="content1" class="content" role="region" aria-hidden="false">
<p>
Introducing Pearson+. Reimagined learning, designed for you. Choose
from one eTextbook or over 1,500 eTextbooks and study tools, all in
one place, for one low monthly subscription. A new way to buy books
that fits your budget. Make the most of your study time with offline
access, enhanced search, notes and flashcards – to get
organized, get the work done quicker and get results. Plus, with the
app, put textbooks in your pocket and learn wherever. It's
time to upgrade the textbook and simplify learning, so you can have
time to live too.
</p>
</div>
<!-- When the accordion content is not visible -->
<div id="content2" class="content" role="region" aria-hidden="true" hidden>
<p>
Introducing Pearson+. Reimagined learning, designed for you. Choose
from one eTextbook or over 1,500 eTextbooks and study tools, all in
one place, for one low monthly subscription. A new way to buy books
that fits your budget. Make the most of your study time with offline
access, enhanced search, notes and flashcards - to get organized,
get the work done quicker and get results. Plus, with the app, put
textbooks in your pocket and learn wherever. It's time to upgrade
the textbook and simplify learning, so you can have time to live too.
</p>
</div>
Handling the programmatic show/hide of content correctly benefits majorly the below users.
- People with cognitive disabilities
- People with visual disabilities
- People using speech input
- People with limited dexterity
- People using keyboard only
<div class="accordion-panel">
<h2>
<button class="collapsible" aria-controls="content1" aria-expanded="false" id="section_1">What's Pearson+?
<svg viewBox="0 0 10 10" aria-hidden="true" focusable="false">
<rect class="vert" height="8" width="2" y="1" x="4" />
<rect height="2" width="8" y="4" x="1" />
</svg>
</button>
</h2>
<div id="content1" class="accordion-content" role="region" aria-labelledby="section_1" aria-hidden="true" hidden>
<p>
Introducing Pearson+. Reimagined learning, designed for you.
Choose from one eTextbook or over 1,500 eTextbooks and study
tools, all in one place, for one low monthly subscription. A
new way to buy books that fits your budget. Make the most of
your study time with offline access, enhanced search, notes
and flashcards — to get organized, get the work done quicker
and get results. Plus, with the app, put textbooks in your
pocket and learn wherever. It's time to upgrade the
textbook and simplify learning, so you can have time to
live too.
</p>
</div>
</div>
<div class="accordion-panel">
<h2>
<button class="collapsible" aria-controls="content2" aria-expanded="false" id="section_2">What's an eTextbook?
<svg viewBox="0 0 10 10" aria-hidden="true" focusable="false">
<rect class="vert" height="8" width="2" y="1" x="4" />
<rect height="2" width="8" y="4" x="1" />
</svg>
</button>
</h2>
<div id="content2" class="accordion-content" role="region" aria-labelledby="section_2" aria-hidden="true" hidden>
<p>
eTextbook is an easy-to-use digital textbook available from
Pearson+. Make it your own by adding notes and highlights.
Download the Pearson+ mobile app to learn on the go, even
offline. Listen on the go with our new audiobook feature,
available for most titles.
</p>
</div>
</div>
.collapsible {
color: rgb(0, 0, 0);
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
}
.accordion-content {
padding: .5rem 1rem;
overflow: hidden;
transition: max-height 0.2s ease-out;
}
[aria-expanded="true"] .vert {
display: none;
}
button:focus svg {
outline: 2px solid;
}
[aria-expanded] rect {
fill: currentColor;
}
button svg {
height: 1em;
margin-left: 0.5em;
float: right;
}
h2 {
margin-bottom: 0;
}
:focus {
outline: .10em solid #000000;
}
.accordion-panel {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
background-color: #fefefe;
border-radius: 4px;
transition: box-shadow .125s ease-in-out;
}
.accordion-panel:hover {
box-shadow: 0 0 25px rgba(0, 0, 0, 0.15);
}
.active {
background-color: #007a9c;
color: #fff;
}
let collapsible = document.getElementsByClassName("collapsible");
let i;
for (i = 0; i < collapsible.length; i++) {
let section = collapsible[i];
collapsible[i].addEventListener("click", function() {
let aria=this.classList.toggle("active");
if (aria) {
section.setAttribute("aria-expanded", "true")
} else {
section.setAttribute("aria-expanded", "false")
}
const controlsId = section.getAttribute('aria-controls');
let content = document.getElementById(controlsId);
const isExpanded = section.getAttribute('aria-expanded') === 'true';
if (!isExpanded){
content.setAttribute('hidden', '');
content.setAttribute("aria-hidden", "true")
} else {
content.removeAttribute('hidden');
content.setAttribute("aria-hidden", "false")
}
});
}
Introducing Pearson+. Reimagined learning, designed for you. Choose from one eTextbook or over 1,500 eTextbooks and study tools, all in one place, for one low monthly subscription. A new way to buy books that fits your budget. Make the most of your study time with offline access, enhanced search, notes and flashcards — to get organized, get the work done quicker and get results. Plus, with the app, put textbooks in your pocket and learn wherever. It’s time to upgrade the textbook and simplify learning, so you can have time to live too.
eTextbook is an easy-to-use digital textbook available from Pearson+. Make it your own by adding notes and highlights. Download the Pearson+ mobile app to learn on the go, even offline. Listen on the go with our new audiobook feature, available for most titles.