Accessibility- Style
Source: Accesibility - Udacity Front End Web Development Nanodegree
- How frequently is this piece of User Interface (UI) used?
- How badly does this accessibility issue affect users?
- How expensive is going to be to fix the issue?
- The pseudo code
focus
only matchend when an element has focus:
:focus {
//Use the "outline " property to change the appeareance of the focus ring
outline: 1 pc dotted #fff;
}
NOTE: This is a MAJOR anti-pattern
- Without a focus indicator, a user does not know which keyboard element to interact with.
:focus {
outline: 0;
}
Alternatives are:
- Give your element the same hover focussed styles
button:hover,
button: focus {
background: #e91e63;
color: #fff;
text-decoration: underline;
}
- Use a specific focus pseudo class in CSS (to get a consistent indicator across browsers)
button: focus {
outline: 0;
box-shadow: 0 0 8px 3 px;
rgba (255, 255, 255, 0.8);
}
- Delete default focus indicator, use focus style
.radio:focus {
outline: 0;
}
.radio:focus::before {
box-shadow: 0 o 1px 2 px #5b9dd9;
}
- Leave the default focus ring in place.
- If you want to change, use the :focus pseudo class to create your own styled focus indicator.
- Exercice
- WebAim-2.4.7 checklist.
- :focus
- outline
- :hover-pseudo-class
- ::before-pseudo-element
- video- Styling for focus :focus pseudo selector.
<div class="btn"
role= "button"
tabindex="0">
Click me!
</div>
:moz-focusring
pseudo-class. Only supported in Firefox!- Proposing CSS input modality article.
- Input modality shim(https://github.com/WICG/focus-visible).
- video_ Styling native/non-native buttons.
-
Styling with ARIA ==> use ARIA attribute as an attribute selector. To set the aria state properly, so it is visually reflected.
-
When building custom controls be sure to include tabindex so keyboard users can easily interact with the elements.
-
A huge benefit to styling with ARIA: it provides visual feedback, which can act as a safeguard when testing and debugging code.
-
HTML not toggled:
<div class="toggle"
role= "button"
aria-labelledby="muteLbl"
aria-pressed="false"
tabindex="0">
Mute
</div>
- HTML toggled:
<div class="toggle pressed"
role= "button"
aria-labelledby="muteLbl"
aria-pressed="true"
tabindex="0">
Mute
</div>
- CSS toggled:
.toggle.pressed{
// transition to
// pressed state
}
- CSS toggled- with aria attr:
.toggle[aria-pressed= "true"]{
// transition to
// pressed state
}
- On older browsers (Mobile Safari) developers would add user-scaleable=no because it disables the 350ms click delay in that browser. - As of Safari 9.1 this is no longer the case, and using
width=device-width
in your viewport will handle removing that click delay. - 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: 48 px.
- If touch target (
icons
) <48 px, add padding. - To avoid overlapping, leave margin around touch target. Minimum 32px.
- WebAim.
- Udacity course on Responsive Web Design Fundamentals
- Responsive web design basics on Web Fundamentals
- Material Design Accessibility recommendations for touch targets
-
Don't convey info with color alone, as 1 of 20 men and 1 in 200 women suffer from some sort of color blindness.
-
Use
color
together withtext
,underline
,audio
, andaria-live
. -
Color Contrast:
- Body text (less than 18.66px) ==> Contrast ratio minimum
4.5:1
- Large Text (more than 18.66px) or (24px) ==> Contrast ratio minimum
3:1
- Body text (less than 18.66px) ==> Contrast ratio minimum
-
Color Contrast ratio:
- Body text (less than 18.66px) ==> Contrast ratio minimum
7:1
- Large Text (more than 18.66px) or (24px) ==> Contrast ratio minimum
4.5:1
- Body text (less than 18.66px) ==> Contrast ratio minimum
-
Accessibility Audit:
- Check contrast ratios/see recommendations/try Live at Dev tools
- Experience color blindness vision, enhance use of color to convey info
- Check how UI appear for high contrast users