References

Beginner-friendly references for web development, with live, editable examples.

HTML Events

113 in total

Event attributes let you run JavaScript in response to user actions such as clicks, key presses and form changes. Here are all 113 HTML event attributes, each with a description and live, editable examples.

Name Description
onabort Runs JavaScript when resource loading is aborted.
onafterprint Runs JavaScript after printing.
onanimationcancel Runs JavaScript when a CSS animation is canceled.
onanimationend Runs JavaScript when a CSS animation finishes.
onanimationiteration Runs JavaScript at the end of each CSS animation iteration.
onanimationstart Runs JavaScript when a CSS animation starts.
onauxclick Runs JavaScript when a non-primary mouse button is clicked.
onbeforeinput Runs JavaScript just before editable content changes.
onbeforematch Runs JavaScript before hidden-until-found content is revealed.
onbeforeprint Runs JavaScript before printing.
onbeforetoggle Runs JavaScript just before a popover or <details> toggles.
onbeforeunload Runs JavaScript before the page unloads, to warn about unsaved changes.
onblur Runs JavaScript when the element loses focus.
oncancel Runs JavaScript when a dialog is canceled.
oncanplay Runs JavaScript when media can begin playing.
oncanplaythrough Runs JavaScript when media can play through without stopping.
onchange Runs JavaScript when a control's value is committed.
onclick Runs JavaScript when the element is clicked.
onclose Runs JavaScript when a dialog is closed.
oncontextlost Runs JavaScript when a canvas context is lost.
oncontextmenu Runs JavaScript when the context menu is requested, e.g. on right-click.
oncontextrestored Runs JavaScript when a canvas context is restored.
oncopy Runs JavaScript when content is copied.
oncuechange Runs JavaScript when a media text track's cues change.
oncut Runs JavaScript when content is cut.
ondblclick Runs JavaScript when the element is double-clicked.
ondrag Runs JavaScript repeatedly while an element is dragged.
ondragend Runs JavaScript when a drag ends.
ondragenter Runs JavaScript when a dragged item enters a drop target.
ondragleave Runs JavaScript when a dragged item leaves a drop target.
ondragover Runs JavaScript while a dragged item is over a drop target.
ondragstart Runs JavaScript when a drag begins.
ondrop Runs JavaScript when an item is dropped on the element.
ondurationchange Runs JavaScript when media duration changes.
onemptied Runs JavaScript when media is emptied.
onended Runs JavaScript when media finishes playing.
onerror Runs JavaScript when a resource fails to load.
onfocus Runs JavaScript when the element gains focus.
onformdata Runs JavaScript when form data is being gathered.
ongotpointercapture Runs JavaScript when the element gains pointer capture.
onhashchange Runs JavaScript when the URL hash changes.
oninput Runs JavaScript every time an input value changes.
oninvalid Runs JavaScript when a form control fails validation.
onkeydown Runs JavaScript when a key is pressed down.
onkeypress Runs JavaScript when a character key is pressed (deprecated).
onkeyup Runs JavaScript when a key is released.
onlanguagechange Runs JavaScript when the preferred language changes.
onload Runs JavaScript when the element or page finishes loading.
onloadeddata Runs JavaScript when the first media frame is available.
onloadedmetadata Runs JavaScript when media metadata is available.
onloadstart Runs JavaScript when resource loading starts.
onlostpointercapture Runs JavaScript when the element loses pointer capture.
onmessage Runs JavaScript when a message is received.
onmessageerror Runs JavaScript when a received message fails to deserialize.
onmousedown Runs JavaScript when a mouse button is pressed on the element.
onmouseenter Runs JavaScript when the mouse enters the element (does not bubble).
onmouseleave Runs JavaScript when the mouse leaves the element (does not bubble).
onmousemove Runs JavaScript when the mouse moves over the element.
onmouseout Runs JavaScript when the mouse leaves the element.
onmouseover Runs JavaScript when the mouse enters the element.
onmouseup Runs JavaScript when a mouse button is released on the element.
onoffline Runs JavaScript when the browser goes offline.
ononline Runs JavaScript when the browser comes back online.
onpagehide Runs JavaScript when the page is hidden.
onpagereveal Runs JavaScript when a document is first revealed.
onpageshow Runs JavaScript when the page is shown.
onpageswap Runs JavaScript just before a cross-document navigation swaps the page.
onpaste Runs JavaScript when content is pasted.
onpause Runs JavaScript when media is paused.
onplay Runs JavaScript when media starts playing.
onplaying Runs JavaScript when media begins playing after a stall.
onpointercancel Runs JavaScript when a pointer interaction is canceled.
onpointerdown Runs JavaScript when a pointer is pressed on the element.
onpointerenter Runs JavaScript when a pointer enters the element (does not bubble).
onpointerleave Runs JavaScript when a pointer leaves the element (does not bubble).
onpointermove Runs JavaScript when a pointer moves over the element.
onpointerout Runs JavaScript when a pointer leaves the element.
onpointerover Runs JavaScript when a pointer enters the element.
onpointerup Runs JavaScript when a pointer is released on the element.
onpopstate Runs JavaScript on history navigation.
onprogress Runs JavaScript periodically while a resource loads.
onratechange Runs JavaScript when the playback speed changes.
onrejectionhandled Runs JavaScript when a late promise-rejection handler runs.
onreset Runs JavaScript when a form is reset.
onresize Runs JavaScript when the window is resized.
onscroll Runs JavaScript when the element is scrolled.
onscrollend Runs JavaScript when scrolling ends.
onsearch Runs JavaScript when a search input is submitted or cleared (non-standard).
onsecuritypolicyviolation Runs JavaScript when a CSP violation occurs.
onseeked Runs JavaScript when seeking finishes.
onseeking Runs JavaScript when seeking starts.
onselect Runs JavaScript when text is selected in a field.
onselectionchange Runs JavaScript when the selection changes.
onslotchange Runs JavaScript when a slot's assigned content changes.
onstalled Runs JavaScript when media data stalls.
onstorage Runs JavaScript when storage changes in another tab.
onsubmit Runs JavaScript when a form is submitted.
onsuspend Runs JavaScript when media loading is suspended.
ontimeupdate Runs JavaScript as the media playback position changes.
ontoggle Runs JavaScript when a <details> or popover toggles open/closed.
ontouchcancel Runs JavaScript when a touch is interrupted.
ontouchend Runs JavaScript when a touch ends on the element.
ontouchmove Runs JavaScript when a touch moves on the element.
ontouchstart Runs JavaScript when a touch begins on the element.
ontransitioncancel Runs JavaScript when a CSS transition is canceled.
ontransitionend Runs JavaScript when a CSS transition finishes.
ontransitionrun Runs JavaScript when a CSS transition is created.
ontransitionstart Runs JavaScript when a CSS transition starts.
onunhandledrejection Runs JavaScript when a promise rejection goes unhandled.
onunload Runs JavaScript while the page is unloading (deprecated/discouraged).
onvolumechange Runs JavaScript when volume changes.
onwaiting Runs JavaScript when media is buffering.
onwheel Runs JavaScript when the wheel is scrolled over the element.