HTML Events

Events occurs which denote that something like some event or action has happened which maybe of interest and the developer could use the event to perform certain tasks in the background or inform the user. For example, the website can inform the user that a button was clicked and the form is submitted.

Window Event Attributes

Event Name Attribute Description
beforeunload onbeforeunload Script to be run when the document is about to be unloaded
error onerror Script to be run when an error occurs
hashchange onhashchange Script to be run when there has been changes to the anchor part of the a URL
load onload Fires after the page is finished loading
message onmessage Script to be run when the message is triggered
pagehide onpagehide Script to be run when a user navigates away from a page
pageshow onpageshow Script to be run when a user navigates to a page
popstate onpopstate Script to be run when the window's history changes
resize onresize Fires when the browser window is resized
storage onstorage Script to be run when a Web Storage area is updated
unload onunload Fires once a page has unloaded (or the browser window has been closed)

Events

Event Name Attribute Description
afterprint onafterprint Script to be run after the document is printed
beforeprint onbeforeprint Script to be run before the document is printed

Network Events

Event Name Attribute Description
offline onoffline Script to be run when the browser starts to work offline
online ononline Script to be run when the browser starts to work online

Focus Events

Event Name Attribute Description
blur onblur Fires when the element loses focus
focus onfocus Fires the moment when the element gets focus

Form Events

Event Name Attribute Description
change onchange Fires when the value of the element is changed
contextmenu oncontextmenu Script to be run when a context menu is triggered
input oninput Script to be run when an element gets user input
invalid oninvalid Script to be run when an element is invalid
reset onreset Fires when the Reset button in a form is clicked
search onsearch Fires when the user writes something in a search field (for <input="search">)
select onselect Fires after some text has been selected in an element
submit onsubmit Fires when a form is submitted

Keyboard Events

Event Name Attribute Description
keydown onkeydown Fires when a user is pressing a key
keypress onkeypress Fires when a user presses a key
keyup onkeyup Fires when a user releases a key

Mouse Events

Event Name Attribute Description
click onclick Fires on a mouse click on the element
dblclick ondblclick Fires on a mouse double-click on the element
mousedown onmousedown Fires when a mouse button is pressed down on an element
mousemove onmousemove Fires when the mouse pointer is moving while it is over an element
mouseout onmouseout Fires when the mouse pointer moves out of an element
mouseover onmouseover Fires when the mouse pointer moves over an element
mouseup onmouseup Fires when a mouse button is released over an element
onmousewheel onmousewheel Deprecated. Use the onwheel attribute instead
scroll onscroll Script to be run when an element's scrollbar is being scrolled
wheel onwheel Fires when the mouse wheel rolls up or down over an element

Drag and Drop Events

Event Name Attribute Description
drag ondrag Script to be run when an element is dragged
dragend ondragend Script to be run at the end of a drag operation
dragenter ondragenter Script to be run when an element has been dragged to a valid drop target
dragleave ondragleave Script to be run when an element leaves a valid drop target
dragover ondragover Script to be run when an element is being dragged over a valid drop target
dragstart ondragstart Script to be run at the start of a drag operation
drop ondrop Script to be run when dragged element is being dropped

Clipboard Events

Event Name Attribute Description
copy oncopy Fires when the user copies the content of an element
cut oncut Fires when the user cuts the content of an element
paste onpaste Fires when the user pastes some content in an element

Media Events

Event Name Attribute Description
abort onabort Script to be run on abort
canplay oncanplay Script to be run when a file is ready to start playing (when it has buffered enough to begin)
canplaythrough oncanplaythrough Script to be run when a file can be played all the way to the end without pausing for buffering
cuechange oncuechange Script to be run when the cue changes in a <track> element
durationchange ondurationchange Script to be run when the length of the media changes
emptied onemptied Script to be run when something bad happens and the file is suddenly unavailable (like unexpectedly disconnects)
ended onended Script to be run when the media has reach the end (a useful event for messages like "thanks for listening")
error onerror Script to be run when an error occurs when the file is being loaded
loadeddata onloadeddata Script to be run when media data is loaded
loadedmetadata onloadedmetadata Script to be run when meta data (like dimensions and duration) are loaded
loadstart onloadstart Script to be run just as the file begins to load before anything is actually loaded
pause onpause Script to be run when the media is paused either by the user or programmatically
play onplay Script to be run when the media is ready to start playing
playing onplaying Script to be run when the media actually has started playing
progress onprogress Script to be run when the browser is in the process of getting the media data
ratechange onratechange Script to be run each time the playback rate changes (like when a user switches to a slow motion or fast forward mode)
seeked onseeked Script to be run when the seeking attribute is set to false indicating that seeking has ended
seeking onseeking Script to be run when the seeking attribute is set to true indicating that seeking is active
stalled onstalled Script to be run when the browser is unable to fetch the media data for whatever reason
suspend onsuspend Script to be run when fetching the media data is stopped before it is completely loaded for whatever reason
timeupdate ontimeupdate Script to be run when the playing position has changed (like when the user fast forwards to a different point in the media)
volumechange onvolumechange Script to be run each time the volume is changed which (includes setting the volume to "mute")
waiting onwaiting Script to be run when the media has paused but is expected to resume (like when the media pauses to buffer more data)

Other Events

Event Name Attribute Description
error onerror Fires when an error occurs while loading an external file
show onshow Fires when a <menu> element is shown as a context menu
toggle ontoggle Fires when the user opens or closes the <details> element