HTML onmouseup Attribute

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

Definition and Usage

The onmouseup attribute is an inline event handler for the mouseup event. It runs when a pointing-device button is released while the pointer is inside the element — the counterpoint to onmousedown.

A full click needs press and release on the same element. MDN also notes that pointerup only fires for the last button release, while mouseup fires for each button release on a physical mouse.

Baseline · Widely available.

Not deprecated and not experimental. Stable across modern browsers since about July 2015.

Accessibility.

Do not make important actions mouse-only. Prefer click (or keyboard-friendly controls) for primary actions so Enter/Space still work.

HTML Syntax

syntax.html
<element onmouseup=" script">

script is JavaScript that runs on release. Pass event to read event.button, event.clientX, and event.clientY. Script alternative: element.addEventListener("mouseup", handler).

Attribute Values

The attribute value is a script. Common patterns:

Value / patternDescriptionTry it
handler()Call a named function when any button is releasedTry it
handler(event)Pass the MouseEvent to read button and coordinatesTry it
With mousedownShow press state, then restore on releaseTry it
addEventListener("mouseup")Preferred modern registration in appsTry it

Live Preview

Press and release a mouse button on the area below. Status updates on mouseup (release), not on press. Right-click may also open the browser menu.

demo

Release left, middle, or right button while the pointer is over the control.

Release area

Last mouseup: (none)

HTML Examples

Short study snippets. Use Try It Yourself for a live editor.

Example 1 — Log Button and Position

Read event.button and coordinates when the release happens.

HTML
<button type="button" onmouseup="logRelease(event)">Release on me</button>
<p id="log">Waiting…</p>

<script>
  function logRelease(e) {
    var names = ["left", "middle", "right"];
    var name = names[e.button] || ("button " + e.button);
    document.getElementById("log").textContent =
      name + " at " + e.clientX + "," + e.clientY;
  }
</script>
Try It Yourself

How It Works

  1. Press anywhere, then release while over the button.
  2. mouseup fires on release — not when the press starts.
  3. Read e.button — 0 left, 1 middle, 2 right.
  4. Read coordinates — clientX / clientY are relative to the viewport.

Example 2 — Press and Release Feedback

Show “Pressed” on mousedown and “Released” on mouseup.

HTML
<button
  type="button"
  id="pad"
  onmousedown="setLabel('Pressed')"
  onmouseup="setLabel('Released')"
  onmouseleave="setLabel('Ready')">
  Ready
</button>

<script>
  function setLabel(text) {
    document.getElementById("pad").textContent = text;
  }
</script>
Try It Yourself

How It Works

  1. mousedown shows “Pressed” as soon as the press starts.
  2. mouseup shows “Released” when the button comes up over the control.
  3. mouseleave resets if the pointer leaves while held (release may fire elsewhere).
  4. For submit-style actions, prefer onclick so drag-away cancels naturally.

Example 3 — mouseup vs click

Log both events so you can feel the difference when you drag off before release.

HTML
<button type="button" id="btn">Press and release</button>
<ul id="log"></ul>

<script>
  var btn = document.getElementById("btn");
  var log = document.getElementById("log");

  function add(line) {
    var li = document.createElement("li");
    li.textContent = line;
    log.appendChild(li);
  }

  btn.addEventListener("mouseup", function () {
    add("mouseup — button up on this element");
  });
  btn.addEventListener("click", function () {
    add("click — press + release on same element");
  });
</script>
Try It Yourself

How It Works

  1. Press and release on the button — both mouseup and click log.
  2. Press on the button, release elsewhere — neither may fire on this button (release lands elsewhere).
  3. Press elsewhere, release on the button — you can get mouseup without click.
  4. Prefer addEventListener in apps so multiple handlers can coexist.

Edge Cases & Pitfalls

Release can land on a different element than the press — that is the main source of bugs.

target

Release target can differ from press

Press on A, drag to B, release — mouseup fires on B. click may not fire on either if the path does not qualify.

a11y

Keyboard users skip mouseup

Enter/Space on a real <button> activates via click, not a mouse sequence. Do not require mouseup for primary actions.

pointer

mouseup ≠ pointerup for multi-button

MDN: physical mice fire mouseup for each button release. pointerup fires only for the last button while others may still be held.

context

Right-click still fires mouseup

Secondary-button release triggers mouseup and may involve the context menu (oncontextmenu).

touch

Touch may synthesize mouse events

Phones often emulate mouse after a tap. For multi-device UIs, consider Pointer Events or dedicated touch handling.

Browser Support

onmouseup is an HTML event handler for the mouseup event in the browser. It is not a Node.js, Deno, or Bun API.

✓ Baseline · Widely available

onmouseup

Widely available since about July 2015. Supported across modern desktop and mobile browsers (with the usual mouse-vs-touch caveats).

98% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet Modern
Full support
Internet Explorer Legacy support
Supported
onmouseup Widely supported

Bottom line: Safe to use for release detection. Prefer click for primary actions; use addEventListener in larger apps.

Key Takeaways

  • Role: run script the moment a pointer button is released over the element.
  • vs click: mouseup is release; click needs press + release on the same element.
  • API: use event.button and coordinates from the MouseEvent.
  • A11y: never make critical features mouse-only.

One line: use onmouseup for the release moment — use onclick for completed activation.

Frequently Asked Questions

It is an inline event handler that runs JavaScript when the mouseup event fires — a pointing-device button is released while the pointer is inside the element.
onmousedown runs when the button is pressed. onmouseup runs when it is released. Press and release can happen on different elements if the pointer moves.
mouseup fires on release over that element. click fires after a press and release that stay on the same element. Prefer click for most button actions.
MDN: with a physical mouse, mouseup fires whenever any button is released. pointerup fires only for the last button release while other buttons may still be held.
On a MouseEvent, button is 0 for the primary (usually left) button, 1 for the auxiliary (usually middle/wheel) button, and 2 for the secondary (usually right) button.
No. The mouseup event is Baseline widely available. Inline handlers are fine for learning; apps often use addEventListener("mouseup", handler).

Next: onmousewheel

Handle legacy mouse-wheel scrolling events.

onmousewheel 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