The onabort attribute is a global event handler for the abort event. On <audio> and <video>, that event fires when media loading stops before it finishes — not as a load error.
Typical trigger: clear src (or set it to "") and call load() while a fetch is still in progress. Prefer addEventListener("abort", …) in modern code.
Baseline · Widely available.
The media abort event is stable across modern browsers since about July 2015. Not deprecated.
Inline handlers discouraged.
MDN: HTML event handler attributes are discouraged. Study onabort to recognize it; use addEventListener in new projects.
Syntax
HTML Syntax
syntax.html
<video onabort="script">
script is JavaScript that runs when abort fires. Same idea on <audio>. Preferred: element.addEventListener("abort", handler).
Values
Attribute Values
What you put in the attribute, and how it relates to listening:
Most confusion comes from expecting abort on every element or mixing it up with error.
media
Useful on audio / video
The attribute is global in the HTML list, but browsers fire the media abort event on HTMLMediaElement. Do not expect it on random divs.
timing
May not fire if already loaded
If the resource finished (or never started) before you clear src, you might not see abort. Cache-bust the URL when testing.
bubble
Does not bubble
Listen on the media element itself. Parent listeners will not see a bubbling abort.
style
Prefer listeners
Inline on* attributes mix concerns and are harder to debug. Use addEventListener in production code.
vs error
Failed URL → error
A missing media file triggers error, not abort. Handle both if you show status to users.
Compatibility
Browser Support
onabort is an HTML event handler attribute for the abort event (mainly media). Prefer addEventListener in apps.
✓ Baseline · Widely available
onabort
Media abort is widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support abort on audio/video.
96%Global support (approx.)
Google ChromeAll
Full support
Mozilla FirefoxAll
Full support
Apple SafariAll
Full support
Microsoft EdgeAll
Full support
OperaAll
Full support
Samsung InternetAll
Full support
Internet ExplorerLegacy*
Partial*
abortWidely supported on media
Bottom line: *Safe on modern browsers for media abort. Prefer addEventListener over inline onabort.
Remember
Key Takeaways
Role: handler for media load stopped early (not an error).
Elements: mainly <audio> / <video>.
Prefer:addEventListener("abort", …) over inline attributes.
Not onerror: failed loads use the error event.
One line:onabort reacts when media loading is canceled mid-way — listen with abort, not error.
Frequently Asked Questions
It is an inline event handler for the abort event. On media elements, abort fires when resource loading stops before it finishes, but not because of a load error — for example when script clears src and calls load().
Browsers fire the media abort event on audio and video (HTMLMediaElement). The onabort attribute is listed as a global event handler, but it is mainly useful on those media elements.
abort means loading was stopped early without treating it as a failure. onerror means the resource failed to load (bad URL, network error, unsupported format).
Prefer element.addEventListener("abort", handler). MDN discourages inline HTML event handler attributes because they mix markup and script and are harder to maintain.
No. The media abort event is not cancelable and does not bubble.
Start loading a video or audio src, then quickly remove the src attribute (or set it to "") and call load(). If loading was still in progress, abort fires.