1.2 Appearance
Introduction
Accessibility (A11Y) is more than making information available to people.
As web creators we should respect people's preferences, so that they can perceive the content with ease, regardless of their abilities.
Let's start with the three most common appearance topics: color, proportions and motion.
Color
Color contrast is the biggest A11Y issue, yet one of the easiest to fix, by following the WCAG color contrast guidelines.
Our vision can be highly dependent on our environment (e.g. looking to the phone screen under the sun is harder than inside a building). That's one of the reasons why color constrast is such an essential topic regardless of someone's vision ability.
My favorite color tools:
- WebAIM contrast checker - Web page
- Colour Contrast - Web page
- Stark - Figma plugin
Proportions (size)
It's out of our control to know the exact size or font that will be presented to people because a webpage can be consumed in multiple mediums.
For that reason, it's safer to think about proportions instead of sizes when building interfaces. This can be achieved by using relative units instead of absolute units for text size.
The relative units rem
and em
are the best replacements for px
. An em
is a unit of typography, relative to the font-size
of its nearest parent. A rem
is only relative to the html (root) font-size
.
The default font-size
in almost every browser is 16px
. Assuming that, we can say that 1rem = 16px
.
.title {
/*font-size: 24px; ---- old away */
font-size: 1.5rem; /* - new way: 24/16 */
}
Math simplified: The math x/16
can be painful when dealing with certain numbers. (eg 15px equals 0.9375rem). We can simplify that by setting the root size to 62.5%, which means 1rem
equals 10px
.
html {
/* 62.5% of 16px is 10px. */
font-size: 62.5%;
}
body {
font-size: 1.6rem; /* 16px */
}
.title-xl {
/* font-size: 28px; */ /* -- old way */
font-size: 2.8rem; /* ------ new way */
}
Motion
We tend to use motion techniques as a way to communicate information. However, some people find them distracting or uncomfortable. Others can't even see the animations, particularly people with cognitive disabilities or slow devices.
Remember that animations are an enhancement and should not be a barrier to understand the content. Creating immersive experiences can't be an excuse to bypass accessibility.
The CSS media query preferes-reduced-motion
allows us to respect the user's motion preferences.
.error {
animation: shake 400ms;
}
@media (prefers-reduced-motion: reduce) {
.error {
animation: none;
}
}
Or, even better, take a "no motion by default" approach where animations are added on top.
.error {
animation: none;
}
@media (prefers-reduced-motion: no-preference) {
.error {
animation: shake 400ms;
}
}
The main practical difference between both approachs is that the animations won't run in old browsers (usually means slower devices) which will avoid a flanky motion experience.
Exercise
In the exercise page, there are multiple accessibility problems related to color and proportions:
- Color: Some text has not enough color contrast.
- Size: The text size is written with absolute units.
- Motion: The notification bell animation can be annoying to some people.
🎯 Goal: Make the page follow appearance guidelines that respect level AA.
Hint 1: Use a browser extension to help you detect color contrast issues.
Hint 2: Use the DevTools color picker to find a color that respects level AA.
Hint 3: Customize your browser font size to see how the content is displayed as you update the code from absolute to relative units. Go to Settings > Appearance > Font Size. (Chrome and Firefox)
Hint 4: In Chrome, you can emulate a motion settings. In Dev Tools, go to Settings > Rendering. Scroll down until "Emulate CSS media" section and select the preferred motion setting. Change in other browsers
Bonus - Achieving Level AAA
1. Color Theming
When creating multiple themes, we can use the CSS media query prefers-color-scheme
to set the default theme based on the user color preferences.
🎯 Goal: Add a dark
theme to the page. Here are the colors:
--theme-text_0: hsl(0deg 0% 89%);
--theme-text_1: hsl(0deg 0% 68%);
--theme-bg_0: hsl(280deg 3% 23%);
--theme-bg_1: hsl(288deg 6% 17%);
--theme-primary: hsl(180deg 100% 45%);
--theme-primary_smooth: hsl(180deg 100% 19%);
--theme-secondary: hsl(26deg 100% 68%);
--theme-success: greenyellow;
Hint: In Chrome, you can emulate a color scheme. In Dev Tools, go to Settings > Rendering. Scroll down until "Emulate CSS media" and select the preferred color scheme.
2. Visual presentation
There are a few small tweaks we can still do, following the WCCAG recommendations for blocks of text, such as:
- Width is no more than 80 characters or glyphs.
- Text is not justified.
- Paragraph line-height is at least 1.5 the font size.
🎯 Goal: Update the page to follow the criterion above.
Further reading
Browser extensions
Articles
- The myths of color contrast accessibility
- The complete guide to dark mode on the web.
- Why you shouldn't "just use pixels"
- Don’t use rem/em for paddings, margins and more
- prefers-reduced-motion: Taking a no-motion-first approach
- A note about automated accessibility "warnings"
WCAG Success Criterion
- WCAG 1.4.1 Use of color - Level A
- WCAG 1.4.3 Contrast (Minimum) - Level AA
- WCAG 1.4.6 Contrast (Enhanced) - Level AAA
- WCAG 1.4.4 Resize text - Level AA
- WCAG 1.4.8 Visual Presentation - Level AAA
- WCAG 1.4.12 Text spacing - Level AA
- WCAG 2.3.3 Animation from interactions - Level AAA
Exercise takeaways
(After the exercise) Reveal takeaways
- Color: Most color contrast issues can be catched automatically.
- Color: Include a "Colors Guide" in your Design System, showing correct and common wrong combinations.
- Proportions: Prefer relative units for text and containers sizes.
- Proportions: Ensure the page is responsive up to 200% zoom.
- Animations: Adopt a no-motion-first approach. Only add motion if it's clear the user has no preferences.
- Custom preferences: When creating a preference toggle (e.g. dark theme), ensure its initial value matches the user preferences, and it keeps the selected option on page refresh.