HTML onmouseover Attribute

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

Definition and Usage

The onmouseover attribute is an inline event handler for the mouseover event. It runs when a pointing device moves the cursor onto the element or one of its child elements.

Pair it with onmouseout for enter/leave. MDN notes that mouseenter is often clearer for “entered this whole box,” because mouseover also fires when moving between parent and children.

Baseline · Widely available.

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

Child boundaries fire mouseover.

Moving from a parent onto a child fires mouseover again (on the child, and bubbled). Prefer mouseenter when you want a single enter for the whole group.

HTML Syntax

syntax.html
<element onmouseover=" script">

script is JavaScript that runs on enter. Pass event to read event.target and event.relatedTarget. Script alternative: element.addEventListener("mouseover", handler).

Attribute Values

The attribute value is a script. Common patterns:

Value / patternDescriptionTry it
handler()Run code when the pointer enters the elementTry it
handler(event)Inspect target / relatedTarget (where the pointer came from)Try it
With nested childrenSee mouseover fire again when moving onto a childTry it
addEventListener("mouseover")Preferred modern registration in appsTry it

Live Preview

Move onto the pad. In nested mode, moving onto the inner box fires extra mouseover events even though you never left the outer pad visually.

demo

Enter the pad (or the inner box in nested mode) to see mouseover.

Hover area
Outer pad — move in

Status: waiting…

HTML Examples

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

Example 1 — Update Status When Entering

Show a message when the pointer enters a simple pad.

HTML
<div
  id="pad"
  onmouseover="setStatus('Inside')"
  onmouseout="setStatus('Outside')">
  Hover me
</div>
<p id="status">Waiting…</p>

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

How It Works

  1. Enter the pad — mouseover sets “Inside”.
  2. Leave the pad — mouseout sets “Outside”.
  3. No children here — so enter means onto this single box.
  4. Common uses — highlight, show a tip, preview an image.

Example 3 — Nested Children Surprise

Moving onto an inner box fires another mouseover — not just the first enter of the outer.

HTML
<div id="outer" onmouseover="logOver(event)">
  Outer
  <span id="inner">Inner</span>
</div>
<ul id="log"></ul>

<script>
  function logOver(e) {
    var li = document.createElement("li");
    li.textContent =
      "mouseover on " + (e.target.id || e.target.tagName) +
      " ← " + (e.relatedTarget ? (e.relatedTarget.id || e.relatedTarget.tagName) : "null");
    document.getElementById("log").appendChild(li);
  }
</script>
Try It Yourself

How It Works

  1. Enter outer — first mouseover (often on outer).
  2. Move onto Inner — another mouseover targets the child and bubbles.
  3. Handlers can run many times while staying “inside” the outer box.
  4. Fix: use mouseenter for one enter per whole group, or ignore events when relatedTarget is already inside the parent.

Edge Cases & Pitfalls

Most bugs come from treating every mouseover as a brand-new “entered the component.”

children

Moving onto a child fires mouseover again

MDN: parent/child boundary moves trigger mouseover/mouseout. Prefer mouseenter for a single whole-box enter.

bubbling

mouseover bubbles

A child enter 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 behind hover alone. Offer focus or click alternatives for the same information.

touch

Touch has no lasting hover

Phones may synthesize a brief hover on tap. Do not rely on mouseover for critical mobile UX.

pair

Match with mouseout carefully

mouseover/mouseout share child-boundary noise. mouseenter/mouseleave usually do not.

Browser Support

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

✓ Baseline · Widely available

onmouseover

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 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
onmouseover Widely supported

Bottom line: Safe to use. For “entered this whole element once,” prefer mouseenter; use mouseover when you intentionally care about child targets.

Key Takeaways

  • Role: pointer moved onto the element or one of its children.
  • vs mouseenter: mouseover reacts to children; mouseenter does not.
  • relatedTarget: the element the pointer left before enter.
  • A11y: do not make essential content hover-only.

One line: onmouseover means “entered this element’s area” — including moves onto its children.

Frequently Asked Questions

It is an inline event handler that runs JavaScript when the mouseover event fires — a pointing device moves the cursor onto the element or one of its child elements.
mouseover bubbles and also fires when the pointer moves between a parent and its children. mouseenter fires once when entering the element as a whole and is not affected by moves into descendants. MDN often recommends mouseenter for simple “entered this box” UI.
onmouseover runs when the pointer enters. onmouseout runs when the pointer leaves (including into a child). They are a common enter/leave pair, with the same child-boundary behavior.
Because entering a child still counts as moving onto that child element. A handler on the parent can see bubbled mouseover events from children too.
relatedTarget is the element the pointer left (or null). Combined with target, you can tell where the pointer came from.
No. The mouseover event is Baseline widely available. Prefer mouseenter when you only care about entering the whole element once.

Next: onmouseup

Handle the moment a mouse button is released.

onmouseup 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