HTML onratechange Attribute

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

Definition and Usage

The onratechange attribute handles the media ratechange event. It fires when the playback rate (speed) of a <video> or <audio> element changes.

Change speed with media.playbackRate (e.g. 1.5 for 1.5×). Related media handlers: onplay, onpause, onvolumechange. Prefer addEventListener("ratechange", …).

Baseline · Widely available.

Stable across modern browsers since about July 2015. Not deprecated. Not cancelable; does not bubble.

Inline handlers discouraged.

MDN: prefer addEventListener over inline on* attributes. Study onratechange to recognize it in markup.

HTML Syntax

syntax.html
<video onratechange=" script">

script runs when playbackRate changes. Same idea on <audio>. Preferred: element.addEventListener("ratechange", handler).

Attribute Values

How you listen for ratechange:

Value / formDescriptionTry it
JavaScript on mediaInline handler, e.g. showSpeed()Try it
addEventListener("ratechange")Preferred listener; read playbackRateTry it
Speed control UIButtons that set 0.5× / 1× / 2×Try it

Live Preview

Load the clip, then change speed. Status shows playbackRate when ratechange fires.

speed

Uses /video/count.mp4. Click a speed chip after the video has a source.

Demo

Rate: 1

HTML Examples

Short study snippets. Use Try It Yourself for a live editor. Prefer listeners in real apps.

Example 1 — Inline onratechange on video

Recognize the attribute form. Changing playbackRate updates status.

HTML
<video
  id="clip"
  width="280"
  controls
  src="/video/count.mp4"
  onratechange="document.getElementById('status').textContent = 'Rate: ' + this.playbackRate"
></video>
<p id="status">Rate: 1</p>
<button type="button" onclick="document.getElementById('clip').playbackRate = 2">2×</button>
<button type="button" onclick="document.getElementById('clip').playbackRate = 1">1×</button>
Try It Yourself

How It Works

  1. onratechange registers an inline media handler.
  2. Buttons set playbackRate to 2 or 1.
  3. ratechange fires when that property changes.
  4. Status reads this.playbackRate.

Example 2 — Preferred addEventListener

Same event with a clean script listener.

HTML
<video id="clip" width="280" controls src="/video/count.mp4"></video>
<p id="status">Rate: 1</p>
<button type="button" id="fast">1.5×</button>
<button type="button" id="normal">1×</button>

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

  video.addEventListener("ratechange", function () {
    status.textContent = "Rate: " + video.playbackRate;
  });

  document.getElementById("fast").addEventListener("click", function () {
    video.playbackRate = 1.5;
  });

  document.getElementById("normal").addEventListener("click", function () {
    video.playbackRate = 1;
  });
</script>
Try It Yourself

How It Works

  1. No attribute — the listener is attached in script.
  2. Setting playbackRate triggers ratechange.
  3. Handler updates the label from video.playbackRate.
  4. Easier to maintain than inline handlers.

Example 3 — Simple speed control UI

Offer 0.5×, 1×, and 2× and keep a label in sync.

HTML
<video id="clip" width="280" controls src="/video/count.mp4"></video>
<p id="status" aria-live="polite">Speed: 1×</p>
<button type="button" data-rate="0.5">0.5×</button>
<button type="button" data-rate="1">1×</button>
<button type="button" data-rate="2">2×</button>

<script>
  var video = document.getElementById("clip");
  var status = document.getElementById("status");
  var buttons = document.querySelectorAll("[data-rate]");

  video.addEventListener("ratechange", function () {
    status.textContent = "Speed: " + video.playbackRate + "×";
  });

  for (var i = 0; i < buttons.length; i++) {
    buttons[i].addEventListener("click", function () {
      video.playbackRate = Number(this.getAttribute("data-rate"));
    });
  }
</script>
Try It Yourself

How It Works

  1. data-rate stores the target speed on each button.
  2. Click assigns playbackRate.
  3. ratechange keeps the visible label honest.
  4. aria-live announces the new speed to assistive tech.

Edge Cases & Pitfalls

Most issues come from listening in the wrong place or expecting pitch control.

target

Listen on the media element

ratechange does not bubble. Put the handler on <video> / <audio>, not a parent wrapper.

value

Use playbackRate

The event itself has no rate field. Read media.playbackRate inside the handler.

limits

Browser clamps extreme rates

Very high or negative rates may be clamped or ignored. Stick to common values like 0.5–2 for demos.

pitch

Pitch may change with speed

Default playback often raises pitch when speeding up. Preserving pitch needs extra APIs beyond this attribute.

style

Prefer listeners

Inline on* attributes mix concerns. Use addEventListener in production code.

Browser Support

onratechange is a media event handler for playbackRate changes on video/audio. Prefer addEventListener in apps.

✓ Baseline · Widely available

onratechange

Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support the media ratechange event.

97% Global support (approx.)
Google Chrome All
Full support
Mozilla Firefox All
Full support
Apple Safari All
Full support
Microsoft Edge All
Full support
Opera All
Full support
Samsung Internet All
Full support
Internet Explorer 9+
Supported*
ratechange Widely supported

Bottom line: *Safe on modern browsers. Read playbackRate in the handler; listen on the media element.

Key Takeaways

  • Role: run script when media playback speed changes.
  • Set speed with: media.playbackRate.
  • Target: <video> / <audio> (no bubbling).
  • Prefer: addEventListener("ratechange", …).

One line: onratechange fires when playbackRate changes — listen on the media element and update your speed UI from that property.

Frequently Asked Questions

It is an event handler for the ratechange event on media elements. That event fires when the playback rate (speed) of a video or audio element changes.
Set media.playbackRate. For example, video.playbackRate = 1.5 plays at 1.5× speed. A rate of 1 is normal speed; 0.5 is half speed; 2 is double speed.
On HTMLMediaElement targets such as <video> and <audio>. Prefer element.addEventListener("ratechange", handler) in modern code.
No. It is not cancelable and does not bubble. Listen on the media element itself.
Prefer addEventListener("ratechange", handler). MDN discourages inline HTML event handler attributes.
Common uses: show the current speed in the UI, sync a custom speed control, or log when users change playback speed.

Next: onreset

Handle when a form is reset to its default values.

onreset 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