HTML onpause Attribute

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The onpause attribute is an event-handler attribute for <audio> and <video>. It runs JavaScript when the pause event fires — playback has entered the paused state (usually after pause() or the user presses Pause in controls).

The event fires once pause() returns and after the media element’s paused property is true. It is not cancelable and does not bubble. Pair it with onplay to keep custom UI in sync.

Baseline · Widely available.

Not deprecated and not experimental. The pause event is stable across modern browsers since about July 2015.

Prefer addEventListener in apps.

Inline onpause is fine for learning. Production code usually uses media.addEventListener("pause", handler). Pausing because of buffering uses waiting, not pause.

HTML Syntax

syntax.html
<video|audio onpause=" script">

script is JavaScript that runs when pause fires. Equivalent JS: media.onpause = handler or media.addEventListener("pause", handler).

Attribute Values

The attribute value is always a script. Common patterns:

Value / patternDescriptionTry it
scriptAny JavaScript run when media becomes pausedTry it
onpause="fn()"Call a named function from the attributeTry it
addEventListener("pause")Preferred modern listener on audio/videoTry it
With onplayUpdate status for both play and pauseTry it
+ controlsUser Pause button in the media UI triggers pauseTry it

Live Preview

Press play, then pause. Status updates when pause (and play) fire.

Media

Sample /video/count.mp4 or /audio/count.mp3. Use controls or the Pause button.

Player

Waiting — press play, then pause

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Inline onpause on Video

Update status when the user pauses the clip.

HTML
<video width="400" height="225" controls onpause="onPaused()">
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="status">Waiting for pause…</p>

<script>
  function onPaused() {
    document.getElementById("status").textContent = "pause fired — media is paused.";
  }
</script>
Try It Yourself

How It Works

  1. Put onpause on the media element — here <video>.
  2. User plays, then pauses via controls (or script calls pause()).
  3. paused becomes true and the pause event fires.
  4. Handler updates UI — status text, icons, analytics, and so on.

Example 2 — addEventListener on Audio

Preferred script pattern on an audio element.

HTML
<audio id="clip" controls>
  <source src="/audio/count.mp3" type="audio/mpeg">
</audio>
<p id="log">Idle</p>

<script>
  document.getElementById("clip").addEventListener("pause", function () {
    document.getElementById("log").textContent =
      "pause event: paused = " + this.paused;
  });
</script>
Try It Yourself

How It Works

  1. Select the audio with getElementById.
  2. Register pause with addEventListener.
  3. When paused, read this.paused (should be true).
  4. Update the log for the student to see.

Example 3 — onplay vs onpause

Keep a simple status line for both start and pause.

HTML
<video id="clip" width="400" height="225" controls>
  <source src="/video/count.mp4" type="video/mp4">
</video>
<p id="state">State: paused</p>

<script>
  var clip = document.getElementById("clip");
  var state = document.getElementById("state");

  clip.addEventListener("play", function () {
    state.textContent = "State: playing";
  });
  clip.addEventListener("pause", function () {
    state.textContent = "State: paused";
  });
</script>
Try It Yourself

How It Works

  1. play — playback requested; update to “playing”.
  2. pause — media paused; update to “paused”.
  3. Same player, two events — cleaner than polling paused.
  4. Ending the media often pauses too — also see onended.

Edge Cases & Pitfalls

Most mistakes are confusing buffering stalls with pause, or expecting the event to bubble.

vs waiting

Buffering is not pause

When playback stops for data, you get waiting. pause means the element entered the paused state (user or pause()).

bubble

Does not bubble

Listen on the audio/video element itself. Parent listeners will not see a bubbling pause.

ended

End of media

Reaching the end can also leave the media paused. Use onended when you care specifically about completion.

already

Calling pause() when already paused

If paused is already true, another pause() typically does not fire pause again.

property

.onpause = replaces listeners

Assigning the IDL property overwrites a previous assignment. Prefer addEventListener for multiple handlers.

Browser Support

onpause 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

onpause

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the pause event on audio and video.

97% Global support (approx.)
Google Chrome 3+
Full support
Mozilla Firefox 3.5+
Full support
Apple Safari 3.1+
Full support
Microsoft Edge 12+
Full support
Opera 10.5+
Full support
Samsung Internet Modern · Full
Full support
Internet Explorer 9+
Supported
onpause Widely supported

Bottom line: Safe to use for media UI sync. Prefer addEventListener in production, and use waiting/ended for buffering and completion.

Key Takeaways

  • Role: run script when audio/video enters the paused state.
  • Trigger: user Pause or pause() — then paused === true.
  • Pair with: onplay (and often onended).
  • Not buffering: use waiting for stalls, not pause.

One line: onpause means the media is paused — sync your UI, and don’t confuse it with buffering.

Frequently Asked Questions

It is an event-handler attribute on audio or video. When playback enters the paused state — usually after pause() or the user presses Pause — the pause event fires and the JavaScript in onpause runs.
The HTML audio and video elements. Put the handler on the media element itself.
After the pause request is handled and the media element’s paused property is true — typically once pause() returns. The event is not cancelable and does not bubble.
onplay runs when playback is requested to start (paused becomes false). onpause runs when playback is paused (paused becomes true). Pair them to keep UI in sync.
Both work. For learning, onpause in HTML is fine. In production code, prefer media.addEventListener("pause", handler).
No. The pause event and onpause handler are standard HTML media features and Baseline widely available since about July 2015.

Next: onplay

Run JavaScript when media playback is requested to start.

onplay tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful