Go to main content
Bypass navigation bar HTML Reference HTML Tags HTML Tutorials
Bypass language selection
Bypass location bar

Location: Home > HTML Reference > Events in HTML

Bypass main content

Events in HTML

Events are a feature of HTML documents (present in other programming languages too) that allow authors to add interactivity between the website and it's visitors, by executing client-side programs when the visitor (or other program) performs an action. For example, the author can make a paragraph change the color of its text when the user puts the mouse pointer over it.

As well as attributes, events can be easily defined in an element's start tag, with the same format:

<tag_name event_name="code">

The content of the event is the code to be executed, and must be created using a cleint-side language (e.g., JavaScript) that must be supported by the browser. In the next example, we define a paragraph that changes the color of its text to red when the mouse passes over, and to black when it goes away.

Code
<p onmouseover="this.style.color='red'" onmouseout="this.style.color='black'">This is a changing color text. Try it!</p>
View

This is a changing color text. Try it!

List of events

Below there is al list of all events available for the HTML 4.01 and XHTML 1.0 standards.

  • onload: The onload event is triggered when the user agent finishes loading a window or all frames within a frameset. This event is exclusive of the HTML body element and the HTML framset element.
  • onunload: The onunload event is fired when the user agent removes a document from a window or frame. This event is exclusive of the HTML body element and the HTML framset element.
  • onclick: The onclick event occurs when the mouse button is clicked over the element.
  • ondblclick: The ondblclick event is executed when the pointing device button is double clicked over the element.
  • onmousedown: The onmousedown is triggered when the mouse button is pressed over the element.
  • onmouseup: The onmouseup event is fired when the pointing device button is released over the element.
  • onmouseover: The onmouseover event occurs when the mouse is moved onto the element.
  • onmousemove: The onmousemove event is executed when the pointing device is moved while it is over the element.
  • onmouseout: The onmouseout event is triggered when the mouse is moved away from the element.
  • onfocus: The onfocus event is fired when an element receives focus either by the pointing device or by tabbing navigation. This attribute is exclusive of those elements that can get the focus.
  • onblur: The onblur event occurs when the element losses focus either by the pointing device or by tabbing navigation. This attribute is exclusive of those elements that can get the focus: HTML a element, HTML area element, HTML label element, HTML input element, HTML select element, HTML textarea element, and HTML button element.
  • onkeypress: The onkeypress event is executed when a key is pressed and released while the element is focused. This attribute is exclusive of those elements that can get the focus: HTML a element, HTML area element, HTML label element, HTML input element, HTML select element, HTML textarea element, and HTML button element.
  • onkeydown: The onkeydown event is triggered when a key is pressed down while the element is focused.
  • onkeyup: The onkeyup event is fired when a key is released while the element is focused.
  • onsubmit: The onsubmit event occurs when the form is submitted. This attribute is exclusive of those elements that can get the focus. This event is exclusive of the HTML form element.
  • onreset: The onreset event is executed when the form is reset. This event is exclusive of the HTML form element.
  • onselect: The onselect event is triggered when a user selects some text in the text field. This event is exclusive of the HTML input element and the HTML textarea element.
  • onchange: The onchange event is fired when a control losses the input focus and its value has been modified since gaining focus. This event is exclusive of the HTML input element, the HTML select element and the HTML textarea element.

Note, that not all elements support every event in this list. To know which events are supported by a specific element, refer to the HTML tags reference and follow its link.

Diseño y desarrollo: Latitud29.com

Links and logos|Contact|Beyond HTML|Tools and resources|Sitemap|Webmaster|Donate