HTML onmousewheel Attribute

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

Definition and Usage

The onmousewheel attribute is an inline handler for the obsolete mousewheel event. It fires while a mouse wheel or similar device is operated over the element.

MDN: it was never part of any standard, and Firefox never implemented it. Use the standard onwheel attribute (or addEventListener("wheel", …)) for new work. Related scroll position changes use onscroll.

Deprecated.

Avoid in new projects. Prefer the standard wheel event via onwheel.

Non-standard.

Not standardized. Limited and inconsistent support — unsuitable for production.

HTML Syntax

syntax.html
<element onmousewheel=" script">

Legacy only. Prefer: <element onwheel="script"> or element.addEventListener("wheel", handler).

Attribute Values

The attribute value is a script. Patterns you may see in old pages:

Value / patternDescriptionTry it
handler(event)Legacy: read wheelDelta (sign/units vary by browser)Try it
UI tweakOld demos change size/zoom from the wheelTry it
onwheel (modern)Standard replacement — use this in new codeTry it
addEventListener("wheel")Preferred modern registrationTry it

Live Preview

Focus the pad and scroll the mouse wheel (or trackpad). Compare legacy mousewheel with standard wheel. In Firefox, only wheel is expected to fire.

demo

Scroll over the pad. Prefer the wheel mode for real projects.

Wheel area
Scroll here

Last event: (none)

HTML Examples

Short study snippets for reading old code. New projects should use onwheel.

Example 1 — Log Legacy wheelDelta

See what old pages read from mousewheel (may not fire in Firefox).

HTML
<div id="pad" onmousewheel="logWheel(event)">
  Scroll over me
</div>
<p id="log">Waiting…</p>

<script>
  function logWheel(e) {
    document.getElementById("log").textContent =
      "wheelDelta: " + e.wheelDelta;
  }
</script>
Try It Yourself

How It Works

  1. Scroll over the pad — browsers that support it fire mousewheel.
  2. Read wheelDelta — often positive when scrolling away from the user.
  3. Units differ by browser/OS — do not hard-code magic numbers.
  4. Firefox — expect no event; use wheel instead.

Example 2 — Change Text Size (Legacy Pattern)

A classic demo: grow/shrink text from the wheel. Study only — migrate to wheel.

HTML
<p id="label" onmousewheel="resizeLabel(event)" style="font-size:16px">
  Scroll to resize
</p>

<script>
  function resizeLabel(e) {
    e.preventDefault();
    var el = document.getElementById("label");
    var size = parseFloat(el.style.fontSize) || 16;
    if (e.wheelDelta > 0) size += 2;
    else size -= 2;
    if (size < 10) size = 10;
    if (size > 48) size = 48;
    el.style.fontSize = size + "px";
  }
</script>
Try It Yourself

How It Works

  1. Wheel over the text — handler runs on each notch/tick (where supported).
  2. preventDefault() — stops the page from scrolling while resizing.
  3. Sign of wheelDelta — grows or shrinks the font within limits.
  4. Accessibility note — do not make essential zoom wheel-only; offer buttons too.

Example 3 — Prefer Standard onwheel

Same idea with the modern event: use deltaY instead of wheelDelta.

HTML
<div id="pad">Scroll over me (wheel)</div>
<p id="log">Waiting…</p>

<script>
  document.getElementById("pad").addEventListener("wheel", function (e) {
    document.getElementById("log").textContent =
      "deltaY: " + e.deltaY + " · deltaX: " + e.deltaX;
  }, { passive: true });
</script>
Try It Yourself

How It Works

  1. Listen for wheel — the standard replacement for mousewheel.
  2. Read deltaY / deltaX — positive deltaY usually means scrolling down.
  3. Works in Firefox — and other modern browsers.
  4. HTML form: onwheel="…" on the element.

Edge Cases & Pitfalls

Most problems come from treating mousewheel as a standard, portable API.

firefox

No mousewheel in Firefox

MDN: Firefox never implemented it. Any feature that depends only on onmousewheel is broken there.

units

wheelDelta is inconsistent

Chrome, Safari, and older engines disagree on magnitude and acceleration. Prefer deltaY on wheel.

sign

Sign differs from wheel

Legacy wheelDelta sign convention is not the same as DOM Level 3 wheel deltas. Do not mix formulas blindly.

a11y

Wheel-only controls exclude many users

Offer buttons or keyboard controls for zoom/size changes. Touch devices often have no physical wheel.

scroll

Wheel ≠ scroll

wheel/mousewheel report device movement. scroll reports position change. Listen for the one that matches your goal.

Browser Support

onmousewheel is a deprecated, non-standard HTML event handler. Prefer onwheel for new work.

✓ Deprecated · Non-standard

onmousewheel

Never standardized. Supported historically in Chromium/WebKit-family browsers for legacy pages. Not implemented in Firefox. Use the standard wheel event instead.

0% Recommended for new work
Google Chrome Legacy support
Legacy only
Mozilla Firefox Not implemented
No support
Apple Safari Legacy support
Legacy only
Microsoft Edge Legacy support
Legacy only
Opera Legacy support
Legacy only
Samsung Internet Legacy (Chromium)
Legacy only
Internet Explorer Legacy support
Supported
onmousewheel Deprecated — use onwheel

Bottom line: Do not use onmousewheel in new pages. Teach it only to read old code — ship onwheel / addEventListener("wheel").

Key Takeaways

  • Status: deprecated and non-standard — not for new projects.
  • Replace with: onwheel / addEventListener("wheel").
  • Firefox: never had mousewheel — use wheel.
  • A11y: do not make critical UI wheel-only.

One line: recognize onmousewheel in old pages — ship onwheel in new ones.

Frequently Asked Questions

It is an inline handler for the obsolete, non-standard mousewheel event, fired while a mouse wheel or similar device is operated over the element. MDN recommends the standard wheel event (onwheel) instead.
Yes. MDN marks mousewheel as Deprecated and Non-standard. It was never in a web standard and was never implemented by Firefox.
Use the standard onwheel attribute or element.addEventListener("wheel", handler). Read deltaY / deltaX on the WheelEvent.
No. Firefox never implemented mousewheel. Use wheel, which Firefox supports.
A legacy property on mousewheel events. Positive often means scrolled away from the user. Values differ by browser and OS — another reason to prefer the standard wheel event’s deltaY.
mousewheel / wheel report wheel-device movement. scroll fires when an element’s scroll position actually changes. You can wheel without scrolling, and scroll without a wheel.

Better path: onwheel

Learn the standard wheel event for portable, modern pages.

onwheel 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