CSS Image Animation

Editor’s Draft,

More details about this document
This version:
https://drafts.csswg.org/css-image-animation-1/
Previous Versions:
Issue Tracking:
CSSWG Issues Repository
Inline In Spec
Editor:
Florian Rivoal
Suggest an Edit for this Spec:
GitHub Editor

Abstract

This CSS module proposes facilities to control the rendering of animated images.

CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, etc.

Status of this document

This is a public copy of the editors’ draft. It is provided for discussion only and may change at any moment. Its publication here does not imply endorsement of its contents by W3C. Don’t cite this document other than as work in progress.

Please send feedback by filing issues in GitHub (preferred), including the spec code “css-image-animation” in the title, like this: “[css-image-animation] …summary of comment…”. All issues and comments are archived. Alternately, feedback can be sent to the (archived) public mailing list www-style@w3.org.

This document is governed by the 18 August 2025 W3C Process Document.

1. Introduction

This section is non-normative.

Animated images (as enabled by [GIF], [PNG], [WebP]…) are in common use on the web. By default, user agents autoplay these images, which can be jarring for users, especially in use cases where there are multiple images on a single page (e.g. image galleries), and violates WCAG 2.2 §  Success Criterion 2.2.2 Pause, Stop, Hide. Currently, site authors have no control over this.

This leads to a user desire to control such animations. However, due to the diversity of usage, there is a wide range of use cases and desired UIs and user experiences, so making this an automatic or opt-in user agent feature would not be sufficient.

To offer their users the best experience, websites need to control the playback experience, separately for each different uses of animated images.

This specification proposes a CSS property ('image animation') and a pseudo-class (:animated-image) to enable authors to control animations, and to target this control and any UI they wish to associate with it to relevant elements.

For further exploration of the motivations and of the alternatives considered, see also the separately maintained explainer and presentation on this topic.

Nothing in this specification precludes user agents offering users a setting to control image animation globally, such as an option to turn all animated images into static images.

2. Controlling Image Animations: the image-animation property

Name: image-animation
Value: normal | paused | running
Initial: normal
Applies to: content images and elements with decorative images
Inherited: yes
Percentages: n/a
Computed value: as specified
Canonical order: per grammar
Animation type: discrete

This property allows authors to control whether animated images are displayed in their animated state or paused.

Both content images and decorative images are affected by this property. When an element contains several decorative images (e.g. multiple background images or border images), or if it contains both a content image and one or more decorative images, the computed value of the property on that element affects them all.

Note: It is therefore not possible to pause decorative images of an element while letting the animation run on the content image of the same element, nor vice-versa.

In the case of non-animated images, the different values of this property have no effect. This property does not affect videos nor programmatic images either.

normal
The animation of animated images is run normally, as determined by the image format and the host language.

Further, all animated images with the same absolute URL, the same image data, and with an image-animation computed value of normal' must be rendered synchronized to the same timeline as a group, with the timeline starting at the time of the least recent addition to the group.

Note: The above requirement is based on a [HTML] rendering expectation defined in HTML § 15.4.2 Images. As [HTML] does not generally require user agents to present documents in any particular way, and therefore does not normatively require the above behavior. This specification does.

paused
Animated images are rendered as if they were static images: the user agent must not run any animation it contains.
running
Like normal, the animation of animated images is run normally, as determined by the image format and the host language,

However, animation timelines are scoped per element: among the content image and decorative images of a single element, any animated images with the same absolute URL, the same image data, and with an image-animation computed value of running must be rendered synchronized to the same timeline as a group, distinct from the timeline of images in other elements, with the timeline starting at the time of the least recent addition to the group.

An author can use this property to suppress non-essential image animations in response to user preferences expressed by the prefers-reduced-motion media feature. Here, decorative images are made static, while img elements are kept animating.
:root { /* propagates through the document by inheritance */
  image-animation: paused;
}
img {
  image-animation: normal;
}
A given HTML page contains several img elements displaying instances of the same image (same absolute URL and same image data), all styled with image-animation: normal.

One of the elements has its image-animation property temporarily switched to paused, stopping the animation of its image. Other images are unaffected, and their animation continues.

The image-animation property of the paused element is later changed to running. At that point, that image resumes its animation, without regard to how far along their timeline other images are, and is now out of sync.

Later still, the image-animation property of that element is changed to normal. At that point, the image’s animation snaps back to being synchronized with the other instances.

