HTML – Events Reference

Share

HTML adds interactivity with the user through events triggered based on actions in a web browser. Most of these events target JavScript script (event handlers) which can be programmed to do whatever the web developer needs it to do.

The HTML 4.01 specification had defined 19 events. HTML5 added more events. Those which were introduced in HTML5 are labeled “Y” in the tables below.

These are the global event attributes that can be added to HTML elements to define event actions.

Window Events

These are the events triggered by the window object.

AttributeHTML5Description
onafterprintYTriggers after a document is printed
onbeforeprintYTriggers before a document is printed
onbeforeonloadYTriggers before a document loads
onerrorYTriggers when an error occurs
onhaschangeYTriggers when a document has changed
onloadTriggers when a document loads
onmessageYTriggers when a message is triggered
onofflineYTriggers when a document goes offline
ononlineYTriggers when a document comes online
onpagehideYTriggers when a window is hidden
onpageshowYTriggers when a window becomes visible
onpopstateYTriggers when a window’s history changes
onredoYTriggers when a document performs a redo
onresizeYTriggers when a window is resized
onstorageYTriggers when a document loads
onundoYTriggers when a document performs an undo
onunloadTriggers when a user leaves the document

Form Events

These events are triggered by actions inside an HTML form even though they may apply to almost all HTML elements outside form elements.

AttributeHTML5Description
onblurYTriggers when a window loses focus
onchangeTriggers when an element changes
oncontextmenuYTriggers when a context menu is triggered
onfocusTriggers when a window gets focus
onformchangeYTriggers when a form changes
onforminputYTriggers when a form gets user input
oninputYTriggers when an element gets user input
oninvalidYTriggers when an element is invalid
onresetTriggers when a form is reset
onselectTriggers when an element is selected
onsubmitTriggers when a form is submitted

Keyboard Events

These events are triggered by actions on keyboard keys.

AttributeHTML5Description
onkeydownTriggers when a key is pressed
onkeypressTriggers when a key is pressed and released
onkeyupTriggers when a key is released

Mouse Events

These events are triggered by actions on the mouse movement as well as button presses.

AttributeHTML5Description
onclickTriggers on a mouse click
ondblclickTriggers on a mouse double-click
onmousedownTriggers when a mouse button is pressed
onmousemoveTriggers when the mouse pointer moves
onmouseoutTriggers when the mouse pointer moves out of an element
onmouseoverTriggers when the mouse pointer moves over an element
onmouseupTriggers when a mouse button is released
onmousewheel(Deprecated use onwheel) Triggers when the mouse wheel is being rotated
onwheelTriggers when the mouse wheel is being rotated

Drag Events

These events are triggered by actions on the mouse movements while keys are pressed on a particular element.

AttributeHTML5Description
ondragYTriggers when an element is dragged
ondragendYTriggers at the end of a drag operation
ondragenterYTriggers when an element has been dragged to a valid drop target
ondragleaveYTriggers when an element leaves a valid drop target
ondragoverYTriggers when an element is being dragged over a valid drop target
ondragstartYTriggers at the start of a drag operation
ondropYTriggers when a dragged element is being dropped
onscrollYTriggers when an element’s scrollbar is being scrolled

Clipboard Events

These events are triggered when data is added or retrieved from the Clipboard.

AttributeHTML5Description
oncopyYTriggered when the user copies the content of an element
oncutYTriggered when the user cuts the content of an element
onpasteYTriggered when the user pastes some content in an element

Media Events

These events are triggered by actions on media like videos, images, and audio. They apply to all elements though it is most practical for use on elements such as audio, embed, img, object, and video.

AttributeHTML5Description
onabortYTriggers on an abort event
oncanplayYTriggers when a media can start play, but might has to stop for buffering
oncanplaythroughYTriggers when a media can be played to the end, without stopping for buffering
ondurationchangeYTriggers when the length of a media is changed
onemptiedYTriggers when a media resource element suddenly becomes empty
onendedYTriggers when a media has reached the end
onerrorYTriggers when an error occurs
onloadeddataYTriggers when media data is loaded
onloadedmetadataYTriggers when the duration and other media data of a media element is loaded
onloadstartYTriggers when the browser starts loading the media data
onpauseYTriggers when media data is paused
onplayYTriggers when media data is going to start playing
onplayingYTriggers when media data has started playing
onprogressYTriggers when the browser is fetching the media data
onratechangeYTriggers when the playing rate of media data has changed
onreadystatechangeYTriggers when the ready-state changes
onseekedYTriggers when the seeking attribute of a media element is no longer true, and the seeking has ended
onseekingYTriggers when the seeking attribute of a media element is true, and the seeking has begun
onstalledYTriggers when there is an error in fetching media data
onsuspendYTriggers when the browser has been fetching media data, but stopped before the entire media file was fetched
onvolumechangeYTriggers when a media changes the volume, also when the volume is set to “mute”
ontimeupdateYTriggers when media changes its playing position
onwaitingYTriggers when media has stopped playing but is expected to resume

Misc Events

AttributeHTML5Description
ontoggleYTriggered when the user opens or closes the details element

Share