FANDOM


This list of obtrusive attributes is not recommended. Authors should generally find an alternative way to accomplish the same task while adhering to all best practices, or simply do without it if it is unimportant.


The event attributes listed below are standard, and are supported by most HTML5 tags. However, they are considered obtrusive and the recommended way of listening for events is documented at events.

Window Events

Only used in the <body> element to specify events triggered for a window object.

Attribute Value Description
onafterprint script Script to be run after the document is printed.
onbeforeprint script Script to be run before the document is printed.
onbeforeonload script Script to be run before the document loads.
onblur script Script to be run when the window loses focus.
onerror script Script to be run when an error occurs.
onfocus script Script to be run when the window gets focused.
onhaschange script Script to be run when the document has changed.
onload script Script to be run when a document loads.
onmessage script Script to be run when the message is triggered.
onoffline script Script to be run when the document goes offline.
ononline script Script to be run when the document comes online.
onpagehide script Script to be run when the window is hidden.
onpageshow script Script to be run when the window becomes visible.
onpopstate script Script to be run when the window's history changes.
onredo script Script to be run when the document performs a redo.
onresize script Script to be run when the window is resized.
onstorage script Script to be run when a document loads.
onundo script Script to be run when a document performs an undo.
onunload script Script to be run when a document unloads.

Form Events

Applies to all HTML5 elements, but generally used in <form> elements.

Attribute Value Description
onblur script Script to be run when an element loses focus.
onchange script Script to be run when an element changes.
oncontextmenu script Script to be run when a context menu is triggered.
onfocus script Script to be run when an element gets focused.
onformchange script Script to be run when a form changes.
onforminput script Script to be run when a form gets user input.
oninput script Script to be run when an element gets user input.
oninvalid script Script to be run when an element is invalid.
onselect script Script to be run when an element is selected.
onsubmit script Script to be run when a form is submitted.

Keyboard Events

Useless in <base />, <bdo>, <br />, <frame />, <frameset>, <head>, <html>, <iframe>, <meta />, <param />, <script>, <style>, and <title>; applies to all HTML5 elements.

Attribute Value Description
onkeydown script Script to be run when a key is pressed.
onkeypress script Script to be run when a key is pressed and released.
onkeyup script Script to be run when a key is released.

Mouse Events

Useless in <base />, <bdo>, <br />, <frame />, <frameset>, <head>, <html>, <iframe>, <meta />, <param />, <script>, <style>, and <title>; applies to all HTML5 elements.

Attribute Value Description
onclick script Script to be run on a mouse click.
ondblclick script Script to be run on a mouse double-clicked.
ondrag script Script to be run when an element is dragged.
ondragend script Script to be run at the end of a drag operation.
ondragenter script Script to be run when an element has been dragged to a valid drop target.
ondragleave script Script to be run when an element leaves a valid drop target.
ondragover script Script to be run when an element is being dragged over a valid drop target.
ondragstart script Script to be run at the start of a drag operation.
ondrop script Script to be run when dragged element is being dropped.
onmousedown script Script to be run when mouse button is pressed.
onmousemove script Script to be run when mouse pointer moves.
onmouseout script Script to be run when mouse pointer moves out of an element.
onmouseover script Script to be run when mouse pointer moves over an element.
onmouseup script Script to be run when mouse button is released.
onmousewheel script Script to be run when the mouse wheel is being rotated.
onscroll script Script to be run when an element's scrollbar is being scrolled.

Media Events

Applies to all HTML5 elements, but is most common in <audio>, <embed />, <img />, <object>, and <video>.

Attribute Value Description
onabort script Script to be run on an abort event.
oncanplay script Script to be run when media can start playing, but might has to stop for buffering.
oncanplaythrough script Script to be run when media can be played to the end, without stopping for buffering.
ondurationchange script Script to be run when the length of the media is changed.
onemptied script Script to be run when a media resource element suddenly becomes empty (network errors, errors on load etc.).
onended script Script to be run when media has reach the end.
onerror script Script to be run when an error occurs during the loading of an element.
onloadeddata script Script to be run when media data is loaded.
onloadedmetadata script Script to be run when the duration and other media data of a media element is loaded.
onloadstart script Script to be run when the browser starts to load the media data.
onpause script Script to be run when media data is paused.
onplay script Script to be run when media data is going to start playing.
onplaying script Script to be run when media data has start playing.
onprogress script Script to be run when the browser is fetching the media data.
onratechange script Script to be run when the media data's playing rate has changed.
onreadystatechange script Script to be run when the ready-state changes.
onseeked script Script to be run when a media element's seeking attribute is no longer true, and the seeking has ended.
onseeking script Script to be run when a media element's seeking attribute is true, and the seeking has begun.
onstalled script Script to be run when there is an error in fetching media data (stalled).
onsuspend script Script to be run when the browser has been fetching media data, but stopped before the entire media file was fetched.
ontimeupdate script Script to be run when media changes its playing position.
onvolumechange script Script to be run when media changes the volume, also when volume is set to "mute".
onwaiting script Script to be run when media has stopped playing, but is expected to resume.

See Also

Global Event Attributes

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.