The mouseleave event fires when a pointing device moves out of an element. Learn addEventListener vs onmouseleave, how it differs from mouseout, the mouseenter pair, CSS :hover-like cleanup, and five try-it labs.
01
Kind
Instance event
02
Type
MouseEvent
03
When
Pointer leaves
04
Handler
onmouseleave
05
Bubbles?
No
06
Status
Baseline widely available
Fundamentals
Introduction
mouseleave answers: “Did the pointer just leave this element and all of its descendants?” Pair it with mouseenter and you get JS hover enter/exit signals similar to CSS :hover.
Unlike mouseout, mouseleave does not bubble and fires only after the pointer has left the element and all descendants. That makes it friendlier for card/hover UI where you want one clean exit, not a burst of out events while moving among children.
💡
Beginner tip
“Leaving” follows the DOM tree, not only the painted box. Moving into a visually nested sibling can fire mouseleave on the outer element even if the pointer still looks inside the outer element’s painted area.
Concept
Understanding mouseleave
An instance event that answers: “Did the pointer just leave this element?”
Fires when the pointer moves out of the element and all descendants.
Does not bubble — stays on the element that was left.
Descendants — moving among children does not fire leave on the parent.
Pair — mouseenter when the pointer enters.
Not fired when the element is removed/replaced in the DOM (MDN).
Baseline Widely available on MDN (since July 2015).
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property:
The secondary target (where the pointer came from), if any
target
The element that was left
ctrlKey / shiftKey / …
Modifier keys at enter time
Compare
⚖️ mouseleave vs mouseout
Feature
mouseleave
mouseout
Bubbles?
No
Yes
Moving among descendants
Does not fire on the parent
Fires / bubbles as you move
Best for
Whole-component hover exit
Delegation / bubbling paths
Enter twin
mouseenter
mouseover
⚠️
Performance note (MDN)
Leaving a deep hierarchy can send many mouseleave events (one per ancestor). Prefer mouseout when you need a single bubbling path, or measure cost if you attach leave listeners widely.
mouseleave is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. Non-bubbling leave behavior is consistent across modern engines.
✓ Baseline · Widely available
Element mouseleave
Fires when the pointer leaves an element and its descendants; pair with mouseenter for hover UI.
FullWidely available
Google ChromeFull support
Yes
Mozilla FirefoxFull support
Yes
Apple SafariFull support
Yes
Microsoft EdgeFull support
Yes
OperaFull support
Yes
Internet ExplorerSupported
Yes
mouseleaveBaseline
Bottom line: Great for component hover exit. Prefer mouseout for bubbling/delegation, and always clean up leave state.
Wrap Up
Conclusion
mouseleave is the non-bubbling “pointer left this element” signal. Pair it with mouseenter for stable hover UI, and reach for mouseout when bubbling or delegation matters.
Pair mouseenter / mouseleave for whole-component hover
Clean up classes, tips, and timers inside mouseleave
Prefer CSS :hover when you only need visual changes
Provide a non-hover path for touch / keyboard users
Prefer addEventListener in production code
❌ Don’t
Expect mouseleave to bubble like mouseout
Assume leave fires when you remove the element from the DOM
Leave hover UI stuck because you only handled enter
Assume hover UX works the same on phones
Overwrite onmouseleave if you need multiple listeners
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about mouseleave
Pointer left—non-bubbling hover exit.
5
Core concepts
📱01
On leave
pointer moved out
Trigger
📄02
No bubble
unlike mouseout
API
👆03
Stable exit
kids do not re-fire
Why
🔄04
mouseenter
enter pair
Pair
🎯05
Baseline
widely available
Status
❓ Frequently Asked Questions
It fires when a pointing device moves out of an element and all of its descendants. Combined with mouseenter, it behaves a lot like leaving CSS :hover for that element.
No. MDN marks Element mouseleave as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
A MouseEvent (inherits from UIEvent and Event). Useful fields include clientX, clientY, relatedTarget, and modifier keys.
mouseleave does not bubble and fires only when the pointer has left the element and all descendants. mouseout bubbles and also fires when moving from the element to a descendant (or between descendants via bubbling).
It follows the element’s position in the DOM tree. Moving into a visually nested sibling can still fire mouseleave on the outer element even if the pointer stays inside the outer element’s painted box.
No. MDN notes that mouseleave and mouseout are not triggered when the element is replaced or removed from the DOM.
Did you know?
If you remove or replace an element while the pointer is over it, mouseleave will not fire. Clean up hover state yourself when you tear down DOM nodes.