HTML onmouseover Event Attribute
Description
The onmouseover HTML event attribute is used to specify a JavaScript function that will be executed when the mouse pointer enters the element. It is one of the many event attributes that can be used to add interactivity to HTML elements.
The onmouseover attribute can be used on any HTML element, except for <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>.
To use the onmouseover attribute, simply add it to the element in question and assign it the name of the JavaScript function that you want to be executed. For example, the following code will cause an alert popup to appear when the user hovers their mouse over the <p> element:
<p onmouseover="alert('Hello, world!')">This is a paragraph.</p>
The onmouseover attribute is often used together with the onmouseout attribute, which is used to specify a JavaScript function that will be executed when the mouse pointer leaves the element. For example, the following code will cause the background color of the <div> element to change to red when the user hovers their mouse over it, and then change back to white when the user moves their mouse away:
<div onmouseover="this.style.backgroundColor = 'red'" onmouseout="this.style.backgroundColor = 'white'">This is a div.</div>
The onmouseover attribute is a powerful tool that can be used to add interactivity to your HTML pages. It is easy to use and can be combined with other event attributes to create complex and sophisticated effects.
Syntax
<element onmouseover="script">
Values
- scriptThe name of the script to use when the event has been triggered.
Example
Browser Support
The following information will show you the current browser support for the HTML onmouseover 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
Tablets & Mobile
Last updated by CSSPortal on: 13th October 2023
