Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / HTML

onpause — media pause event handler

The onpause attribute contains JavaScript that handles the pause event, usually on an audio or video element. It reacts to playback being paused but does not itself pause playback.

Version: WHATWG HTML Living Standard; index snapshot date recorded separately

Syntax

<audio onpause="handlerCode"></audio>
<video onpause="handlerCode"></video>
media.onpause = handler;
media.addEventListener("pause", handler);

onpause is a global event handler attribute for pause. Although available on all HTML elements, its typical use is handling pauses on audio and video elements. Its value is JavaScript code, not a Boolean value.

During normal media pausing, paused becomes true, and the event is dispatched in a queued task. Calling pause() on an already paused element does not produce another pause event. The event does not bubble and cannot be canceled; return false will not prevent pausing.

Inside attribute code, event represents the event and this refers to the element. The JavaScript property media.onpause accepts a function or null; assigning it again replaces the previous function. media.addEventListener("pause", handler) lets you register independent handlers. A CSP policy can block attribute code.

The example dispatches a synthetic pause event to check attribute wiring without a media file. The expected text is pause. This test neither starts nor pauses playback and does not check a real media state transition.

Examples

<!doctype html>
<meta charset="utf-8">
<title>onpause test</title>
<audio id="media" onpause="document.getElementById('result').textContent = event.type"></audio>
<output id="result">pending</output>
<script>
  const media = document.getElementById('media');
  media.dispatchEvent(new Event('pause'));
</script>

Result

pause

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources