event
Pagereveal — CSS reference
Incoming document receives pagereveal before its first rendering opportunity. The viewTransition property can be null for an ineligible navigation. The paired HTTP demo listens to both events.
Formal Syntax & Structure
css syntaxcss
window.addEventListener("pagereveal", event => { /* inspect event.viewTransition */ });Working Example
Example Snippetcss
<!doctype html><html lang="en"><meta charset="utf-8"><title>pagereveal</title><style>body{margin:12px;font:16px system-ui}#card{width:120px;padding:12px;background:#e2e8f0;color:#172033;view-transition-name:card}#card.changed{width:220px;background:#bfdbfe}::view-transition-group(*){animation-duration:.5s}@media(prefers-reduced-motion:reduce){::view-transition-group(*),::view-transition-old(*),::view-transition-new(*){animation-duration:0s!important}}
</style><body><button id="run" type="button">Change card</button><p id="card">Old state</p><output id="status" aria-live="polite"></output><script>const card=document.getElementById('card');const root=document.documentElement;const feedback=document.getElementById('status');function update(){card.classList.toggle('changed');card.textContent=card.classList.contains('changed')?'New state':'Old state';}function start(types){if(!document.startViewTransition||matchMedia('(prefers-reduced-motion: reduce)').matches){update();return null;}return types?document.startViewTransition({update,types}):document.startViewTransition(update);}async function inspect(check,types){const t=start(types);if(!t)return false;try{await t.ready;return await check(t);}finally{t.skipTransition();await t.finished;}}const ps=(name,prop)=>getComputedStyle(root,name).getPropertyValue(prop);run.onclick=async()=>{const t=start();if(t){try{await t.finished;}catch(e){feedback.textContent='Update failed';return;}}feedback.textContent='Updated';};</script></body></html>