HTML Event Reference Manual

Global Event Properties

HTML has the ability to trigger actions in the browser, such as starting JavaScript when a user clicks on an element.

For more information on programming events, please visit our JavaScript Tutorial.

The following are global event properties that can be added to HTML elements to define event operations.

Window Event Properties

Events triggered for the window object (applied to the <body> tag):

Property Value Description
onafterprint script Script executed after the document is printed.
onbeforeprint script Script executed before the document is printed.
onbeforeunload script Script executed before the document is unloaded.
onerror script Script executed when an error occurs.
onhaschange script Script executed when the document has changed.
onload script Triggered after the page has finished loading.
onmessage script Script executed when a message is triggered.
onoffline script Script executed when the document goes offline.
ononline script Script executed when the document goes online.
onpagehide script Script executed when the window is hidden.
onpageshow script Script executed when the window becomes visible.
onpopstate script Script executed when the window history changes.
onredo script Script executed when the document performs undo (redo).
onresize script Triggered when the browser window is resized.
onstorage script Script executed after the Web Storage area is updated.
onundo script Script executed when the document performs undo.
onunload script Triggered once the page has been downloaded (or the browser window has been closed).

Form Events

Events triggered by actions within HTML forms (applied to almost all HTML elements, but most commonly used in form elements):

Property Value Description
onblur script Scripts that run when an element loses focus.
onchange script Scripts that run when the value of an element is changed.
oncontextmenu script Scripts that run when a context menu is triggered.
onfocus script Scripts that run when an element receives focus.
onformchange script Scripts that run when a form changes.
onforminput script Scripts that run when a form receives user input.
oninput script Scripts that run when an element receives user input.
oninvalid script Scripts that run when an element is invalid.
onreset script Triggered when the reset button in a form is clicked. Not supported in HTML5.
onselect script Triggered after text in an element is selected.
onsubmit script Triggered when a form is submitted.

Keyboard events

Property Value Description
onkeydown script Triggered when a user presses a key.
onkeypress script Triggered when a user presses a button.
onkeyup script Triggered when a user releases a key.

Mouse events

Events triggered by mouse or similar user actions:

Property Value Description
onclick script Triggered when a mouse click occurs on the element.
ondblclick script Triggered when a mouse double-click occurs on the element.
ondrag script Scripts that run when an element is being dragged.
ondragend script Scripts that run at the end of a drag operation.
ondragenter script Scripts that run when an element has been dragged into a valid drop area.
ondragleave script Scripts that run when an element leaves a valid drag target.
ondragover script Scripts that run when an element is being dragged over a valid drag target.
ondragstart script Scripts that run at the beginning of a drag operation.
ondrop script Scripts that run when the element being dragged is being dragged and dropped.
onmousedown script Triggered when a mouse button is pressed on the element.
onmousemove script Triggered when the mouse pointer moves onto the element.
onmouseout script Triggered when the mouse pointer moves out of the element.
onmouseover script Triggered when the mouse pointer moves onto the element.
onmouseup script Triggered when the mouse button is released on the element.
onmousewheel script Scripts that run when the mouse wheel is being scrolled.
onscroll script Scripts that run when the element scrollbar is scrolled.

Media events

Events triggered by media (such as video, images, and audio) (applicable to all HTML elements, but commonly found in media elements such as <audio>, <embed>, <img>, <object>, and <video>):

Property Value Description
onabort script The script runs when exiting.
oncanplay script The script runs when the file is ready and can start playing (the buffer is sufficient to start).
oncanplaythrough script The script runs when the medium can play through to the end without stopping for buffering.
ondurationchange script The script runs when the length of the medium changes.
onemptied script The script runs when a failure occurs and the file suddenly becomes unavailable (for example, when the connection is unexpectedly disconnected).
onended script The script runs when the medium has reached the end (can send messages like 'Thank you for watching').
onerror script The script runs when an error occurs during the file loading period.
onloadeddata script The script runs when the media data has been loaded.
onloadedmetadata script The script runs when metadata (such as resolution and duration) is loaded.
onloadstart script The script runs when the file starts loading but no actual data is loaded yet.
onpause script The script runs when the medium is paused by the user or a program.
onplay script The script runs when the medium is ready and can start playing.
onplaying script The script runs when the medium has started playing.
onprogress script The script runs when the browser is fetching media data.
onratechange script The script runs whenever the playback rate changes (for example, when the user switches to slow motion or fast-forward mode).
onreadystatechange script The script runs whenever the ready state changes (monitoring the status of the media data).
onseeked script The script runs when the seeking attribute is set to false (indicating that seeking has ended).
onseeking script The script runs when the seeking attribute is set to true (indicating that seeking is active).
onstalled script The script runs when the browser fails to retrieve media data for any reason.
onsuspend script The script runs when retrieving media data is terminated for any reason before the media data is completely loaded.
ontimeupdate script The script runs when the playback position changes (for example, when the user fast-forwards to a different position in the medium).
onvolumechange script The script runs whenever the volume changes (including when the volume is set to mute).
onwaiting script When the medium has stopped playing but intends to continue playing (for example, when the medium is paused to buffer more data), the script runs.