Favorites

HTML onmouseleave Event Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
onmouseleave
HTML Event AttributeThis event attribute is supported by all modern browsers.
Updated 22nd November 2026

Description

The onmouseleave event attribute runs a script when the mouse pointer moves out of an element and all of its descendants.

Unlike onmouseout, mouseleave does not bubble and does not fire when the pointer moves from the element onto one of its children; it only fires when the pointer leaves the element's area completely. It is usually paired with onmouseenter.

For pens and touch as well as mice, use onpointerleave.

Syntax

<element onmouseleave="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html>
<html>
<head>
<title>onmouseleave event</title>
<style>
#box {
padding: 30px;
background: #dde3ff;
}
#box span {
display: inline-block;
padding: 10px;
background: #4361ee;
color: #fff;
}
</style>
</head>
<body>
<div id="box" onmouseleave="log('mouseleave')" onmouseout="log('mouseout')">Move the mouse over this box <span>child</span></div>
<ul id="log"></ul>
<script>
function log(text) {
var li = document.createElement("li");
li.textContent = text;
document.getElementById("log").appendChild(li);
}
</script>
</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML onmouseleave event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.

This event attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee