Accordion
- Buttons are used as the accordions so that they are tab-able by keyboard users and accessible to screen readers.
- Each accordion button and realted content has a unique
id
associated with itsaria-controls
. - Each button has an
aria-expanded
attribute on it that is toggled between true and false. Ifaria-expanded='true'
, the content associated with it is shown, and ifaria-expanded='false'
the content is hidden.
WCAG 2.1 Guidelines
2.4.3 Focus Order - If a Web page can be navigated sequentially and the navigation sequences affect meaning or operation, focusable components receive focus in an order that preserves meaning and operability. (Level A)
2.4.5 Multiple Ways - More than one way is available to locate a Web page within a set of Web pages except where the Web Page is the result of, or a step in, a process. (Level AA)
2.4.7 Focus Visible - Any keyboard operable user interface has a mode of operation where the keyboard focus indicator is visible. (Level AA)
2.4.8 Location - Information about the user's location within a set of Web pages is available. (Level AAA)
4.1.2 Name, Role, Value - For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies. (Level A)
A candle
Neither, they both weigh one pound.
Footprints.
<section class="accordion-section">
<div class="accordion" role="presentation">
<div class="js-accordion__panel">
<h3 class="accordion__heading">
<button class="accordion__trigger" aria-controls="accordion__content_1" aria-expanded="false" tabindex="0" id="accordion__title_1" aria-selected="false">I’m tall when I’m young and I’m short when I’m old. What am I?
</button>
</h3>
<div class="accordion__content" id="accordion__content_1" role="region" aria-hidden="true" aria-labelledby="accordion__title_1">
<p>A candle</p>
</div>
</div>
<div class="js-accordion__panel">
<h3 class="accordion__heading">
<button class="accordion__trigger" aria-controls="accordion__content_2" aria-expanded="false" tabindex="0" id="accordion__title_2" aria-selected="false">Which weighs more, a pound of feathers or a pound of bricks?
</button>
</h3>
<div class="accordion__content" id="accordion__content_2" role="region" aria-hidden="true" aria-labelledby="accordion__title_2">
<p>Neither, they both weigh one pound.</p>
</div>
</div>
<div class="js-accordion__panel">
<h3 class="accordion__heading">
<button class="accordion__trigger" aria-controls="accordion__content_3" aria-expanded="false" tabindex="0" id="accordion__title_3" aria-selected="false">The more you take, the more you leave behind. What are they?
</button>
</h3>
<div class="accordion__content" id="accordion__content_3" role="region" aria-hidden="true" aria-labelledby="accordion__title_3">
<p>Footprints.</p>
</div>
</div>
</div>
</section>
Copied!
Breadcrumbs
- Place the breadcrumb in a
<nav>
element when you can. - If you do not use a
<nav>
element, you need to addrole="navigation"
to the markup. Note: this role is implied when you use the<nav>
element so it is a bit redundant to use both at the same time. - The markup includes an
aria-label="breadcrumbs"
to describe the type of navigation. - Add
aria-current="page"
to the link that points to the current page. This will tell assistive technology (AT) devices that the focused link is pointing to the current page.
Resources
WCAG 2.1 Guidelines
2.4.8 Location - Information about the user's location within a set of Web pages is available. (Level AAA)
<section class="breadcrumbs-section">
<h3>Option #1: List styling with nav element</h3>
<nav aria-label="breadcrumbs">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#" aria-current="page">Home</a></li>
</ol>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item"><a href="#" aria-current="page">Parent</a></li>
</ol>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="#">Home</a></li>
<li class="breadcrumb-item"><a href="#">Parent</a></li>
<li class="breadcrumb-item"><a href="#" aria-current="page">Child</a></li>
</ol>
</nav>
<div class="break"></div>
<h3>Option #2: Link styling with no nav element</h3>
<div role="navigation" aria-label="breadcrumbs" class="breadcrumb">
<a class="breadcrumb-item" href="#">Home</a>
<a class="breadcrumb-item" href="#">Parent</a>
<a class="breadcrumb-item" href="#" aria-current="page">Child</a>
</div>
</section>
Copied!
Basic Navigation
- All navigation elements should have a
<nav>
tag. - If you have to use a more generic element such as a
<div>
, addrole="navigation"
to every navbar to explicitly identify it as a landmark region for users of assistive technologies. - Menus should be labeled according to their individual function. Use can use
class="visuallyhidden">
,aria-label=""
, oraria-labelledby=""
to easily add context to the different menus on your site.
WCAG 2.1 Guidelines
2.4.3 Focus Order - If a Web page can be navigated sequentially and the navigation sequences affect meaning or operation, focusable components receive focus in an order that preserves meaning and operability. (Level A)
2.4.5 Multiple Ways - More than one way is available to locate a Web page within a set of Web pages except where the Web Page is the result of, or a step in, a process. (Level AA)
2.4.7 Focus Visible - Any keyboard operable user interface has a mode of operation where the keyboard focus indicator is visible. (Level AA)
2.4.8 Location - Information about the user's location within a set of Web pages is available. (Level AAA)
4.1.2 Name, Role, Value - For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies. (Level A)
Option #1: List styling with visuallyhidden class
Option #2: List styling with ARIA label
Option #3: No list styling with ARIA labelledby
<section class="navbar-section">
<h3>Option #1: List styling with visuallyhidden class</h3>
<nav class="navbar">
<h2 class="visuallyhidden">Main Menu</h2>
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">More Information</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Us</a>
</li>
</ul>
</nav>
<div class="break"></div>
<h3>Option #2: List styling with ARIA label</h3>
<nav class="navbar" aria-label="Main Menu">
<h2 class="visuallyhidden">Main Menu</h2>
<ul class="nav navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About Us</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">More Information</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact Us</a>
</li>
</ul>
</nav>
<div class="break"></div>
<h3>Option #3: No list styling with ARIA labelledby</h3>
<nav class="navbar" aria-labelledby="mainmenulabel">
<h2 class="visuallyhidden" id="mainmenulabel">Main Menu</h2>
<div class="nav navbar-nav menu3">
<a class="nav-item nav-link2" href="#">Home</a>
<a class="nav-item nav-link2" href="#">About Us</a>
<a class="nav-item nav-link2" href="#">More Information</a>
<a class="nav-item nav-link2" href="#">Contact Us</a>
</div>
</nav>
</section>
Copied!
Footer Navigation
- All navigation elements should have a
<nav>
tag. - If you have to use a more generic element such as a
<div>
, addrole="navigation"
to every navbar to explicitly identify it as a landmark region for users of assistive technologies. - Menus should be labeled according to their individual function. Use can use
class="visuallyhidden">
,aria-label=""
, oraria-labelledby=""
to easily add context to the different menus on your site.
WCAG 2.1 Guidelines
2.4.3 Focus Order - If a Web page can be navigated sequentially and the navigation sequences affect meaning or operation, focusable components receive focus in an order that preserves meaning and operability. (Level A)
2.4.5 Multiple Ways - More than one way is available to locate a Web page within a set of Web pages except where the Web Page is the result of, or a step in, a process. (Level AA)
2.4.7 Focus Visible - Any keyboard operable user interface has a mode of operation where the keyboard focus indicator is visible. (Level AA)
2.4.8 Location - Information about the user's location within a set of Web pages is available. (Level AAA)
4.1.2 Name, Role, Value - For all user interface components (including but not limited to: form elements, links and components generated by scripts), the name and role can be programmatically determined; states, properties, and values that can be set by the user can be programmatically set; and notification of changes to these items is available to user agents, including assistive technologies. (Level A)
<footer class="footer">
<div>
<div class="l-center">
<div class="footer__left">
<div class="footer__contact">
<div aria-labelledby="footer-contact" class="footer__header">
<h2 class="footer__title" id="footer-contact">Contact</h2>
<div class="footer__content">
<ul>
<li class="icon--phone">+1 (800) 555-5555</li>
<li><a class="icon--email" href="#">info@company.com</a></li>
<li class="icon--address">Street Address <br>City, Zip Code</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="footer__right">
<nav aria-labelledby="footer-resources" class="footer__header">
<h2 class="footer__title" id="footer-resources">Resources</h2>
<ul>
<li><a href="#">Press</a></li>
<li><a href="#">FAQ</a></li>
<li><a href="#">Jobs</a></li>
<li><a href="#">Charity</a></li>
</ul>
<ul>
<li><a href="#">Privacy</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
</div>
</div>
</div>
<div class="l-center">
<div class="footer__flex">
<div class="footer__left-social">
<div class="footer__social">
<nav aria-labelledby="footer-social-links" class="navigation navigation--social">
<h2 class="visuallyhidden" id="footer-social-links">Social Media Links</h2>
<ul class="navigation__menu menu" id="footer-social-links">
<li class="navigation__link navigation__link--icon first"><a href="#" class="icon icon--facebook">Facebook</a></li>
<li class="navigation__link navigation__link--icon"><a href="#" class="icon icon--instagram">Instagram</a></li>
<li class="navigation__link navigation__link--icon"><a href="#" class="icon icon--twitter">Twitter</a></li>
<li class="navigation__link navigation__link--icon last"><a href="#" class="icon icon--youtube">YouTube</a></li>
</ul>
</nav>
</div>
</div>
<div class="footer__right-search">
<div role="search">
<input type="search" name="search" aria-label="Search">
<button type="submit">Search</button>
</div>
</div>
</div>
</div>
<div class="footer__credits">
<div class="l-center">
<p class="footer__copyright">All rights reserved A11Y Style Guide ©2017</p>
</div>
</div>
</footer>
Copied!
Mobile Navigation
- Use the
<button>
element for your mobile navigation icon. - If you use an icon that is purely decoration, declare
alt=""
, as no additional information is needed. If the icon you are using is important to the functionality, then supply additionalalt="_descriptive text goes here_"
information. - It is helpful to all users when you add descriptive text when displaying a mobile icon to give more context to the button's purpose.
- Place mobile open/close buttons within the
<nav>
element and use them to toggle state of another child wrapper of the nav. This will ensure that the navigation landmark is still discoverable by screen readers, even if it is in a closed/hidden state.
Resources
WCAG 2.1 Guidelines
1.1.1 Non-text Content - All non-text content that is presented to the user has a text alternative that serves the equivalent purpose (some exceptions). (Level A)
Note: If non-text content is pure decoration, is used only for visual formatting, or is not presented to users, then it does not need text alternatives.
<section class="navbar-mobile-icon">
<button class="menu-toggle" id="menu-toggle-ex1" aria-expanded="false" aria-controls="nav-menu-ex-1"><span class="screen-reader-text">Menu</span>
<svg class="icon icon-menu-toggle" aria-hidden="true" version="1.1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100">
<g class="svg-menu-toggle">
<path class="line line-1" d="M5 13h90v14H5z"/>
<path class="line line-2" d="M5 43h90v14H5z"/>
<path class="line line-3" d="M5 73h90v14H5z"/>
</g>
</svg>
</button>
<button class="menu-toggle" id="menu-toggle-ex2" aria-expanded="false" aria-controls="nav-menu-ex-2"><span>Click for Menu</span>
<svg class="icon icon-menu-toggle" aria-hidden="true" version="1.1" xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100">
<g class="svg-menu-toggle">
<path class="line line-1" d="M5 13h90v14H5z"/>
<path class="line line-2" d="M5 43h90v14H5z"/>
<path class="line line-3" d="M5 73h90v14H5z"/>
</g>
</svg>
</button>
</section>
Copied!
Pagination
- Place the pager in a
<nav>
element when you can. - If you do not use a
<nav>
element, you need to addrole="navigation"
to the markup. Note: this role is implied when you use the<nav>
element so it is a bit redundant to use both at the same time. - The markup includes an
aria-label="pagination"
to describe the type of navigation. - Add
aria-current="page"
to the link that points to the current page. This will tell AT that the focused link is pointing to the current page. - Add
aria-disabled="true"
to the link when the link is disabled.
Resources
WCAG 2.1 Guidelines
2.4.8 Location - Information about the user's location within a set of Web pages is available. (Level AAA)
Default State
Disabled Previous/Next Group Link State
Disabled Previous/Next Page Link State
<section class="pagination-section">
<h3>Default State</h3>
<nav aria-label="pagination">
<ul class="pagination">
<li class="pagination__item pagination__item--previous-group">
<a class="pagination__link" href="#">
<span class="visuallyhidden">
Previous
<span>set of pages</span>
</span>
</a>
</li>
<li class="pagination__item pagination__item--previous-page">
<a class="pagination__link" href="#">
<span class="visuallyhidden">
Previous
<span>page</span>
</span>
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>1
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>2
</a>
</li>
<li class="pagination__item pagination__item--is-active">
<a class="pagination__link" href="#" aria-current="page"><span class="visuallyhidden">page</span>3</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>4
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>5
</a>
</li>
<li class="pagination__item pagination__item--next-page">
<a class="pagination__link" href="#">
<span class="visuallyhidden">
Next
<span>page</span>
</span>
</a>
</li>
<li class="pagination__item pagination__item--next-group">
<a class="pagination__link" href="#">
<span class="visuallyhidden">
Next
<span>set of pages</span>
</span>
</a>
</li>
</ul>
</nav>
<div class="break"></div>
<h3>Disabled Previous/Next Group Link State</h3>
<nav aria-label="pagination">
<ul class="pagination">
<li class="pagination__item pagination__item--previous-group">
<a class="pagination__link pagination__link--is-disabled" href="#" aria-disabled="true">
<span class="visuallyhidden">
Previous
<span>set of pages</span>
</span>
</a>
</li>
<li class="pagination__item pagination__item--previous-page">
<a class="pagination__link" href="#">
<span class="visuallyhidden">
Previous
<span>page</span>
</span>
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>1
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>2
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#"><span class="visuallyhidden">page</span>3</a>
</li>
<li class="pagination__item pagination__item--is-active">
<a class="pagination__link" href="#" aria-current="page">
<span class="visuallyhidden">page </span>4
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>5
</a>
</li>
<li class="pagination__item pagination__item--next-page">
<a class="pagination__link" href="#">
<span class="visuallyhidden">
Next
<span>page</span>
</span>
</a>
</li>
<li class="pagination__item pagination__item--next-group">
<a class="pagination__link pagination__link--is-disabled" href="#" aria-disabled="true">
<span class="visuallyhidden">
Next
<span>set of pages</span>
</span>
</a>
</li>
</ul>
</nav>
<div class="break"></div>
<h3>Disabled Previous/Next Page Link State</h3>
<nav aria-label="pagination">
<ul class="pagination">
<li class="pagination__item pagination__item--previous-page">
<a class="pagination__link pagination__link--is-disabled" href="#" aria-disabled="true">
<span class="visuallyhidden">
Previous
<span>page</span>
</span>
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>1
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>2
</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#"><span class="visuallyhidden">page</span>3</a>
</li>
<li class="pagination__item">
<a class="pagination__link" href="#">
<span class="visuallyhidden">page </span>4
</a>
</li>
<li class="pagination__item pagination__item--is-active">
<a class="pagination__link" href="#" aria-current="page">
<span class="visuallyhidden">page </span>5
</a>
</li>
<li class="pagination__item pagination__item--next-page">
<a class="pagination__link pagination__link--is-disabled" href="#" aria-disabled="true">
<span class="visuallyhidden">
Next
<span>page</span>
</span>
</a>
</li>
</ul>
</nav>
</section>
Copied!