The image-animation property affects not only raster image formats, but also to vector images, including SVG (see [SVG2]). However, this is only the case for distinct SVG resources loaded as content images or decorative images, and does not include svg elements inlined into HTML documents. (However, if set on the svg element, it does inherit, and does affect any animated content image loaded via the SVG image element.)

3. Telling Animated Images Apart: the :animated-image pseudo-class

The :animated-image pseudo-class represents content image elements where a animated image has been loaded. For the animated-image pseudo-class to match, the image must not only be in a format that is capable of animation, but must also be an actually animated image.

On elements which do not represent content images, the animated-image pseudo-class never matches.

This pseudo class can be used for authors to selectively provide some user interface to enable users to play paused images.

In this simplistic example, images that can animate are initially paused, and a filter is applied to them to make them look dull and grayed out. Upon hovering or focusing the image, the filter is removed and the image is allowed to play.

img:animated-image {
  image-animation: paused;
  filter: grayscale(10%) contrast(50%) brightness(80%);
}
img:animated-image:hover,
img:animated-image:focus {
  filter: none;
  image-animation: running;
}
It is important for authors building UI to control the animation of images to take the needs of keyboard users into consideration, and to avoid making the interaction rely solely on mouse interactions.
In the above example, play is triggered not only by hovering the image but also by focusing it. To make this fully functional, it would be necessary to make animatable images focusable. This could be accomplished with something like the following code snippet.
function setImageFocusability(event) {
  var img = event.target;
  if (img.matches(":animated-image") {
    img.tabIndex = 0;
  } else {
    img.removeAttribute("tabindex");
  }
}
document.querySelectorAll("img").forEach( (i) => {
  setImageFocusability({target: i });
  i.addEventListener('load', setImageFocusability);
  i.addEventListener('error', setImageFocusability);
});

Whether :animated-image matches is not affected by the current playing state of the image, nor by the value of the image-animation property. However, if some user agent setting has globally disabled image animations, even images that could otherwise be animated are considered static images, and do not match.

4. Terminology

static image
Images where a single frame is intended to be displayed as the final viewing experience.

A JPEG image is a static image.

animated image
Images where multiple frames are intended to be displayed sequentially as part of the final viewing experience, possibly though not necessarily looping.

An animated PNG image, or an animated [GIF] image are animated images.

Support for progressive rendering or multi-pass loading does not make an image qualify as animated.

content image
An element of the host language representing a static image or an animated image, at the exclusion of videos or programmatic images.

The img [HTML] element, including when it is nested in the picture element; the object [HTML] element, in cases where it represents an image; or the image [SVG2] element represent content images.

decorative image
An image inserted into the document rendering by CSS, through such properties as background-image or border-image.
video

An element of the host language representing a moving picture, typically though not necessarily accompanied by sound, typically though not necessarily presented with interactive controls (for playing, pausing, seeking, controlling the volume, presenting in full screen…), possibly though not necessarily accompanied by captions or subtitles.

Note: From a conceptual point of view, and only based on file formats, videos and animated images have considerable overlap, and cannot not necessarily be distinguished from one another in principle. The distinction here is based on author intent, as expressed through the choice of element in the document.

The video [HTML] element represents a video.

Assuming a user agent which would support both usages, the same video/mp4 file would be considered a video if presented via the video element, or a decorative image if used as a CSS background-image.
programmatic image
An image created programmatically via an API of the host language, as opposed to one loaded from an external resource.

The canvas [HTML] element represents a programmatic image.

Should the video element when it represents its poster frame be treated as a content image, a decorative image, or as (a state of) a video and not an image at all?

5. Accessibility Considerations

This section is non-normative.

6. Privacy Considerations

This section is non-normative.

The image-animation property enables control over image animation cross origin, without leaking any information about whether the image is actually animatable or not. The computed value does not change based on this information. The running value has effects that are visibly different on animated images vs static images, but none of these differences are observable by the page itself.

However, the :animated-image pseudo class does reveal whether a content image is animated or static, which the page could not otherwise know cross-origin. This could be restricted via CORS, but this specification chose not to impose such restriction, for the following reasons:

7. Security Considerations

This section is non-normative.

This specification is not known to introduce any new security issue.

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class="example", like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class="note", like this:

Note, this is an informative note.

Advisements are normative sections styled to evoke special attention and are set apart from other normative text with <strong class="advisement">, like this: UAs MUST provide an accessible alternative.

Tests

Tests relating to the content of this specification may be documented in “Tests” blocks like this one. Any such block is non-normative.


Conformance classes

Conformance to this specification is defined for three conformance classes:

style sheet
A CSS style sheet.
renderer
A UA that interprets the semantics of a style sheet and renders documents that use them.
authoring tool
A UA that writes a style sheet.

A style sheet is conformant to this specification if all of its statements that use syntax defined in this module are valid according to the generic CSS grammar and the individual grammars of each feature defined in this module.

A renderer is conformant to this specification if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the features defined by this specification by parsing them correctly and rendering the document accordingly. However, the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)

An authoring tool is conformant to this specification if it writes style sheets that are syntactically correct according to the generic CSS grammar and the individual grammars of each feature in this module, and meet all other conformance requirements of style sheets as described in this module.

Partial implementations

So that authors can exploit the forward-compatible parsing rules to assign fallback values, CSS renderers must treat as invalid (and ignore as appropriate) any at-rules, properties, property values, keywords, and other syntactic constructs for which they have no usable level of support. In particular, user agents must not selectively ignore unsupported component values and honor supported values in a single multi-value property declaration: if any value is considered invalid (as unsupported values must be), CSS requires that the entire declaration be ignored.

Implementations of Unstable and Proprietary Features

To avoid clashes with future stable CSS features, the CSSWG recommends following best practices for the implementation of unstable features and proprietary extensions to CSS.

Non-experimental implementations

Once a specification reaches the Candidate Recommendation stage, non-experimental implementations are possible, and implementors should release an unprefixed implementation of any CR-level feature they can demonstrate to be correctly implemented according to spec.

To establish and maintain the interoperability of CSS across implementations, the CSS Working Group requests that non-experimental CSS renderers submit an implementation report (and, if necessary, the testcases used for that implementation report) to the W3C before releasing an unprefixed implementation of any CSS features. Testcases submitted to W3C are subject to review and correction by the CSS Working Group.

Further information on submitting testcases and implementation reports can be found from on the CSS Working Group’s website at http://www.w3.org/Style/CSS/Test/. Questions should be directed to the public-css-testsuite@w3.org mailing list.

Index

Terms defined by this specification

Terms defined by reference

References

Normative References

[CSS-CASCADE-5]
Elika Etemad; Miriam Suzanne; Tab Atkins Jr.. CSS Cascading and Inheritance Level 5. URL: https://drafts.csswg.org/css-cascade-5/
[CSS-VALUES-4]
Tab Atkins Jr.; Elika Etemad. CSS Values and Units Module Level 4. URL: https://drafts.csswg.org/css-values-4/
[HTML]
Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/
[RFC2119]
S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119
[SVG2]
Amelia Bellamy-Royds; et al. Scalable Vector Graphics (SVG) 2. URL: https://svgwg.org/svg2-draft/

Informative References

[GIF]
Graphics Interchange Format. 31 July 1990. URL: https://www.w3.org/Graphics/GIF/spec-gif89a.txt
[IMAGE-ANIMATION-EXPLAINER]
Florian Rivoal; Lea Verou. CSS Image Animation Explainer. URL: https://github.com/webplatformco/project-image-animation/blob/main/image-animation-property/README.md
[IMAGE-ANIMATION-TALK]
Lea Verou; Florian Rivoal. We need to be able to control Image Animation on the Web Platform!. URL: https://github.com/webplatformco/project-image-animation/tree/main/image-animation-property
[MEDIAQUERIES-5]
Dean Jackson; et al. Media Queries Level 5. URL: https://drafts.csswg.org/mediaqueries-5/
[PNG]
Chris Lilley; et al. Portable Network Graphics (PNG) Specification (Third Edition). URL: https://w3c.github.io/png/
[WCAG22]
Michael Cooper; et al. Web Content Accessibility Guidelines (WCAG) 2.2. URL: https://w3c.github.io/wcag/guidelines/22/
[WebP]
J. Zern; P. Massimino; J. Alakuijala. WebP Image Format. November 2024. Informational. URL: https://www.rfc-editor.org/rfc/rfc9649

Property Index

Name Value Initial Applies to Inh. %ages Anim­ation type Canonical order Com­puted value
image-animation normal | paused | running normal content images and elements with decorative images yes n/a discrete per grammar as specified

Issues Index

Should the video element when it represents its poster frame be treated as a content image, a decorative image, or as (a state of) a video and not an image at all?