Accessible
index
layout: collection
override:tags: []
date: 2018-11-05
pathName: accessible
Accessible responsive design
We know that it's a good idea to design responsively to provide the best multi-device experience,
but responsive design also yields a win for accessibility.
Consider a site like Udacity:
The Udacity site
A low-vision user who has difficulty reading small print might zoom in the page,
perhaps as much as 400%.
Because the site is designed responsively,
the UI will rearrange itself for the "smaller viewport" (actually for the larger page),
which is great for desktop users who require screen magnification
and for mobile screen reader users as well. It's a win-win.
Here's the same page magnified to 400%:
The Udacity site zoomed to 400%
In fact, just by designing responsively,
we're meeting rule 1.4.4 of the WebAIM checklist,
which states that a page "… should be readable and functional when the text size is doubled."
Going over all of responsive design is outside the scope of this guide,
but here are a few important takeaways that will benefit your responsive experience
and give your users better access to your content.
Use the viewport meta tag
Setting
width=device-width will match the screen's width in device-independent pixels,
and setting
initial-scale=1 establishes a 1:1 relationship between CSS pixels and device-independent pixels.
Doing this instructs the browser to fit your content to the screen size,
so users don't just see a bunch of scrunched-up text.
See Size content to viewport to learn more.
Allow users to zoom
It is possible to use the viewport meta tag to prevent zooming,
by setting
maximum-scale=1 or
user-scaleable=no.
Avoid doing this, and let your users zoom in if they need to.
Design with flexibility
Avoid targetting specific screen sizes and instead use a flexible grid,
making changes to the layout when the content dictates.
As we saw with the Udacity example above, this approach ensures that the design responds
whether the reduced space is due to a smaller screen or a higher zoom level.
You can read more about these techniques in the Responsive web design basics article.
Use relative units for text
To get the best out of your flexible grid
use relative units like em or rem for things like text size, instead of pixel values.
Some browsers support resizing text only in user preferences,
and if you're using a pixel value for text, this setting will not affect your copy.
If, however, you've used relative units throughout,
then the site copy will update to reflect the user's preference.
This will enable the whole site to reflow as the user zooms,
creating the reading experience they need to use your site.
Avoid disconnecting the visual view from the source order
A visitor who is tabbing through your site with the keyboard
will be following the order of the content in the HTML document.
When using modern layout methods such as Flexbox and Grid,
it is easy to make the visual rendering not match the source order.
This can lead to disconcerting jumps around the page for someone using the keyboard to move around.
Make sure to test your design at each breakpoint by tabbing through the content,
does the flow through the page still make sense?
Read more about the source and visual display disconnect.
Take care with spatial clues
When writing microcopy avoid using language which indicates the location of an element on the page.
For example, referring to navigation "on your left" makes no sense in a mobile version
when the navigation is at the top of the screen.
Ensure tap targets are large enough on touchscreen devices
On touchscreen devices make sure your tap targets are large enough
to make them easy to activate without hitting other links.
A good size for any tappable element is 48px,
read more guidance on tap targets.
Accessible tap targets
When your design is displayed on a mobile device,
you should ensure that interactive elements like buttons or links are large enough,
and have enough space around them,
to make them easy to press without accidentally overlapping onto other elements.
This benefits all users,
but is especially helpful for anyone with a motor impairment.
A minimum recommended touch target size is around 48 device independent pixels
on a site with a properly set mobile viewport.
For example, while an icon may only have a width and height of 24px,
you can use additional padding to bring the tap target size up to 48px.
The 48x48 pixel area corresponds to around 9mm,
which is about the size of a person's finger pad area.
In the demo, I have added padding to all of the links in order to make sure they meet the minimum size.
https://glitch.com/edit/#!/tap-targets
Touch targets should also be spaced about 8 pixels apart,
both horizontally and vertically,
so that a user's finger pressing on one tap target does not inadvertently touch another tap target.
Testing your touch targets
If your target is text and you have used relative values such as
em or
rem to size the text and any padding,
you can use DevTools to check that the computed value of that area is large enough.
In the example below I am using
em for my text and padding.
https://glitch.com/edit/#!/tap-targets-2
Inspect the
a of the link,
and in Chrome DevTools switch to the Computed pane where you can inspect the various parts of the box
and see what pixel size they resolve to.
In Firefox DevTools there is a Layout Panel.
In that Panel you get the actual size of the inspected element.
The Layout Panel in Firefox DevTools showing the size of the a element
Using media queries to detect touchscreen use
Instead of simply testing for viewport dimensions, and then guessing
that small dimensions are likely to be phones or tablets, which in turn
use a touchscreen, there are now more robust ways to adapt
your design based on actual device capabilities.
One of the media features we can now test for with media queries
is whether the user's primary input is a touchscreen (
pointer) and
whether any of the currently detected inputs is a touchscreen (
any-pointer).
The
pointer and
any-pointer features will return
fine or
coarse.
A fine pointer will be someone using a mouse or trackpad,
even if that mouse is connected via Bluetooth to a phone.
A
coarse pointer indicates a touchscreen,
which could be a mobile device but may also be a laptop screen or large tablet.
If you are adjusting your CSS within a media query to increase the touch target,
testing for a coarse pointer allows you to increase the tap targets for all touchscreen users.
This gives the larger tap area whether the device is a phone or larger device.
.container a {
padding: .2em;
}
@media (any-pointer: coarse) {
.container a {
padding: .8em;
}
}
You can find out more about interaction media features such as pointer
in the Responsive web design basics article.
Color and contrast accessibility
If you have good vision, it's easy to assume that everyone perceives colors,
or text legibility, the same way you do—but of course that's not the case.
As you might imagine,
some color combinations that are easy for some people to read are difficult or impossible for others.
This usually comes down to color contrast,
the relationship between the foreground and background colors' luminance.
When the colors are similar, the contrast ratio is low;
when they are different, the contrast ratio is high.
The WebAIM guidelines recommend an AA (minimum) contrast ratio of 4.5:1 for all text.
An exception is made for very large text (120-150% larger than the default body text),
for which the ratio can go down to 3:1. Notice the difference in the contrast ratios shown below.
An image showing the different contrast ratios
The contrast ratio of 4.5:1 was chosen for level AA
because it compensates for the loss in contrast sensitivity
usually experienced by users with vision loss equivalent to approximately 20/40 vision.
20/40 is commonly reported as typical visual acuity of people at about age 80.
For users with low vision impairments or color deficiencies,
we can increase the contrast up to 7:1 for body text.
You can use the Accessibility Audit in Lighthouse to check your color contrast.
Open DevTools, click Audits, and select Accessibility to run the report.
A screenshot of the output of an audit for color contrast.
Chrome also includes an experimental feature to help you detect all the low contrast texts of your page. You can also use the accessible color suggestion to fix the low contrast text.
A screenshot of the output of the Chrome low contrast text experimental feature.
For a more complete report, install the Accessibility Insights Extension.
One of the checks in the Fastpass report, is color contrast.
You will get a detailed report of any failing elements.
The report in Accessibility Insights
Advanced Perceptual Contrast Algorithm (APCA)
The Advanced Perceptual Contrast Algorithm (APCA) is a new way to compute contrast based on modern research on color perception.
Compared to AA/AAA guidelines, APCA is more context-dependent.
The contrast is calculated based on the following features:
Spatial properties (font weight and text size)
Text color (perceived lightness difference between text and background)
Context (ambient light, surroundings, and intended purpose of the text)
Chrome includes an experimental feature to replace the AA/AAA contrast ratio guidelines with APCA.
A screenshot of the output of the APCA feature in Chrome.
Don't convey information with color alone
There are roughly 320 million people worldwide with color vision deficiency.
About 1 in 12 men and 1 in 200 women have some form of "color blindness";
that means about 1/20th, or 5%, of your users will not experience your site the way you intended.
When we rely on color to convey information, we push that number to unacceptable levels.
Note: The term "color blindness" is often used to describe a visual condition where a person has trouble distinguishing colors,
but in fact very few people are truly color blind.
Most people with color deficiencies can see some or most colors,
but have difficulty differentiating between certain colors such as reds and greens (most common),
browns and oranges, and blues and purples.
For example, in an input form,
a telephone number might be underlined in red to show that it is invalid.
But to a color deficient or screen reader user, that information is not conveyed well, if at all.
Thus, you should always try to provide multiple avenues for the user to access critical information.
A image of an input form with an incorrect phone number highlighted only with a red color.
The WebAIM checklist states in section 1.4.1 that
"color should not be used as the sole method of conveying content or distinguishing visual elements."
It also notes that "color alone should not be used to distinguish links from surrounding text"
unless they meet certain contrast requirements.
Instead, the checklist recommends adding an additional indicator such as an underscore
(using the CSS
text-decoration property) to indicate when the link is active.
An easy way to fix the previous example is to add an additional message to the field,
announcing that it is invalid and why.
The same input form as in the last example, this time with a text label indicating the problem with the field.
When you're building an app, keep these sorts of things in mind
and watch out for areas where you may be relying too heavily on color to convey important information.
If you're curious about how your site looks to different people,
or if you rely heavily on the use of color in your UI,
you can use DevTools to simulate various forms of visual impairment,
including different types of color blindness.
Chrome includes an Emulate Vision Deficiencies feature.
To access it open DevTools and then open the Rendering tab in the Drawer,
you can then emulate the following color deficiencies.
Protanopia: the inability to perceive any red light.
Deuteranopia: the inability to perceive any green light.
Tritanopia: the inability to perceive any blue light.
Achromatopsia: the inability to perceive any color except for shades of grey (extremely rare).
Emulating the vision of a person with Achromatopsia shows our page in greyscale.
High contrast mode
High-contrast mode allows a user to invert foreground and background colors,
which often helps text stand out better.
For someone with a low vision impairment,
high-contrast mode can make it much easier to navigate the content on the page.
There are a few ways to get a high-contrast setup on your machine.
Operating systems like Mac OSX and Windows offer high-contrast modes
that can be enabled for everything at the system level.
A useful exercise is to turn on high-contrast settings
and verify that all of the UI in your application is still visible and usable.
For example, a navigation bar might use a subtle background color
to indicate which page is currently selected.
If you view it in a high-contrast extension, that subtlety completely disappears,
and with it goes the reader's understanding of which page is active.
Screenshot of a navigation bar in high contrast mode where the acvtive tab is hard to read
Similarly, if you consider the example from the previous lesson,
the red underline on the invalid phone number field might be
displayed in a hard-to-distinguish blue-green color.
Screenshot of the address form used earlier, this time in high contrast mode. The color change of the invalid element is hard to read.
If you are meeting the contrast ratios covered earlier
you should be fine when it comes to supporting high-contrast mode.
But for added peace of mind, consider installing the
High Contrast Chrome Extension
and giving your page a once-over just to check that everything works, and looks, as expected.
Content reordering
The order of content in your document is important for the accessibility of your site.
A screen reader will read out content based on the document order,
using the HTML elements that you have selected to give meaning to that content.
A person navigating the site using a keyboard, rather than a touchscreen or mouse, will tab around the document.
This means that they will jump from active element to active element,
tabbing between links and form fields, once again in the order they exist in the document.
Starting with a well-structured document and using all of the right HTML elements
is therefore a key part of creating an accessible site.
However, it is possible to undo some of that good work when you start using CSS. Let's take a look at why.
Source vs. visual order
Website navigation is often marked up as a list of links.
You can then use Flexbox to turn these into a horizontal bar.
In the Glitch example below, I have created this commonly used pattern.
Click into the example, and tab between the links.
The focus will move in a logical direction from left to right,
the order that we read in English.
https://glitch.com/edit/#!/flex-nav-source-ordered
If you have created this sort of pattern and then were asked to move Contact Us,
which is second in the source, to the end. You could use the
order property which works in Flexbox.
Try tabbing through the items in the example below, which has used the
order property to rearrange the items.
https://glitch.com/edit/#!/flex-nav-ordered
The focus jumps to the final item and then back again.
As far as the tab order is concerned that item is the second item.
Visually however, it's the last item.
The above example highlights the problem that we face if we rearrange and reorder content using CSS.
If you were dealing with this issue then the right thing to do would be to change the order in the source,
rather than using CSS.
Which CSS properties can cause reordering?
Any layout method that allows you to move elements around can cause this problem.
The following CSS properties commonly cause content reordering problems:
Using
position: absolute and taking an item out of flow visually.
The
order property in Flexbox and Grid layout.
The
row-reverse and
column-reverse values for
flex-direction in Flexbox.
The
dense value for
grid-auto-flow in Grid Layout.
Any positioning by line name or number, or with
grid-template-areas in Grid Layout.
In this next example, I have created a layout using CSS Grid and positioned the items
using line numbers, without considering where they are in the source.
https://glitch.com/edit/#!/grid-mixed-up-order
Try tabbing around this example, and see how the focus jumps about.
This makes for a very confusing experience, especially if this is a long page.
Testing for the problem
A very simple test is to keyboard navigate through your page. Can you get to everything?
Are there any strange jumps as you do so?
For a visual demonstration of content reordering,
try the Tab Stop checker in the Accessibility Insights extension for Chrome.
The image below shows the CSS Grid example in that tool.
You can see how the focus has to jump around the layout.
A screenshot of the Accessibility Insights Tool demonstrating the confusing order of items.
Content reordering and responsive web design
If you only have one presentation of your content,
then having your source in a logical order, and reflecting that in layout is not usually difficult.
It can become harder, when you consider the layout at different breakpoints.
It might make sense to have an element moved to the bottom of the layout on smaller screens for example.
There is not at this time a good solution for this problem.
In most situations developing "mobile first", will help you keep your source and layout in order.
The choices you make about priority on mobile, are often solid ones for the content in general.
The key is to be aware when there is a possibility of this type of content reordering,
and to test that the end experience is not too jarring at each breakpoint.
Control focus with tabindex
Standard HTML elements such as