The Reduced Motion Media Query
Sites all too often inundate their audiences with automatically playing, battery-draining, resource-hogging animations. The need for people being able to take back control of animations might be more prevalent than you may initially think.
[…]
Remember: we’re all just temporarily-abled. Feeling a little dizzy might not seem like that big a deal, but that moment of nausea might be a critical one: losing balance and falling down, a migraine during an interview, nausea-triggered vomiting while working a food service job, passing out while operating a car UI, etc.
So what can we do about it?
Enter a new Media Query
Safari 10.1 introduces the Reduced Motion Media Query. It is a non-vendor-prefixed declaration that allows developers to “create styles that avoid large areas of motion for users that specify a preference for reduced motion in System Preferences.”
The syntax is pretty straightforward:
Code language: CSS
@media (prefers-reduced-motion: reduce) {
.background {
animation: none;
}
}
Safari will parse this code and apply it to your site, letting you provide an alternative experience for users who have the Reduced Motion option enabled. Think of this new Media Query like
@supports
: describe the initial appearance, then modify the styles based on capability.
Toggletip widget pattern (tooltip alternative)
What it does
- Uses a real
button
as a control.- Places the displayed content next in DOM order after the button.
- Uses some ARIA magic to augment the semantics and behaviour.
- Displays or dismisses content on click, press or tap (also dismisses on
esc
key press).- Conveys state (collapsed or expanded) to AT users.
- When initially displayed content is announced by (most) screen readers that support
aria-live
.- Screen readers users can also virtual cursor through and interact with the displayed content.
- keyboard only users can interact with controls in the displayed content.
What it does not do
Display content on mouse cursor hover.
Using the aria-current attribute
It is common on the web for the current thing in a collection to be highlighted visually, but providing an alternative for screen reader users has often involved something of a hack. The
aria-current
attribute is intended to solve this problem.[…]
Here’s the official attribute definition:
Indicates the element that represents the current item within a container or set of related elements. The
aria-current
attribute is an enumerated type. Any value not included in the list of allowed values should be treated by assistive technologies as if the value true had been provided. If the attribute is not present or its value is an empty string, the default value of false applies and thearia-current
state must not be exposed by user agents or assistive technologies.According to the ARIA 1.1 specification, the
aria-current
attribute can be given one of a predefined set of values (enumerated tokens):
- page
- represents the current page within a set of pages;
- step
- represents the current step within a process;
- location
- represents the current location within an environment or context;
- date
- represents the current date within a collection of dates;
- time
- represents the current time within a set of times;
- true
- represents the current item within a set;
- false
- does not represent item within a set.
So the
aria-current
attribute can be used to solve the first use case in this post like this:
Code language: CSS
[aria-current] {
font-weight: bold;
background-color: #cc33ff;
}
When a screen reader encounters the link identified with
aria-current
, it will announce something like “Home, current page link”.Whenever
aria-current
is used with a value other than true, that information is incorporated into the screen reader announcement. For example in this set of steps, a screen reader will announce “Do this, current step link”.
The Bias in What We Build
I’ve been thinking a lot lately about our biases and their influence on what we build and how. We’re all biased in some way—it’s an inevitable side-effect of living. We experience certain things, we live in a certain environment, we have certain interactions and over time all of these experiences and factors add up to impact the way we view ourselves and the way we view others.
These biases come into play over and over again in our work, and can have devastating consequences.
There was an interesting post on The Coral Project about anonymity and its impact—or rather, non-impact—on online behavior. A frequent refrain heard when we try to understand why online behavior is so frequently so poor is that the ability to be anonymous is one of the primary reasons for the problem. J. Nathan Matias argues differently, though:
Not only would removing anonymity fail to consistently improve online community behavior – forcing real names in online communities could also increase discrimination and worsen harassment.
We need to change our entire approach to the question. Our concerns about anonymity are overly-simplistic; system design can’t solve social problems without actual social change.
While the article cites a little bit of research questioning our assumptions about anonymity online, the bulk of the article is focused on reframing our perspective of the discussion. We often consider the question of bad behavior online from the perspective of the people misbehaving. What is it that makes them feel free to be so much more vindictive in an online setting? Matias instead builds his case by focusing on the victims of this behavior.
Revealing personal information exposes people to greater levels of harassment and discrimination. While there is no conclusive evidence that displaying names and identities will reliably reduce social problems, many studies have documented the problems it creates. When people’s names and photos are shown on a platform, people who provide a service to them – drivers, hosts, buyers – reject transactions from people of color and charge them more. Revealing marital status on DonorsChoose caused donors give less to students with women teachers, in fields where women were a minority. Gender- and race-based harassment are only possible if people know a person’s gender and/or race, and real names often give strong indications around both of these categories. Requiring people to disclose that information forces those risks upon them.
[…]
[O]ne thing we can state about removing anonymity is that it increases the risk for people on the receiving end of online harassment.
Removing anonymity online, then, is yet another example of how we reflect our own biases in the decisions we make and the things we build.
It is our biases that lead us to overlook accessibility or how an application performs on a low-powered device or spotty network.
It is our biases that lead us to develop algorithms that struggle to recognize women’s voices or show more high-paying executive jobs to men than women.
And it is our biases that lead us to frame the problem of online behavior from that of the attacker, leading to solutions that are dangerous for the people on the receiving end of that harassment.
In each of these situations, our biases don’t just lead us to build something that is hard to use; they cause us to actively, if unintentionally, exclude entire groups of people.
Roving tabindex for keyboard navigation around JavaScript widgets
Setting the
tabindex
of the focused element to “0” ensures that if the user tabs away from the widget and then returns, the selected item within the group retains focus. Note that updating thetabindex
to “0” requires also updating the previously selected item totabindex="-1"
. This technique involves programmatically moving focus in response to key events and updating thetabindex
to reflect the currently focused item. To do this:Bind a key down handler to each element in the group, and when an arrow key is used to move to another element:
- programmatically apply focus to the new element,
- update the
tabindex
of the focused element to “0”, and- update the
tabindex
of the previously focused element to “-1”.Here’s an example of a WAI-ARIA tree view using this technique.
For a more visual explanation, see the following video by Rob Dodson:
Hiding DOM elements - ally.js
This document explains the various ways of hiding things and the implications that come with that.
When we say an element is hidden, we usually mean it is not visible. However, the screen is not the only output mechanism we may need to hide content from. Systems like screen readers and braille displays rely on a document’s representation in the accessibility tree. For disambiguation we’ll use the following terms:
- Completely hidden
- The element is not rendered on screen, not exposed in the accessibility tree, not accessible to keyboard navigation.
- Semantically hidden
- The element is rendered on screen, but not exposed in the accessibility tree, and still accessible to keyboard navigation.
- Visually hidden
- The element is not rendered on screen, but exposed in the accessibility tree, and still accessible to keyboard navigation.
[…]
How to hide elements completely
Completely hiding elements can be done in 3 ways:
- via the CSS property
display
, e.g.display: none;
- via the CSS property
visibility
, e.g.visibility: hidden;
- via the HTML5 attribute
hidden
, e.g.<span hidden>
While each of these techniques has the same end result, i.e. content is not rendered and not exposed in the accessibility tree, they have different behaviors.
[…]
How to hide elements semantically
To hide content from the accessibility tree but retain the content on screen, we may use the attribute
aria-hidden="true"
.[…]
2016 edition of
.visuallyhidden
[…]
Code language: CSS
.visuallyhidden:not(:focus):not(:active) {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
border: 0;
padding: 0;
clip-path: inset(100%);
clip: rect(0 0 0 0);
overflow: hidden;
}
- It works in all modern browsers including Internet Explorer 9 - 11.
- It side-steps the need to re-style everything for focusable elements such as skip-links.
- It accounts for the deprecated
clip
property.Keyboard navigation
The techniques to hide elements only visually or semantically come with a caveat. Focusable elements like
<a href="…">
remain keyboard navigatable, even though the element is not visible on screen or not exposed in the accessibility tree.To make sure sighted keyboard users do not end up focusing elements they can’t see, and screen reader users not focusing element’s that don’t exist for them, we need to make sure that partially hidden content is not accessible to keyboard navigation using the Tab and Shift Tab keys. To accomplish this, we can add
tabindex="-1"
to the elements we want to hide from the keyboard.Recap
- Use the
hidden
attribute to completely hide an element.- Use the
aria-hidden
attribute to hide an element from the accessibility tree.- Use the
.visuallyhidden
class to hide an element from the screen.- Use
visibility: inherit;
instead ofvisibility: visible;
to avoid accidentally showing content.- Do not attach any CSS styles to the
aria-hidden
attribute.- Take care of keyboard focusable content that is partially hidden by adding
tabindex="-1"
.
Alex Feyerke: Step Off This Hurtling Machine | JSConf.au 2014
I thought this was an excellent talk on the hard questions we should be asking ourselves as developers. Why do most people use closed, proprietary systems and devices, if the open web is so wonderful? Even as developers, we still use them ourselves, and depend on them. How can we be more empathetic to what the average user needs and wants? How can we lock open the web, so the future isn’t entirely dependent on huge corporations and services, which is where we seem to be heading?
You Can't Detect A Touchscreen
Whatever you may think, it currently isn’t possible to reliably detect whether or not the current device has a touchscreen, from within the browser.
And it may be a long time before you can.
Let me explain why…
Boxed in
The browser environment is a sandbox. Your app’s code can only get at things the browser wants you to, in order to limit the damage a malicious website can cause.
This means that the only information about the system you can get is what the browser exposes to you, in the form of HTML, CSS and JavaScript APIs. To determine if a system supports a certain feature, we can a) see if a certain API is present, or b) see if it actually does the right thing.
Historically, two browser features have been used for “touchscreen detection”: media queries and touch APIs. But these are far from foolproof.
Walk with me.
Device width media queries
Mobiles have small screens and mobiles have touchscreens, so small screen equals touchscreen, right?
[…]
So, so very wrong. Large tablets and touchscreen laptops/desktops have clearly proven this wrong. Plus thousands of older mobile handset models had small non-touch screens. Unfortunately, sites applying the mantra “If it’s a small screen, it’s touch; if it’s a big screen, it’s mouse-driven” are now everywhere, leaving tablet and hybrid users with a rubbish experience.
Touch APIs
[…]
If the browser supports events like
touchstart
(or other events in the Touch Events API spec) it must be a touchscreen device, right?[…]
Well, maybe. The problem is, no one ever said that a non-touch device can’t implement touch APIs, or at least have the event handlers in the DOM.
Chrome 24.0 shipped with these APIs always-on, so that they could start supporting touchscreens without having separate “touch” and “non-touch” builds. But loads of developers had already used detects like the example above, so it broke a lot of sites. The Chrome team “fixed” this with an update, which only enables touch APIs if a touch-capable input device is detected on start-up.
So we’re all good, right?
Not quite.
An API for an API
The browser is still quite a long way from the device itself. It only has access to the devices via the operating system, which has it’s own APIs for letting the browser know what devices are connected.
While these APIs appear to be fairly reliable for the most part, we recently came across cases whereby they’d give incorrect results in Chrome on Windows 8… they were reporting presence of a touchscreen (“digitizer”), when no touchscreen was connected.
Firefox also does some kind of similar switching and it appears to fail in the same cases as Chrome, so it looks like it might use the same cues – although I can’t profess to know for sure.
It appears certain settings and services can mess with the results these APIs give. I’ve only seen this in Windows 8 so far, but theoretically it could happen on any operating system.
Some versions of BlackBerry OS have also been known to leave the touch APIs permanently enabled on non-touch devices too.
So it looks like the browser doesn’t know with 100% confidence either. If the browser doesn’t know, how can our app know?
Drawing a blank
Assuming the presence of one of these touch APIs did mean the device had a touchscreen… does that mean that if such a touch API isn’t present then there definitely isn’t a touchscreen?
Of course not. The original iPhone (released in 2007) was the first device to support Touch Events, but touchscreens have been around in one form or another since the 1970s. Even recently, Nokia’s Symbian browser didn’t support touch events until version 8.2 was released last year.
IE 10 offers the (arguably superior) Pointer Events API on touch devices instead of the Touch Events spec, so would return
false
for theontouchstart
test.[…]
Neither Safari nor Opera has implemented either touch API in their desktop browsers yet, so they’ll draw a blank on touch devices too.
Without dedicated touch APIs, browsers just emulate mouse events… so there are loads of devices kicking about with touchscreens which you simply can’t detect using this kind of detection.
[…]
You’re doing it wrong
In my opinion, if you’re trying to “detect a touchscreen” in the first place, you’re probably making some dangerous assumptions.
[…]
So what should I do?
For layouts, assume everyone has a touchscreen. Mouse users can use large UI controls much more easily than touch users can use small ones. The same goes for hover states.
For events and interactions, assume anyone may have a touchscreen. Implement keyboard, mouse and touch interactions alongside each other, ensuring none block each other.
Front-End Performance Checklist 2017
This is an incredibly exhaustive list of performance tweaks, improvements, and best practices. Some may be outside the scope of smaller websites, but there are plenty of things for everyone.
Back in the day, performance was often a mere afterthought. Often deferred till the very end of the project, it would boil down to minification, concatenation, asset optimization and potentially a few fine adjustments on the server’s
config
file. Looking back now, things seem to have changed quite significantly.Performance isn’t just a technical concern: It matters, and when baking it into the workflow, design decisions have to be informed by their performance implications. Performance has to be measured, monitored and refined continually, and the growing complexity of the web poses new challenges that make it hard to keep track of metrics, because metrics will vary significantly depending on the device, browser, protocol, network type and latency (CDNs, ISPs, caches, proxies, firewalls, load balancers and servers all play a role in performance).
So, if we created an overview of all the things we have to keep in mind when improving performance — from the very start of the process until the final release of the website — what would that list look like? Below you’ll find a (hopefully unbiased and objective) front-end performance checklist for 2017 — an overview of the issues you might need to consider to ensure that your response times are fast and your website smooth.