HTML5 Event Attributes

Standard Event Attributes

HTML 4 added the ability to let events trigger actions in a browser, like starting a JavaScript when a user clicks on an element.
To learn more about programming events, please visit our JavaScript tutorial and our DHTML tutorial.
Below are the standard event attributes that can be inserted into HTML5 elements to define event actions.
New : New event attributes in HTML5.

Window Event Attributes

Events triggered for the window object.
Applies to the <body> tag:
AttributeValueDescription
onafterprintNewscriptScript to be run after the document is printed
onbeforeprintNewscriptScript to be run before the document is printed
onbeforeonloadNewscriptScript to be run before the document loads
onblurscriptScript to be run when the window loses focus
onerrorNewscriptScript to be run when an error occur
onfocusscriptScript to be run when the window gets focus
onhaschangeNewscriptScript to be run when the document has change
onloadscriptScript to be run when the document loads
onmessageNewscriptScript to be run when the message is triggered
onofflineNewscriptScript to be run when the document goes offline
ononlineNewscriptScript to be run when the document comes online
onpagehideNewscriptScript to be run when the window is hidden
onpageshowNewscriptScript to be run when the window becomes visible
onpopstateNewscriptScript to be run when the window's history changes
onredoNewscriptScript to be run when the document performs a redo
onresizeNewscriptScript to be run when the window is resized
onstorageNewscriptScript to be run when a document loads
onundoNewscriptScript to be run when a document performs an undo
onunloadNewscriptScript to be run when the user leaves the document


Form Events

Events triggered by actions inside a HTML form.
Applies to all HTML5 elements, but is most common in form elements:
AttributeValueDescription
onblurscript Script to be run when an element loses focus
onchangescriptScript to be run when an element changes
oncontextmenuNewscript Script to be run when a context menu is triggered
onfocusscript Script to be run when an element gets focus
onformchangeNewscript Script to be run when a form changes
onforminputNewscript Script to be run when a form gets user input
oninputNewscript Script to be run when an element gets user input
oninvalidNewscript Script to be run when an element is invalid
onresetscript Script to be run when a form is reset
Not supported in HTML5
onselectscript Script to be run when an element is selected
onsubmitscriptScript to be run when a form is submitted


Keybord Events

Events triggered by a keyboard.
Applies to all HTML5 elements.
AttributeValueDescription
onkeydownscript Script to be run when a key is pressed
onkeypressscript Script to be run when a key is pressed and released
onkeyupscript Script to be run when a key is released


Mouse Events

Events triggered by a mouse, or similar user actions:
Applies to all HTML5 elements.
AttributeValueDescription
onclickscript Script to be run on a mouse click
ondblclickscript Script to be run on a mouse double-click
ondragNewscript Script to be run when an element is dragged
ondragendNewscript Script to be run at the end of a drag operation
ondragenterNewscript Script to be run when an element has been dragged to a valid drop target
ondragleaveNewscript Script to be run when an element leaves a valid drop target
ondragoverNewscript Script to be run when an element is being dragged over a valid drop target
ondragstartNewscript Script to be run at the start of a drag operation
ondropNewscript Script to be run when dragged element is being dropped
onmousedownscript Script to be run when a mouse button is pressed
onmousemovescript Script to be run when the mouse pointer moves
onmouseoutscriptScript to be run when the mouse pointer moves out of an element
onmouseoverscriptScript to be run when the mouse pointer moves over an element
onmouseupscript Script to be run when a mouse button is released
onmousewheelNewscript Script to be run when the mouse wheel is being rotated
onscrollNewscript Script to be run when an element's scrollbar is being scrolled


Media Events

Events triggered by medias like videos, images and audio.
Applies to all HTML5 elements, but is most common in media elements, such as audio, embed, img, object, and video:
AttributeValueDescription
onabortscript Script to be run on an abort event
oncanplayNewscriptScript to be run when media can start play, but might has to stop for buffering
oncanplaythroughNewscriptScript to be run when media can be played to the end, without stopping for buffering
ondurationchangeNewscript Script to be run when the length of the media is changed
onemptiedNewscript Script to be run when a media resource element suddenly becomes empty (network errors, errors on load etc.)
onendedNewscript Script to be run when media has reach the end
onerrorNewscript Script to be run when an error occurs during the loading of an element
onloadeddataNewscriptScript to be run when media data is loaded
onloadedmetadataNewscriptScript to be run when the duration and other media data of a media element is loaded
onloadstartNewscriptScript to be run when the browser starts to load the media data
onpauseNewscript Script to be run when media data is paused
onplayNewscript Script to be run when media data is going to start playing
onplayingNewscript Script to be run when media data has start playing
onprogressNewscript Script to be run when the browser is fetching the media data
onratechangeNewscript Script to be run when the media data's playing rate has changed
onreadystatechangeNewscript Script to be run when the ready-state changes
onseekedNewscript Script to be run when a media element's seeking attribute is no longer true, and the seeking has ended
onseekingNewscript Script to be run when a media element's seeking attribute is true, and the seeking has begun
onstalledNewscript Script to be run when there is an error in fetching media data (stalled)
onsuspendNewscriptScript to be run when the browser has been fetching media data, but stopped before the entire media file was fetched
ontimeupdateNewscriptScript to be run when media changes its playing position
onvolumechangeNewscriptScript to be run when media changes the volume, also when volume is set to "mute"
onwaitingNewscriptScript to be run when media has stopped playing, but is expected to resume

Comments