The onmouseout attribute is an inline event handler for the mouseout event. It runs when a pointing device moves so the cursor is no longer contained within the element or one of its children.
Pair it with onmouseover for enter/leave pairs. MDN notes that mouseleave is often clearer for “left this whole box,” because mouseout also fires when moving onto a child.
Baseline · Widely available.
Not deprecated and not experimental. Stable across modern browsers since about July 2015.
Child boundaries fire mouseout.
Moving from a parent into a child counts as leaving the parent for mouseout. Prefer mouseleave when that surprise is unwanted.
Syntax
HTML Syntax
syntax.html
<element onmouseout="script">
script is JavaScript that runs on leave. Pass event to read event.target and event.relatedTarget. Script alternative: element.addEventListener("mouseout", handler).
Move into and out of the pad. Try the nested mode: moving onto the inner box fires mouseout on the outer pad even though you are still “inside” the outer visually.
demo
Leave the pad (or enter the inner box in nested mode) to see mouseout.
Hover area
Outer pad — move out
Status: waiting…
Code
HTML Examples
Short study snippets. Use Try It Yourself for a live editor.
Example 1 — Update Status When Leaving
Show a message when the pointer leaves a simple pad.
HTML
<div
id="pad"
onmouseover="setStatus('Inside')"
onmouseout="setStatus('Left')">
Hover, then leave
</div>
<p id="status">Waiting…</p>
<script>
function setStatus(text) {
document.getElementById("status").textContent = text;
}
</script>
No children here — so leave means truly outside the box.
Use for reset UI — hide a tip, clear a highlight, stop a hover preview.
Example 2 — Where Did the Pointer Go?
Read relatedTarget on leave to see the next element (if any).
HTML
<div id="pad">Leave this pad</div>
<p id="log">Waiting…</p>
<script>
document.getElementById("pad").addEventListener("mouseout", function (e) {
var next = e.relatedTarget;
document.getElementById("log").textContent =
"Left pad → went to: " + (next ? (next.id || next.tagName) : "null");
});
</script>
Enter outer, then move onto Inner. The child covers the parent.
mouseout fires because the pointer left the parent’s own area.
This is why hover menus flicker if they hide on mouseout while moving toward a child.
Fix: use mouseleave for whole-group leave, or ignore events when relatedTarget is still inside the parent.
Edge Cases & Pitfalls
Most bugs come from treating mouseout like “left the whole component.”
children
Entering a child counts as leaving the parent
MDN: mouseout fires when the cursor enters a child that obscures the parent. Prefer mouseleave for whole-box leave.
bubbling
mouseout bubbles
A leave from a nested element can bubble to ancestors. Check event.target if you only want the outer element.
a11y
Hover-only UI excludes keyboard users
Do not hide essential content only on mouse leave. Provide focus/click alternatives for the same information.
touch
Touch has no lasting hover
Phones may not deliver reliable mouseout after a tap. Do not rely on hover leave for critical mobile UX.
pair
Match with mouseover carefully
Enter/leave pairs using mouseover/mouseout both see child boundary noise. Enter/leave pairs using mouseenter/mouseleave usually do not.
Compatibility
Browser Support
onmouseout is an HTML event handler for the mouseout event in the browser. It is not a Node.js, Deno, or Bun API.
✓ Baseline · Widely available
onmouseout
Widely available since about July 2015. Supported across modern browsers; understand child-boundary behavior before using it for hover menus.
98%Global support (approx.)
Google ChromeAll modern
Full support
Mozilla FirefoxAll modern
Full support
Apple SafariAll modern
Full support
Microsoft EdgeAll modern
Full support
OperaAll modern
Full support
Samsung InternetModern
Full support
Internet ExplorerLegacy support
Supported
onmouseoutWidely supported
Bottom line: Safe to use. For “left this whole element,” prefer mouseleave; use mouseout when you intentionally care about child boundaries.
Remember
Key Takeaways
Role: pointer left the element (or moved onto a child that covers it).
vs mouseleave:mouseout reacts to children; mouseleave does not.
relatedTarget: the element receiving the pointer after leave.
Hover menus: child moves often need mouseleave, not mouseout.
One line:onmouseout means “left this element’s area” — including into its own children.
Frequently Asked Questions
It is an inline event handler that runs JavaScript when the mouseout event fires — the pointing device moves so the cursor is no longer contained within the element or one of its children.
mouseout bubbles and also fires when the pointer moves from a parent onto a child (the child covers the parent). mouseleave does not fire for moves into descendants — it fires when leaving the element as a whole. MDN often recommends mouseleave for “left this box” UI.
onmouseover runs when the pointer enters an element (including via children). onmouseout runs when the pointer leaves that element (including into a child or outside).
Because the child obscures the parent’s visible area, so the pointer is no longer “in” the parent alone. That is expected mouseout behavior.
On mouseout, relatedTarget is the element the pointer is entering (or null). On mouseover, it is the element being left. Useful for knowing where the pointer went.
No. The mouseout event is Baseline widely available. Prefer mouseleave when you only care about leaving the whole element and its children as a unit.