Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

@starting-style — transition starting style

The @starting-style rule supplies a before-change style for an element that had no previously rendered style.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

@starting-style { <rule-list> }

@starting-style supplies starting values only for starting a transition when the previous style-change event provided no before-change style. A newly inserted element or one returning from display: none is the common case. The normal rule still defines the after-change state opacity: 1, while the block can provide opacity: 0.

The example inserts two new elements with a transition at the same time. Only the covered element receives a transition animation; a CSSStartingStyleRule remains in CSSOM, and pausing halfway yields computed opacity 0.5. The control element without the rule creates no animation.

This is neither a keyframe nor a property initial value. Its declarations participate in the normal cascade and must lose to the after-change style for a change to occur. Reinsertion within the same style-change event, or a property without a matching transition, might not start the effect.

Examples

const style=document.createElement('style');
style.textContent='.probe { opacity: 1; transition: opacity 1000ms linear; } @starting-style { .with-start { opacity: 0; } }';
document.head.append(style);
const withStart=document.createElement('div'); withStart.className='probe with-start'; withStart.textContent='with';
const control=document.createElement('div'); control.className='probe'; control.textContent='control';
document.body.append(withStart,control);
await new Promise(requestAnimationFrame);
const animation=withStart.getAnimations()[0];
if(!animation) throw new Error('starting-style transition did not start');
animation.pause(); await animation.ready; animation.currentTime=500;
const rule=style.sheet.cssRules[1];
console.log('rule='+rule.constructor.name+'; animations='+withStart.getAnimations().length+'/'+control.getAnimations().length+'; midpoint='+getComputedStyle(withStart).opacity);

Result

rule=CSSStartingStyleRule; animations=1/0; midpoint=0.5

The @starting-style rule supplies a before-change style for an element that had no previously rendered style.

Sources