You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2.[Discussion of the `controlled` Value](#discussion-of-the-controlled-value)
17
+
3.[Possible Extensions](#possible-extensions)
17
18
1.[Control Over Iterations](#control-over-iterations)
18
19
2.[Longhands And Further Controls](#longhands-and-further-controls)
19
20
3.[Control Over the Paused State](#control-over-the-paused-state)
@@ -61,6 +62,7 @@ For example:
61
62
* Turn off autoplay for decorative images when `prefers-reduced-motion` is on,
62
63
while keeping animations on for those that are part of UI interactions
63
64
65
+
<pid=there-to-stay>
64
66
In some cases,
65
67
this can already be done using alternatives to animated images,
66
68
such as CSS animations, SVG, or `<video>` elements,
@@ -196,6 +198,7 @@ Turn off autoplay on all images, showing UI controls for playback on animatable
196
198
```
197
199
Note that this can be applied just as easily by a site's author, a [web extension](https://w3c.github.io/webextensions/specification/), a user-stylesheet, without any modification to—or knowledge of—the site's markup patterns. Other uses could include a web-based email-client using this to keep animated images under control in HTML email.
198
200
201
+
<pid=ex-on-demand>
199
202
Same as above, in response to a [user request for reduced motion](https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion):
200
203
```css
201
204
@media (prefers-reduced-motion) {
@@ -216,6 +219,7 @@ and offering on-demand playback for relevant parts of the content.
216
219
}
217
220
```
218
221
222
+
<pid=ex-simple-controls>
219
223
The browser-provided controls are not the only way to start a paused image.
220
224
Elaborate controls can obviously be build with custom markup and script,
221
225
but simple cases can be done declaratively.
@@ -245,6 +249,85 @@ Interesting effects can easily be achieved in combination with other CSS:
245
249
.carouselimg:snapped { image-animation: play; }
246
250
```
247
251
252
+
### Discussion of the `controlled` Value
253
+
254
+
The `controlled` value presented above is more complex than the rest,
255
+
so it is worth taking some time to explain
256
+
why it is a reasonable and important part of this proposal.
257
+
258
+
<dl>
259
+
<dt>Is it OK to have a CSS property affect UI?
260
+
<dd>
261
+
There is precedent for CSS properties affecting the presence of UI controls on elements:
[`overflow: scroll` or `overflow: auto `](https://www.w3.org/TR/css-overflow-3/#overflow-control).
264
+
265
+
<dt>Do we need any such thing at all?
266
+
<dd>
267
+
As discussed [in the example above](#ex-simple-controls),
268
+
a simple interaction model can be built without any additional markup nor JS;
269
+
and certainly arbitrary UI can be built if you allow for extra markup and JS.
270
+
271
+
However, in the general case, authors have no way of knowing which images are static and which are animatable.
272
+
Without this knowledge, the choice is either to provide no controls at all,
273
+
or controls even on static images that don't need it.
274
+
275
+
Enabling authors (and web-extension developers, and writers of user stylesheets)
276
+
to disable by default unwanted animations,
277
+
while keeping the ability to view them on demand,
278
+
on existing content,
279
+
is an important motivation for this feature.
280
+
This is trivially achieved with this [previously discussed](#ex-on-demand) rule,
281
+
but out of reach otherwise:
282
+
```css
283
+
@media (prefers-reduced-motion) {
284
+
:root { image-animation: controlled; }
285
+
}
286
+
```
287
+
288
+
<dt>Couldn't we use pseudo-classes instead?
289
+
<dd>
290
+
Something like an `:animatable` pseudo class would solve the above information problem,
291
+
and authors could build their UI from there.
292
+
But would it be better?
293
+
We should make easy things easy,
294
+
and provide a good user experience for users.
295
+
The example below shows what a typical browser-provided UI can be expected to look like,
296
+
and replicating that manually,
297
+
with good accessibility,
298
+
would not be easy.
299
+
300
+
<imgsrc="../images-in-video/media/wa-animated-image.gif"alt="Paused image with a centered overlayed triangular 'play' button, visible whether or not the user hovers. When pressed, the image animation starts, and the button turns into a double-bar 'pause' button, visible while the image is hovered, but disapearing if the cursor is moved away">
301
+
302
+
<dt>Shouldn't this be done in markup instead?
303
+
<dd>
304
+
Arguably that should be possible too.
305
+
In [a different explainer](../images-in-video/README.md),
306
+
we argue that the ability to use animated image formats in the `<video>` element would address a number of use cases.
307
+
Maybe animatable images in `<img>` elements should never have existed,
308
+
but they do,
309
+
and [for a number of reasons they are here to stay](#here-to-stay).
310
+
And as discussed [in the intro](user-needs--use-cases),
311
+
due to preferences and to WCAG reasons,
312
+
users need to be able to chose to turn such animations off
313
+
while keeping the ability to opt into viewing them individually.
314
+
`image-animation: controlled` can be applied to existing markup and user-generated content
315
+
in a way that changing markup cannot.
316
+
317
+
More over, styling can declaratively respond to `@media (prefers-reduced-motion)`,
318
+
while no such solution is available directly on markup.
319
+
320
+
Adding `controls` or `noautoplay` attributes to the `<img>` element
321
+
(along with related APIs)
322
+
[might be worth looking into as well](../images-in-video/README.md#making-img-andor-picture-media-elements),
323
+
but the same observations apply.
324
+
If we were to add both `image-animation: controlled`
325
+
and new markup-level capabilities to the `<img>` element,
0 commit comments