HTML Event Reference

Events are actions or occurrences detected by the browser, such as a user clicking a button, entering text, submitting a form, pressing a key, or loading a page.

JavaScript can listen for these events and respond when they occur. HTML also provides event handler attributes such as onclick, oninput, and onsubmit, although JavaScript event listeners are generally preferred for separating behavior from HTML markup.

Mouse Events

Mouse events occur when a pointing device interacts with an element, including clicking, double-clicking, and moving the pointer over or away from an element.

Event Handler Description Example
clickonclickOccurs when an element is clicked.Play in Editor
dblclickondblclickOccurs when an element is double-clicked.Play in Editor
mousedownonmousedownOccurs when a pointing-device button is pressed over an element.Play in Editor
mouseuponmouseupOccurs when a pointing-device button is released over an element.Play in Editor
mousemoveonmousemoveOccurs when the pointer moves over an element.Play in Editor
mouseoveronmouseoverOccurs when the pointer enters an element or one of its descendants.Play in Editor
mouseoutonmouseoutOccurs when the pointer leaves an element or enters one of its descendants.Play in Editor
mouseenteronmouseenterOccurs when the pointer enters an element.Play in Editor
mouseleaveonmouseleaveOccurs when the pointer leaves an element.Play in Editor
contextmenuoncontextmenuOccurs when the user requests a context menu.Play in Editor
wheelonwheelOccurs when a mouse wheel or similar input device is used.Play in Editor

Keyboard Events

Keyboard events occur when a user presses or releases a key while interacting with the webpage.

Event Handler Description Example
keydownonkeydownOccurs when a key is pressed.Play in Editor
keyuponkeyupOccurs when a pressed key is released.Play in Editor

The older keypress event is deprecated and should not be used for new webpages. Use keydown or keyup instead.

Form & Input Events

Form and input events occur when users enter data, change form controls, submit forms, or reset form values.

Event Handler Description Example
inputoninputOccurs when the value of an editable control changes through user input.Play in Editor
changeonchangeOccurs when the value of a form control is committed or changed.Play in Editor
submitonsubmitOccurs when a form is submitted.Play in Editor
resetonresetOccurs when a form is reset.Play in Editor
invalidoninvalidOccurs when a form control fails constraint validation.Play in Editor
selectonselectOccurs when text is selected in certain editable controls.Play in Editor

Focus Events

Focus events occur when an element receives or loses keyboard or programmatic focus.

Event Handler Description Example
focusonfocusOccurs when an element receives focus.Play in Editor
bluronblurOccurs when an element loses focus.Play in Editor
focusinonfocusinOccurs when an element or one of its descendants receives focus.Play in Editor
focusoutonfocusoutOccurs when an element or one of its descendants loses focus.Play in Editor

Clipboard Events

Clipboard events occur when content is copied, cut, or pasted using the clipboard.

Event Handler Description Example
copyoncopyOccurs when content is copied.Play in Editor
cutoncutOccurs when content is cut.Play in Editor
pasteonpasteOccurs when content is pasted.Play in Editor

Drag & Drop Events

Drag-and-drop events are generated while draggable content is picked up, moved, placed over a potential drop target, or dropped.

Event Handler Description Example
dragondragOccurs while an element is being dragged.Play in Editor
dragstartondragstartOccurs when a drag operation begins.Play in Editor
dragendondragendOccurs when a drag operation ends.Play in Editor
dragenterondragenterOccurs when dragged content enters a potential drop target.Play in Editor
dragleaveondragleaveOccurs when dragged content leaves a potential drop target.Play in Editor
dragoverondragoverOccurs while dragged content is over a potential drop target.Play in Editor
dropondropOccurs when dragged content is dropped onto a drop target.Play in Editor

Media Events

Audio and video elements generate events as media loads, plays, pauses, seeks, changes volume, and reaches the end of playback.

Event Handler Description Example
canplayoncanplayOccurs when enough media data is available to begin playback.Play in Editor
durationchangeondurationchangeOccurs when the media duration changes.Play in Editor
endedonendedOccurs when playback reaches the end of the media.Play in Editor
loadeddataonloadeddataOccurs when the current media frame has loaded.Play in Editor
loadedmetadataonloadedmetadataOccurs when media metadata has loaded.Play in Editor
pauseonpauseOccurs when playback is paused.Play in Editor
playonplayOccurs when playback begins or resumes.Play in Editor
playingonplayingOccurs when playback is ready to continue after being paused or delayed.Play in Editor
progressonprogressOccurs while the browser is loading media data.Play in Editor
ratechangeonratechangeOccurs when the playback rate changes.Play in Editor
seekedonseekedOccurs when a seek operation has completed.Play in Editor
seekingonseekingOccurs when a seek operation begins.Play in Editor
timeupdateontimeupdateOccurs when the current playback position changes.Play in Editor
volumechangeonvolumechangeOccurs when the volume or muted state changes.Play in Editor
waitingonwaitingOccurs when playback stops temporarily because more data is needed.Play in Editor

Window & Document Events

Window and document-related events can indicate when resources load, errors occur, the page is resized or scrolled, or other browser-level activity takes place.

Event Handler Description Example
loadonloadOccurs when a resource has finished loading.Play in Editor
erroronerrorOccurs when an error happens while loading or processing a resource.Play in Editor
resizeonresizeOccurs when the browser viewport is resized.Play in Editor
scrollonscrollOccurs when a document or element is scrolled.Play in Editor
beforeunloadonbeforeunloadOccurs before the document is about to be unloaded.Play in Editor
hashchangeonhashchangeOccurs when the fragment identifier in the URL changes.Play in Editor
onlineononlineOccurs when the browser reports that network access has been restored.Play in Editor
offlineonofflineOccurs when the browser reports that network access has been lost.Play in Editor

Using Event Handlers

An HTML event handler attribute places JavaScript directly in the element. For example, the onclick attribute can respond when a button is activated.

<button type="button" onclick="alert('Hello!')">Click Me</button>

For larger scripts, JavaScript can register an event listener instead. This keeps the HTML markup separate from the behavior of the page.

<button type="button" id="example-button">Click Me</button>

<script>
const button = document.querySelector('#example-button');

button.addEventListener('click', function () {
  alert('Hello!');
});
</script>

Event listeners can also make it easier to attach multiple handlers and manage event behavior without adding JavaScript to individual HTML attributes.