HTML Event Attributes
HTML Event Attributes
To learn more about programming events, please visit our JavaScript tutorial.
Below are the global event attributes that can be added to HTML elements to define event actions.
onhashchange script Script to be run when there has been changes to the anchor
part of the a URL
ononline script Script to be run when the browser starts to work online
onpagehide script Script to be run when a user navigates away from a page
onunload script Fires once a page has unloaded (or the browser window has
been closed)
Form Events
Events triggered by actions inside a HTML form (applies to almost all HTML elements, but is most
used in form elements):
onblur script Fires the moment that the element loses focus
onchange script Fires the moment when the value of the element is changed
onsearch script Fires when the user writes something in a search field (for
<input="search">)
onselect script Fires after some text has been selected in an element
Keyboard Events
Mouse Events
onmousemove script Fires when the mouse pointer is moving while it is over an
element
onmouseout script Fires when the mouse pointer moves out of an element
onmouseover script Fires when the mouse pointer moves over an element
Drag Events
ondragenter script Script to be run when an element has been dragged to a valid
drop target
ondragleave script Script to be run when an element leaves a valid drop target
ondragover script Script to be run when an element is being dragged over a valid
drop target
Clipboard Events
oncopy script Fires when the user copies the content of an element
oncut script Fires when the user cuts the content of an element
onpaste script Fires when the user pastes some content in an element
Media Events
Events triggered by medias like videos, images and audio (applies to all HTML elements, but is most
common in media elements, like <audio>, <embed>, <img>, <object>, and <video>).
Tip: Look at our HTML Audio and Video DOM Reference for more information.
oncanplay script Script to be run when a file is ready to start playing (when it
has buffered enough to begin)
oncanplaythrough script Script to be run when a file can be played all the way to the
end without pausing for buffering
oncuechange script Script to be run when the cue changes in a <track> element
ondurationchange script Script to be run when the length of the media changes
onemptied script Script to be run when something bad happens and the file
is suddenly unavailable (like unexpectedly disconnects)
onended script Script to be run when the media has reach the end (a
useful event for messages like "thanks for listening")
onerror script Script to be run when an error occurs when the file is being
loaded
onloadedmetadata script Script to be run when meta data (like dimensions and
duration) are loaded
onloadstart script Script to be run just as the file begins to load before
anything is actually loaded
onpause script Script to be run when the media is paused either by the
user or programmatically
onplay script Script to be run when the media is ready to start playing
onplaying script Script to be run when the media actually has started
playing
onratechange script Script to be run each time the playback rate changes (like
when a user switches to a slow motion or fast forward
mode)
onseeked script Script to be run when the seeking attribute is set to false
indicating that seeking has ended
onseeking script Script to be run when the seeking attribute is set to true
indicating that seeking is active
onstalled script Script to be run when the browser is unable to fetch the
media data for whatever reason
onsuspend script Script to be run when fetching the media data is stopped
before it is completely loaded for whatever reason
ontimeupdate script Script to be run when the playing position has changed
(like when the user fast forwards to a different point in the
media)
onvolumechange script Script to be run each time the volume is changed which
(includes setting the volume to "mute")
onwaiting script Script to be run when the media has paused but is
expected to resume (like when the media pauses to buffer
more data)
Misc Events
ontoggle script Fires when the user opens or closes the <details> element
❮ Previous Next ❯
COLOR PICKER
LIKE US
Get certified
by completing
a course today!
Get started
CODE GAME
Play Game
Report Error
Forum
About
Shop
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Bootstrap Reference
PHP Reference
HTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples
Web Courses
HTML Course
CSS Course
JavaScript Course
Front End Course
SQL Course
Python Course
PHP Course
jQuery Course
Java Course
C++ Course
C# Course
XML Course
Get Certified »