Source: Udacity Accessibility part of the Front end nanodegree
- Definition: A11y means that site content should be available to everyone and functionality is operable to everyone.
- It affects every user of your website, having disabilities, or others with no disabilities but can not access your website due to unresponsive design, colors, etc...
-
WCAG: Web Content Accessibility Guidelines. It is about making your site POUR.
-
POUR: Percievable, Operable, Understandable, and Robust.
-
Web Aim Checklist: a checklist for ensuring that the website meets WCAG guidelines.
- Web Aim
- Implicity focusable elements (automatic tab order + built-in keyboard event handling) ex.:
- input elements.
- buttons.
- No need to focus something if the user can NOT interact with it, or provide some sort of input from the user.
- Focus Management- tab order is the same as DOM order even if the visual order ( by CSS ) is changed.
- Changing the order visually can cause confusion to users depend on keyboard navigation. Web Aim.
- tabindex = "-1"
[.] Not in tab order.
[.] can be programmatically focused by focus()
[.] For Off screen content (appears in response to user event) like modals.
<dialog id="modal" tabindex="-1"></dialog>
- tabindex = "0"
[.] Insert natively Unfocusable element in tab order.
[.] can also be programmatically focused by focus()
[.] And then keyboard events get directed to it.
<div id="dropdown" tabindex="0"></div>
- tabindex > 0
[.] In front of tab order.
[.] If multiple elements the lowest value is the first in tab order.
[.] ANTI - PATTERN
[.] Confuse screen readers and also keyboard users.
[.] Instead change elements DOM order.
To get tabindex value of an element:
element.tabIndex;
Don't add focus to any content user will Not interact with.
This video shows an exception to this rule: https://www.youtube.com/watch?time_continue=155&v=ifW_oy9hajU
- Allows screen reader users and keyboard, or switch devices users to directly navigate towards main content of the page bypassing navigation items and other things before main content.
- Visually hidden until it comes into focus.
<!--html code-->
<a href="#main-content" class="skip-link">Skip to main content</a>
<nav>
.
.
.
</nav>
<main id="main-content" tabindex="-1">
.
.
.
</main>
/*CSS code*/
.skip-link {
position: absolute;
top: -40px;
left: 0;
background: red;
color: white;
padding: 8px;
z-index: 100;
}
.skip-link:focus {
top: 0;
}
👽 Alternate way to skip to main content.
- Like in case of drop down menu, tree view component. The keyboard interaction after getting focused is what we are talking about.
- WAI-Aria guidelines provide guidance in selcting which keyboard interaction is appropriate for such action.
- To implement focus inside of a component.
- For example: Radio group:
-
first radio button: 1. tabindex="0" / 2. checked / 3. focus()
-
when moving to the next element => first element: 1. tabindex="-1" / 2. remove checked / 3. unfocus :: next element: 1. tabindex="0" / 2. checked / 3. focus()
-
If it is the last element
tab
move us to the first element. -
If it is the first element
shift
+tab
move us to the last element.
-
- Like drawer panel.
- This can lead focus to visually disappear.
- You can track the focus (active element) by
document.activeElement;
- Overcome it by setting
display: none;
orvisibility: hidden;
- WebAim
- It is desirable in modals when you want to trap keyboard focus inside the modal until you close it => return focus to the last focused element before modal open.
- Example
- Definition: the qualities or properties of an object that define its possible uses or make clear how it can or should be used.
- WebAim
- Screen reader can provide info for elements' Name(label) Role State Value.
- Browser takes DOM tree (natively semantic elements or othered with ARIA) ==modify it to==> Accessibility tree( containing all information for screen reader Name Role State Value).
- WebAim
- Element could have a visual label (name) like for radio button or text alternative like in case of images.
- There are 2 ways of labeling form inputs.
<label>
<input type="radio">
Check me
</label>
<input type="radio" id="radio-button">
<label for="radio-button">Check me</label>
- Using these labeling allow user to toggle the input element by also clicking the label.
- alt text: 1. An alternative to the image if not loaded. 2. describe what the image about for screen reader. 3. For logos you can assign the company name for alt attribute. 4. For search icon you can leave alt with no value. This will skip it from accessibility tree. 5. Any image that is meant for decoration should have an empty alt.
- Screen Reader can make you navigate through headings, links, form controls, and landmarks.
- It is important to use meaningful headings and links names.
- Also use a good heading structure from h1 to h6 (for long complex content).
- descriptive link text example: instead of using "learn more" links text use :learn more about bla bla".
- link Anti-patterns video
- Landmarks: you can navigate by landmarks
<header>
<nav>
<main>
<section>
<article>
<aside>
<footer>
-
WAI-ARIA: Web Accessibility Initiative - Accessible Rich Internet Application.
-
ARIA attributes need to have explicit values (can't be empty values).
-
What ARIA can do and what can not do:
- Can:
✅ modify Accessibility tree.
- Can Not:
❌ modify element behaviour.
❌ modify element appearance.
❌ add focus.
❌ add event handling.
-
ARIA give a semantic meaning to non semantic elements.
-
ARIA can also give a new semantic meaning to a native semantic element.
- Example:
<button role="switch" aria-checked="true" class="toggle"> Enable </button>
-
ARIA can express UI patterns which doesn't exist in HTML.
- Example:
tree widget
- Example:
-
ARIA can add labels which is only accessible to assestive technology.
-
ARIA can provide semantic Relationship.
-
ARIA can provide live updates (aria-live).
-
the video explains that.
-
Definition: Short hand for a particular UI pattern.
-
make sure that the role attribute is in the same element as tabindex attribute.
<div tabindex="0" role="checkbox" aria-checked="true" class="checkbox" checked>check me</div>
-
aria-label attribute
- Can be used for element that has only a visual appearance.
- override any other labelling such as
<label>
, or text content (like that for a button) except aria-labelledby attribute. - have the label clicking behaviour like
<label>
-
aria-labelledby attribute
- Overcome all other labelling methods.
- refers to another element (which label it) by using a value corresponds to the id of the labelling element.
- can take more than one element id (multiple labels) .
- can refer to elements that are hidden for assestive technologies ( hidden for example).
- Don't have the label clicking behaviour like
<label>
andaria-label
.
- Landmarks may not have support in browsers' old versions. So we need to use role attribute with them.
-Examples:
<header role="banner"> <nav role="navigation"> <main role="main"> <aside role="complementary"> <footer role="contentinfo"> <dialog role="dialog">
-
ARIA relationship attributes
- They take a reference to one or more elements on the page to make a link between them.
- The difference is: 1. What link means. 2. How represented to users.
-
Attributes:
aria-labelledby
aria-describedby
aria-owns
aria-activedescendant
aria-posinset
aria-setsize
-
Video explains it.
e. Visible and Hidden content
-
For the seek of fine tuning the experience of users using assistive tech.
-
To ensure that certain parts of the DOM is either:
- hidden to assistive tech. Or
- Only visible to assistive tech.
-
Hidden:
<button style="visibility: hidden;"> <div style="display: none;"> <span hidden>
aria-hidden="true"
-
Only visible to assistive tech:
- element positioned absolute far off the screen.
position: absolute; left: -1000;
aria-label
aria-labelledby
oraria-describedby
reference a hidden element.
- element positioned absolute far off the screen.
- for in time alerts to user.
aria-live="polite"
: important but not urgent alert.aria-live="assertive"
: important and urgent alert.
-
attributes work with
aria-live
. -
They are:
-
aria-atomic
: when true assistive tech will present the entire region as a whole. -
aria-relevant
:indicates which type of changes should be presented to the user.aria-relevant="additions"
==> means any element added to live region is presented.aria-relevant="text"
==> means that any text content added to any descendant element is presented.aria-relevant="removals"
==> means that removal of any text or element within the live region is presented.aria-relevant="all"
==> means that additions or removals of text is presented.aria-relevant="additions text"
(default).
-
-
aria-busy
- WebAim.
- video shows different styling for focus using :focus pseudo selector.
- video shows different styling reaction between native and non native buttons.
- Styling with ARIA ==> using ARIA attribute as an attribute selector. This made a good verification that I set the aria state properly.
- Responsive website:
- WebAim.
- meta viewport tag:
<meta name="viewport" content="width=device-width, initial-scale=1">
- In meta viewport tag: don't use
user-scalable=no
==> prevent user from zooming the screen. - Use relative CSS units.
- Use appropriate size touch targets.Minimum touch target size is 48 px.
- If the touch target(like icons) is smaller, add padding to it.
- To avoid overlapping make sure to leave margin around touch target with minimum 32px.
- Color Contrast:
-
WebAim Minimum. -It states that: Body text (less than 18.66px) ==> Contrast ratio minimum
4.5:1
Large Text (more than 18.66px) or (24px) ==> Contrast ratio minimum3:1
-
WebAim Enhanced. -It states that: Body text (less than 18.66px) ==> Contrast ratio minimum
7:1
Large Text (more than 18.66px) or (24px) ==> Contrast ratio minimum4.5:1
-
- You can use {Chrome Accessibility Extension}(https://chrome.google.com/webstore/detail/accessibility-developer-t/fpkknkljclfencbdbgkenhalefipecmb?hl=en) to make Accessibility Audit to check contrast ratios and see recommendations and try them live at Dev tools.
- 1 of 20 men and 1 in 200 women suffer from some sort of color blindness.
- Don't convey info with color alone.
- You can use color together with text, underline, audio, and aria-live.
- WebAim.
- You can use Nocoffee chrome extension to experience color blindness vision and enhance use of color to convey info.
- You can use High Contrast chrome extension and check how your UI appear for high contrast users.