HTML Event Attributes
HTML event attributes are special attributes that can be added to HTML elements to define how the element should respond to various user interactions or other events, such as mouse clicks, keyboard input, or page loading. These attributes are used to specify the behavior and actions associated with specific events.
HTML event attributes enable web developers to create interactive and dynamic web pages by responding to user actions and other events, making websites more engaging and functional. They are typically paired with JavaScript code to define the specific actions that should occur when these events are triggered.
Keyboard Events:
Attribute | Definition |
---|---|
onkeydown | The script is triggered when the user presses any key. |
onkeypress | The script is triggered after the user presses a key (does not work with keys such as Alt, Ctrl, Shift, Esc, PrScr, etc.). |
onkeyup | The script is triggered after the key is released. |
Mouse Events:
Attribute | Definition |
---|---|
onclick | The script is triggered by clicking on the element. |
ondblclick | The script is triggered after a double click on the element. |
ondrag | The script is triggered when an element or selected text is dragged. |
ondragend | The script is triggered when the user has finished dragging the item (after the drag operation). |
ondragenter | The script is triggered when the item is moved to the specified zone (target for transfer). |
ondragleave | The script is triggered when the element leaves the valid zone for transfer. |
ondragover | The script is triggered when an item is moved over a valid transfer zone. |
ondragstart | The script is triggered when the user starts to drag an item. |
ondrop | The script is triggered after the dragged item descends onto the drag object. |
onmousedown | The script is triggered when a mouse button is clicked on an element. |
onmousemove | The script fires while the mouse pointer moves over the element. |
onmouseout | The script fires when the mouse moves outside the element. |
onmouseover | The script fires when the mouse pointer begins to move over an element. |
onmouseup | The script is triggered when you release the mouse button from an element. |
onmousewheel | The script is triggered when using the mouse wheel. Deprecated attribute (not recommended). |
onscroll | The script is triggered while scrolling the scroll bar of an element. |
onwheel | The script fires when you use the mouse wheel on an element. |
Touch Events:
Attribute | Definition |
---|---|
ontouchcancel | The touch is interrupted. |
ontouchend | The user removes the finger from an element. |
ontouchmove | The user moves the finger across the screen. |
ontouchstart | A finger is placed on a touch screen. |
Form Events:
Attribute | Definition |
---|---|
onblur | The script is triggered when the element loses focus. |
onchange | The script is triggered when the element values change. |
oncontextmenu | The script is triggered when the context menu on the element is called. |
onfocus | The script is triggered when the item receives focus. |
oninput | The script is triggered when the element receives data input from the user. |
oninvalid | The script is triggered when the submitted form element has been verified and does not meet the restrictions of the form (for example, the required field is not filled - the required attribute). |
onreset | The script is triggered when the form is reset. |
onsearch | The script fires when the user presses the Enter key or the x button in the <input> element (type = "search"). |
onselect | The script fires when text is selected in an element. |
onsubmit | The script is triggered when the form is submitted. |
Clipboard Events:
Attribute | Definition |
---|---|
oncopy | The script is triggered when the user copies the contents of the element. |
oncut | The script is triggered when the user cuts out the contents of the element. |
onpaste | The script is triggered when the user inserts the content into the element. |
Windows Events:
Attribute | Definition |
---|---|
onafterprint | The script is triggered after the document is printed. |
onbeforeprint | The script is executed before printing the document. |
onbeforeunload | The script is triggered before the document is loaded. |
onhaschange | The script is triggered if there are changes in the name of # anchors in the document (from the current URL). |
onload | The script will be launched after completion of the full page load (including images, external style sheets and external scripts). |
onmessage | The script is executed when the message is triggered. |
onoffline | The script is triggered when the browser starts working offline. |
ononline | The script is triggered when the browser starts working online. |
onpagehide | The script is triggered when the user leaves the page. |
onpageshow | The script is triggered when the user goes to the page. |
onpopstate | The script is triggered when the history window changes. |
onresize | The script is triggered when the browser window changes. |
onstorage | The script is triggered when the web datastore is updated. |
onunload | The script is triggered when the user exits the document. |
Media Events:
Attribute | Definition |
---|---|
onabort | The script is triggered upon interruption. |
oncanplay | The script is triggered when the file is ready to start playing (when it is buffered enough to start). |
oncanplaythrough | The script is triggered when the file can be played in full (from start to finish) without stopping for buffering. |
ondurationchange | The script is triggered when the length of the media file is changed. |
onemptied | The script is triggered when a malfunction occurs and the file becomes unavailable (for example, when the connection to the Internet is disconnected). |
onended | The script is triggered when the audio / video file reaches the end (for example, to display a message: thanks for listening / viewing). |
onloadeddata | The script is triggered when loading media file data. |
onloadedmetadata | The script is triggered when meta data is loaded (for example, size and duration). |
onloadstart | The script is triggered when a file is downloaded before it actually starts loading. |
onpause | The script is triggered if the file is paused (paused) by the user or programmatically. |
onplay | The script is triggered when the file is ready to start playing. |
onplaying | The script is triggered when a file is played. |
onprogress | The script is triggered when the browser is in the process of receiving media file data. |
onratechange | The script is triggered each time the playback mode changes (for example, when the user switches to slow playback or fast rewind mode). |
onreadystatechange | The script is triggered each time the ready state changes (the ready state tracks the state of the media data). |
onseeked | The script fires when the object.seeking attribute of the <audio> tags or <video> set to "false" (the user does not move to new playback positions - the end of the "rewind"). |
onseeking | The script fires when the object.seeking attribute of the <audio> tags or <video> set to "true" (the user moves to the new playback position - "rewind"). |
onstalled | The script is triggered when the browser cannot receive media file data for any reason. |
onsuspend | The script is triggered when the receipt of media file data is stopped, before the end of the full download for any reason. |
ontimeupdate | The script is triggered when the playback position has changed (for example, when the user has selected a different playback point). |
onvolumechange | The script is triggered every time the sound volume value changes (including the complete mute). |
onwaiting | The script is triggered when the media file is stopped, but restarting is expected (for example, when the file pauses to buffer the remaining data). |
Other Events:
Attribute | Definition |
---|---|
onerror | The script is triggered when an error occurs while loading an external file. |
onshow | The script is triggered when the <menu> element displayed as a context menu. |
ontoggle | The script is triggered when the user opens or closes the <details> element. |