The onplay attribute is an event-handler attribute for <audio> and <video>. It runs JavaScript when the play event fires — the media element’s paused property changed from true to false (usually after play(), the Play control, or autoplay).
The event is not cancelable and does not bubble. Pair it with onpause for UI sync. For “actually playing after a stall,” see onplaying.
Baseline · Widely available.
Not deprecated and not experimental. The play event is stable across modern browsers since about July 2015.
Prefer addEventListener in apps.
Inline onplay is fine for learning. Production code usually uses media.addEventListener("play", handler). Autoplay without a user gesture is often blocked unless the media is muted.
Syntax
HTML Syntax
syntax.html
<video|audio onplay="script">
script is JavaScript that runs when play fires. Equivalent JS: media.onplay = handler or media.addEventListener("play", handler).
Values
Attribute Values
The attribute value is always a script. Common patterns:
Most confusion is play vs playing, or assuming autoplay always succeeds.
vs playing
play ≠ playing
play means paused became false. playing means playback is ready after a pause or buffering delay.
autoplay
Autoplay may be blocked
Browsers often block audible autoplay. Use muted with autoplay, or wait for a user gesture before play().
promise
play() returns a Promise
Handle rejection (policy / load errors). The play event fires only if playback actually leaves the paused state.
bubble
Does not bubble
Listen on the audio/video element itself. Parent listeners will not see a bubbling play.
property
.onplay = replaces listeners
Assigning the IDL property overwrites a previous assignment. Prefer addEventListener for multiple handlers.
Compatibility
Browser Support
onplay is an HTML event-handler attribute for media elements in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
onplay
Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the play event on audio and video.
97%Global support (approx.)
Google Chrome3+
Full support
Mozilla Firefox3.5+
Full support
Apple Safari3.1+
Full support
Microsoft Edge12+
Full support
Opera10.5+
Full support
Samsung InternetModern · Full
Full support
Internet Explorer9+
Supported
onplayWidely supported
Bottom line: Safe to use for media UI sync. Prefer addEventListener in production, and remember autoplay policies when starting playback without a click.
Remember
Key Takeaways
Role: run script when media leaves the paused state.
Trigger: Play control, play(), or successful autoplay.
Pair with:onpause; use onplaying for post-stall readiness.
Autoplay: often needs muted or a user gesture.
One line:onplay means “no longer paused” — sync UI, and use onplaying when you care about actual playback readiness.
Frequently Asked Questions
It is an event-handler attribute on audio or video. When the paused property changes from true to false — usually after play() or autoplay — the play event fires and the JavaScript in onplay runs.
The HTML audio and video elements. Put the handler on the media element itself.
onplay means playback was requested and paused became false. onplaying means playback is actually ready to proceed after being paused or delayed for data. They are related but not identical.
onplay runs when playback starts (paused becomes false). onpause runs when playback is paused (paused becomes true). Pair them to keep UI in sync.
Both work. For learning, onplay in HTML is fine. In production code, prefer media.addEventListener("play", handler).
No. The play event and onplay handler are standard HTML media features and Baseline widely available since about July 2015.