HTML5 Reference – Event Attributes


What is an Event ?

Whatever thing that happens is an event.

What is an HTML Event ?

Something happens in the browser is called as an HTML event.

When the browser loads or user submits a form its called HTML event.

In HTML5 there are lots of event attributes available which can executed with client-side scripting language such as JavaScript.

1. Windows Event Attributes

2. Form Event Attributes

3. Keyboard Event Attributes

4. Mouse Event Attributes

5. Clipboard Event Attributes

6. Media Event Attributes

7. Other Event Attributes

Tutorial on html !!!

Click to Learn More about – HTML Tutorial for beginners

1. Windows Event Attributes

Windows events are related to the window objects.


This can only be applied inside <body> tag.

Sno AttributeDescription
1onafterprintExecuted when the document is printed.( New attribute in HTML5).
2onbeforeprintExecuted before the document is printed.( New attribute in HTML5).
3onbeforeunloadExecuted when the document is about to get unloaded (when a user is about to quit the page before it is loaded). (New attribute in HTML5).
4onblurExecuted when a window loses focus.
5onerrorExecuted when an error occurs when downloading the document.( New attribute in HTML5).
6onhashchangeExecuted when the anchor in URL of a web page is changed (anchor comes after #). (New attribute in HTML5).
7onloadExecuted when content of a web page is entirely loaded eg (images, CSS styles and scripts).
8onmessageExecuted when a message is triggered.(New attribute in HTML5).
9onofflineExecuted when the browser works offline.(New attribute in HTML5).
10ononlineExecuted when the browser works online.(New attribute in HTML5).
11onpagehideExecuted when a user go away from the web page.(New attribute in HTML5).
12onpageshowExecuted when a user navigates to a web page.(New attribute in HTML5).
13onpopstateExecuted when the window’s history is changed.(New attribute in HTML5).
14onredoExecuted when a “Redo” option is used ( the last action is reversed).(New attribute in HTML5).
15onresizeExecuted when a window is resized.(New attribute in HTML5).
16onstorageExecuted when a web storage is updated.(New attribute in HTML5).
17onundoExecuted when the last action is cancelled (“undo” command).(New attribute in HTML5).
18onunloadExecuted when a web page is unloaded (closed).

2. Form Event Attributes

Form event occurs when the user performs some action like submitting the form, selecting input field in the form.


Form events can be used with any HTML form elements.

SnoAttributeDescription
1onblurExecuted when a form element loses focus.
2onchangeExecuted when the value of the element is changed.
3oncontextmenu Executed when the context menu is shown.(New attribute in HTML5).
4onfocusExecuted when an element gets focus.
5oninputExecuted when an element gets user input.(New attribute in HTML5).
6oninvalidExecuted if an input element is invalid.(New attribute in HTML5).
7onresetExecuted when a form is reset (all controls within the form are set to their initial values).(New attribute in HTML5).
8onsearchExecuted when the user writes something in a search field (for <input=”search”>).
9onselectExecuted when some text is selected in an element.
10onsubmitExecuted when a form is sent.

3. Keyboard Event Attributes

Keyboard event occurs when a user interacts with the keyboard.

SnoAttributeDescription
1onkeydownExecuted when the user is pressing any key on the keyboard.
2onkeypressExecuted when the user has pressed a key on the keyboard. (doesn’t work with Alt, Ctrl, Shift, Esc, PrScr).
3onkeyupExecuted when a pressed key is released.

4. Mouse Event Attributes

Mouse event occurs when a user interacts with the mouse.

SnoAttributeDescription
1onclickExecuted when a mouse-button is clicked.
2ondblclickExecuted when a mouse-button is clicked twice.
3ondragExecuted when an element is being dragged.(New attribute in HTML5).
4ondragendExecuted when an element has been dragged.(New attribute in HTML5).
5ondragenterExecuted when a dragged element enters a valid drop target.(New attribute in HTML5).
6ondragleaveExecuted when a dragged element leaves a valid drop target.(New attribute in HTML5).
7ondragoverExecuted when a dragged element being dragged over a valid drops target (every few hundred milliseconds).(New attribute in HTML5)
8ondragstartExecuted when the user starts dragging an element.(New attribute in HTML5).
9ondropExecuted when the user drops dragging an element.(New attribute in HTML5).
10onmousedownExecuted when a mouse button is pressed.
11onmousemoveExecuted when the mouse pointer is moved onto the element.
12onmouseoutExecuted when the mouse pointer moves out of an element.
13onmouseoverExecuted when the mouse pointer is moved onto an element.
14onmouseupExecuted when a mouse button is released.
15onmousewheelExecuted when the mouse wheel rolls up or down over an element.
Obsolete attribute (use onwheel attribute instead).
16onscrollExecuted when an element’s scrollbar is being scrolled.(New attribute in HTML5).
17onwheelExecuted when the mouse wheel rolls up or down over an element.(New attribute in HTML5).

5. Clipboard Event Attributes

SnoAttributeDescription
1oncopyExecuted when the content of an element is copied.
2oncutExecuted when the content of an element is cut.
3onpasteExecuted when the content of an element is pasted.

6. Media Event Attributes

Media-files events occur in media elements, like video, image, audio etc.

SnoAttributeDescription
1onabortExecuted when the loading of an audio/video is aborted.(New attribute in HTML5).
2oncanplayExecuted when the file is ready to start playing (has buffered enough to start playing).(New attribute in HTML5).
3oncanplaythroughExecuted when the file is ready to be played from start to end without stopping for buffering.(New attribute in HTML5).
4oncuechangeExecuted when the duration of the media is changed.(New attribute in HTML5).
5onemptiedExecuted when something happens and the file is unavailable (e.g., when the Internet connection is lost).(New attribute in HTML5).
6onendedExecuted when a media file reached the end.(New attribute in HTML5).
7onerrorExecuted when an error occurs when the file is being loaded.(New attribute in HTML5).
8onloadeddataExecuted when media data is loaded.(New attribute in HTML5).
9onloadedmetadataExecuted when metadata (size of media files, duration, etc. ) is loaded.(New attribute in HTML5).
10onloadstartExecuted when the browser starts downloading media data.(New attribute in HTML5).
11onpauseExecuted when the mediafile is paused.(New attribute in HTML5).
12onplayExecuted when the file is ready to start playing.(New attribute in HTML5).
13onplayingExecuted when the file starts playing.(New attribute in HTML5).
14onprogressExecuted when the browser is in process of getting media data.(New attribute in HTML5).
15onratechangeExecuted each time, when the playing mode is changed (e.g. user switches fast forward or slow motion mode).(New attribute in HTML5)
16onseekedExecuted when the seeking attribute of the <audio> or <video> tags is set to false indicating that seeking has ended.(New attribute in HTML5).
17onseekingExecuted when the seeking attribute of the <audio> or <video> tags is set to false indicating that seeking is active.(New attribute in HTML5).
18onstalledExecuted when the browser cannot get media data for whatever reason.(New attribute in HTML5).
19onsuspendExecuted when the browser has already started extracting media data, but the process was suspended before the data is completely loaded.(New attribute in HTML5).
20ontimeupdateExecuted when the playing position is changed.(New attribute in HTML5).
21onvolumechangeExecuted each time when the volume is changed (includes setting the volume to “mute”).(New attribute in HTML5).
22onwaitingExecuted when media file is suspended, but is about to resume (e.g., when the file is paused for buffering).(New attribute in HTML5).

Tutorial on html !!!

Click to Learn More about – HTML Tutorial for beginners

7. Other Events Attributes

SnoAttributeDescription
1onerrorExecuted when an error occurs when downloading external file.
2onshowExecuted when the <menu> is shown as a context menu.(New attribute in HTML5).
3ontoggleExecuted when a user opens or closes the <details>.(New attribute in HTML5).