CKTIS / CSS
will-change — anticipating rendering changes
The `will-change` property warns the browser about upcoming changes. It neither starts animations nor guarantees faster rendering.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
will-change: auto | <animateable-feature>#;
<animateable-feature> = scroll-position | contents | <custom-ident>will-change is a rendering hint. Its initial auto leaves normal optimizations in place. The property is neither inherited nor animatable.
A comma-separated list accepts scroll-position (scrolling), contents (content), or property names such as transform, opacity. An unrecognized name is ignored without affecting the other list items only if it is a valid identifier for will-change. Naming a custom property also has no effect. none is not a permitted identifier here, so the entire declaration will-change: opacity, none is invalid and does not set even the opacity hint.
Use sparingly, ahead of time; restore auto afterward. Overuse can consume resources. A GPU layer is not guaranteed.
The hint can change layering: will-change: opacity creates a stacking context even with opacity: 1. Where the named property requires them, containing blocks for absolutely or fixed-positioned elements are also created.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>will-change</title>
<style>
#tile { padding: 1rem; background: navy; color: white; }
</style>
<button id="prepare" type="button">1. Prepare</button>
<button id="change" type="button">2. Change</button>
<button id="reset" type="button">Reset</button>
<p id="tile">will-change</p>
<pre id="status"></pre>
<script>
const tile = document.querySelector('#tile');
const status = document.querySelector('#status');
function report() {
const style = getComputedStyle(tile);
status.textContent = `${style.willChange} | ${style.opacity}`;
}
document.querySelector('#prepare').addEventListener('click', () => {
tile.style.willChange = 'opacity';
report();
});
document.querySelector('#change').addEventListener('click', () => {
tile.style.opacity = '0.5';
tile.style.willChange = 'auto';
report();
});
document.querySelector('#reset').addEventListener('click', () => {
tile.style.opacity = '1';
tile.style.willChange = 'auto';
report();
});
report();
</script>
</html>Result
Initial: auto | 1 After Prepare: opacity | 1 After Change: auto | 0.5 After Reset: auto | 1
Clicking `Prepare` sets the `opacity` hint but leaves opacity at `1`. Clicking `Change` sets opacity to `0.5` and restores `will-change: auto`.