Skip to content

Commit a1eb7bc

Browse files
committed
Allow animations, scrolling effects, and transitions to be reduced in all browsers
1 parent 5d86afd commit a1eb7bc

2 files changed

Lines changed: 60 additions & 0 deletions

File tree

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ A separate stylesheet that normalizes typography using system interface fonts.
4545

4646
[Learn more about `typography.css`](#typography).
4747

48+
#### Reduce Motion CSS
49+
50+
A separate stylesheet that normalizes typography using system interface fonts.
51+
52+
```html
53+
<link href="https://unpkg.com/sanitize.css/reduce-motion.css" rel="stylesheet" />
54+
```
55+
56+
[Learn more about `reduce-motion.css`](#reduce-motion).
57+
4858
#### Page CSS
4959

5060
A separate stylesheet that applies a comfortable measure to plain documents.
@@ -397,6 +407,36 @@ code, kbd, pre, samp {
397407
}
398408
```
399409

410+
## Reduce Motion
411+
412+
[sanitize.css] includes a separate stylesheet for restricting motion when the
413+
user has requested this at a system level.
414+
415+
```html
416+
<link href="https://unpkg.com/sanitize.css" rel="stylesheet" />
417+
<link href="https://unpkg.com/sanitize.css/reduce-motion.css" rel="stylesheet" />
418+
```
419+
420+
### Reduce Motion Features
421+
422+
##### Animations, scrolling effects, and transitions are reduced in all browsers
423+
424+
```css
425+
@media (prefers-reduced-motion: reduce) {
426+
*,
427+
::before,
428+
::after {
429+
animation-delay: -1ms !important;
430+
animation-duration: 1ms !important;
431+
animation-iteration-count: 1 !important;
432+
background-attachment: initial !important;
433+
scroll-behavior: auto !important;
434+
transition-delay: 0s !important;
435+
transition-duration: 0s !important;
436+
}
437+
}
438+
```
439+
400440
## Contributing
401441

402442
Please read the [contribution guidelines](CONTRIBUTING.md) in order to make the

reduce-motion.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* 1. Remove animations when motion is reduced (opinionated).
3+
* 2. Remove fixed background attachments when motion is reduced (opinionated).
4+
* 3. Remove timed scrolling behaviors when motion is reduced (opinionated).
5+
* 4. Remove transitions when motion is reduced (opinionated).
6+
*/
7+
8+
@media (prefers-reduced-motion: reduce) {
9+
*,
10+
::before,
11+
::after {
12+
animation-delay: -1ms !important; /* 1 */
13+
animation-duration: 1ms !important; /* 1 */
14+
animation-iteration-count: 1 !important; /* 1 */
15+
background-attachment: initial !important; /* 2 */
16+
scroll-behavior: auto !important; /* 3 */
17+
transition-delay: 0s !important; /* 4 */
18+
transition-duration: 0s !important; /* 4 */
19+
}
20+
}

0 commit comments

Comments
 (0)