Skip to main content
Syllabus
On this page

HTML Events Reference

Badar KhalilUpdated September 27, 2026 2 min read

HTML Events Reference

This HTML events reference covers every major event type available in HTML5, showing you how to detect and respond to user actions like clicks, key presses, form changes, and page loading. Understanding HTML events is essential for building interactive, responsive web pages.

What Are HTML Events?

An HTML event is something that happens to an element — the user clicks a button, a page finishes loading, a value changes in a form field. JavaScript can 'listen' for these events and run code in response, using either inline event attributes or the modern addEventListener() method.

1. Mouse Events

EventDescription
onclickFires when an element is clicked
ondblclickFires on double-click
onmousedownFires when a mouse button is pressed down
onmouseupFires when a mouse button is released
onmouseoverFires when the pointer enters an element
onmouseoutFires when the pointer leaves an element
onmousemoveFires continuously as the pointer moves over an element

2. Keyboard Events

EventDescription
onkeydownFires when a key is pressed down
onkeyupFires when a key is released
onkeypressFires while a key is being pressed (deprecated in favor of keydown)

3. Form Events

EventDescription
onsubmitFires when a form is submitted
onchangeFires when an input's value changes and loses focus
oninputFires immediately as an input's value changes
onfocusFires when an element gains focus
onblurFires when an element loses focus
onresetFires when a form is reset
oninvalidFires when a form field fails validation

4. Window and Document Events

EventDescription
onloadFires when the page has fully loaded
onresizeFires when the browser window is resized
onscrollFires when an element or the page is scrolled
onunloadFires when the user leaves the page
onbeforeunloadFires just before the page is unloaded, often used for exit prompts

5. Drag and Drop Events

EventDescription
ondragstartFires when the user starts dragging an element
ondragoverFires when a dragged item is over a valid drop target
ondropFires when the dragged item is dropped
ondragendFires when the drag operation finishes

6. Clipboard and Touch Events

EventDescription
oncopyFires when content is copied
oncutFires when content is cut
onpasteFires when content is pasted
ontouchstartFires when a touch point is placed on a touch surface
ontouchendFires when a touch point is removed

Inline vs addEventListener

While inline attributes like onclick="..." work directly in HTML, modern development favors addEventListener() because it keeps JavaScript separate from markup and allows multiple handlers on the same element.

Try It Yourself

Use the live, editable examples below to practice handling different HTML events.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself HTML
Output

Press Run to execute.

Try it Yourself JAVASCRIPT
Output

Press Run to execute.

Exercise: Build a Live Character CounterHTML

Create a textarea and a paragraph below it. Using the oninput event, update the paragraph in real time to show how many characters the user has typed.

Try it Yourself HTML
Output

Press Run to execute.

Show expected output
The character count updates live as the user types in the textarea.

This is a self-check — compare your result with the expected output above.

Was this page helpful?