CKTIS / HTML
onplaying — handling readiness to play
The onplaying attribute contains code that handles the playing event, used by audio and video when playback is ready to start or resume after an interruption. It does not start playback and is not equivalent to onplay.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
onplaying="JavaScript statements"
media.onplaying = (event) => { /* handler */ };onplaying is an event handler attribute for playing. It is available as an HTML attribute on all HTML elements, but its typical use concerns audio and video elements. Its value is JavaScript code, not a file address or a Boolean value.
The playing event indicates readiness to start playback after a pause or a delay caused by insufficient data. In contrast, play signals that paused changed to false. playing can occur again after buffering; it guarantees neither uninterrupted playback nor audible sound.
In JavaScript, you can assign a function to media.onplaying; another assignment replaces the previous function for that handler. An alternative is media.addEventListener('playing', handler). Setting up a handler does not itself start playback.
The example dispatches a synthetic playing event to test the attribute without a media file. The expected text is playing. This does not test actual playback; it requires scripting to be enabled and inline event handlers to be permitted.
Examples
<!doctype html>
<meta charset="utf-8">
<title>onplaying test</title>
<audio id="media" onplaying="document.getElementById('result').textContent = event.type"></audio>
<output id="result">pending</output>
<script>
const media = document.getElementById('media');
media.dispatchEvent(new Event('playing'));
</script>Result
playing
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.