Element: contentvisibilityautostatechange event

Baseline 2024
Newly available

Since September 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The contentvisibilityautostatechange event fires on any element with content-visibility: auto set on it when it starts or stops being relevant to the user and skipping its contents.

While the element is not relevant (between the start and end events), the user agent skips an element's rendering, including layout and painting, which can significantly improve page rendering speed. The contentvisibilityautostatechange event provides a way for an app's code to also start or stop rendering processes (e.g., drawing on a <canvas>) when they are not needed, thereby conserving processing power.

Note that even when hidden from view, element contents will remain semantically relevant (e.g., to assistive technology users), so this signal should not be used to skip significant semantic DOM updates.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("contentvisibilityautostatechange", (event) => { })

oncontentvisibilityautostatechange = (event) => { }

Event type

A ContentVisibilityAutoStateChangeEvent.

Examples

js
const canvasElem = document.querySelector("canvas");

canvasElem.addEventListener("contentvisibilityautostatechange", stateChanged);
canvasElem.style.contentVisibility = "auto";

function stateChanged(event) {
  if (event.skipped) {
    stopCanvasUpdates(canvasElem);
  } else {
    startCanvasUpdates(canvasElem);
  }
}

// Call this when the canvas updates need to start.
function startCanvasUpdates(canvas) {
  // …
}

// Call this when the canvas updates need to stop.
function stopCanvasUpdates(canvas) {
  // …
}

Specifications

Specification
CSS Containment Module Level 2
# content-visibility-auto-state-change

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
contentvisibilityautostatechange event
Chrome – Full support
Chrome 108 (Release date: 2022-11-29)
footnote Full support
Edge – Full support
Edge 108 (Release date: 2022-12-05)
footnote Full support
Firefox – Partial support
Firefox 124 – 129 (Release date: 2024-03-19)
footnote Partial support
footnote The oncontentvisibilityautostatechange event handler property is not supported.
Firefox – Full support
Firefox 130 (Release date: 2024-09-03)
footnote Full support
Opera – Full support
Opera 94 (Release date: 2022-12-15)
footnote Full support
Safari – Full support
Safari 18 (Release date: 2024-09-16)
footnote Full support
Chrome Android – Full support
Chrome Android 108 (Release date: 2022-11-29)
footnote Full support
Firefox for Android – Partial support
Firefox for Android 124 – 129 (Release date: 2024-03-19)
footnote Partial support
footnote The oncontentvisibilityautostatechange event handler property is not supported.
Firefox for Android – Full support
Firefox for Android 130 (Release date: 2024-09-03)
footnote Full support
Opera Android – Full support
Opera Android 73 (Release date: 2023-01-17)
footnote Full support
Safari on iOS – Full support
Safari on iOS 18 (Release date: 2024-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 21 (Release date: 2023-05-19)
footnote Full support
WebView Android – Full support
WebView Android 108 (Release date: 2022-11-29)
footnote Full support
WebView on iOS – Full support
WebView on iOS 18 (Release date: 2024-09-16)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Has more compatibility info.

See also