Wednesday, August 15, 2012

HTML / XHTML Standard Event Attributes


Standard Event Attributes

HTML 4 added the ability to let events trigger actions in a browser, like starting a JavaScript when a user clicks on an element.

To learn more about programming events, please visit our JavaScript tutorial and our DHTML tutorial.
Below is the standard event attributes that can be inserted into HTML / XHTML elements to define event actions.


<body> and <frameset> Events

The two attributes below can only be used in <body> or <frameset>:

AttributeValueDescription
onloadscriptScript to be run when a document load
onunloadscriptScript to be run when a document unload


Form Events

The attributes below can be used in form elements:

AttributeValueDescription
onblurscriptScript to be run when an element loses focus
onchangescriptScript to be run when an element changes
onfocusscriptScript to be run when an element gets focus
onresetscriptScript to be run when a form is reset
onselectscriptScript to be run when an element is selected
onsubmitscriptScript to be run when a form is submitted


Image Events

The attribute below can be used with the img element:

AttributeValueDescription
onabortscriptScript to be run when loading of an image is interrupted


Keyboard Events

Valid in all elements except base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title.

AttributeValueDescription
onkeydownscriptScript to be run when a key is pressed
onkeypressscriptScript to be run when a key is pressed and released
onkeyupscriptScript to be run when a key is released


Mouse Events

Valid in all elements except base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title.

AttributeValueDescription
onclickscriptScript to be run on a mouse click
ondblclickscriptScript to be run on a mouse double-click
onmousedownscriptScript to be run when mouse button is pressed
onmousemovescriptScript to be run when mouse pointer moves
onmouseoutscriptScript to be run when mouse pointer moves out of an element
onmouseoverscriptScript to be run when mouse pointer moves over an element
onmouseupscriptScript to be run when mouse button is released


HTML Attributes


The attributes listed below are standard, and can be used in nearly all HTML/XHTML tags.

Core Attributes

Valid in all elements, except: <base>, <head>, <html>, <meta>, <param>, <script>, <style>, and <title>.

AttributeDescription
classSpecifies one or more classnames for an element (refers to a class in a style sheet)
idSpecifies a unique id for an element
styleSpecifies an inline CSS style for an element
titleSpecifies extra information about an element


Language Attributes

Valid in all elements, except: <base>, <br>, <frame>, <frameset>, <hr>, <iframe>, <param>, and <script>.

AttributeDescription
dirSpecifies the text direction for the content in an element
langSpecifies the language of the element's content
xml:langSpecifies the language of the element's content (for XHTML documents)


Keyboard Attributes

AttributeDescription
accesskeySpecifies a shortcut key to activate/focus an element
tabindexSpecifies the tabbing order of an element

HTML Tags


Ordered Alphabetically

DTD: indicates in which HTML 4.01 / XHTML 1.0 DTD the tag is allowed. S=Strict, T=Transitional, and F=Frameset

TagDescriptionDTD
<!--...-->Defines a commentSTF
<!DOCTYPE> Defines the document typeSTF
<a>Defines an anchorSTF
<abbr>Defines an abbreviationSTF
<acronym>Defines an acronymSTF
<address>Defines contact information for the author/owner of a documentSTF
<applet>Deprecated. Defines an embedded appletTF
<area />Defines an area inside an image-mapSTF
<b>Defines bold textSTF
<base />Specifies the base URL/target for all relative URLs in a documentSTF
<basefont />Deprecated. Specifies a default color, size, or font for all the text in a documentTF
<bdo>Overrides the current text directionSTF
<big>Defines big textSTF
<blockquote>Defines a long quotationSTF
<body>Defines the document's bodySTF
<br />Defines a single line breakSTF
<button>Defines a clickable buttonSTF
<caption>Defines a table captionSTF
<center>Deprecated. Defines centered textTF
<cite>Defines a citationSTF
<code>Defines a piece of computer codeSTF
<col />Defines attribute values for one or more columns in a table STF
<colgroup>Specifies a group of one or more columns in a table for formattingSTF
<dd>Defines a description of an item in a definition listSTF
<del>Defines text that has been deleted from a documentSTF
<dfn>Defines a definition termSTF
<dir>Deprecated. Defines a directory listTF
<div>Defines a section in a documentSTF
<dl>Defines a definition listSTF
<dt>Defines a term (an item) in a definition listSTF
<em>Defines emphasized text STF
<fieldset>Groups related elements in a formSTF
<font>Deprecated. Defines font, color, and size for textTF
<form>Defines an HTML form for user inputSTF
<frame />Defines a window (a frame) in a framesetF
<frameset>Defines a set of framesF
<h1> to <h6>Defines HTML headingsSTF
<head>Defines information about the documentSTF
<hr />Defines a horizontal lineSTF
<html>Defines the root of an HTML documentSTF
<i>Defines italic textSTF
<iframe>Defines an inline frameTF
<img />Defines an imageSTF
<input />Defines an input controlSTF
<ins>Defines text that has been inserted into a documentSTF
<kbd>Defines keyboard inputSTF
<label>Defines a label for an <input> elementSTF
<legend>Defines a caption for a <fieldset> elementSTF
<li>Defines a list itemSTF
<link />Defines the relationship between a document and an external resourceSTF
<map>Defines a client-side image-map STF
<menu>Deprecated. Defines a menu listTF
<meta />Defines metadata about an HTML documentSTF
<noframes>Defines an alternate content for users that do not support framesTF
<noscript>Defines an alternate content for users that do not support client-side scriptsSTF
<object>Defines an embedded objectSTF
<ol>Defines an ordered listSTF
<optgroup>Defines a group of related options in a drop-down listSTF
<option>Defines an option in a drop-down listSTF
<p>Defines a paragraphSTF
<param />Defines a parameter for an objectSTF
<pre>Defines preformatted textSTF
<q>Defines a short quotationSTF
<s>Deprecated. Defines strikethrough textTF
<samp>Defines sample output from a computer programSTF
<script>Defines a client-side scriptSTF
<select>Defines a drop-down listSTF
<small>Defines smaller textSTF
<span>Defines a section in a documentSTF
<strike>Deprecated. Defines strikethrough textTF
<strong>Defines strong textSTF
<style>Defines style information for a documentSTF
<sub>Defines subscripted textSTF
<sup>Defines superscripted textSTF
<table>Defines a tableSTF
<tbody>Groups the body content in a tableSTF
<td>Defines a cell in a tableSTF
<textarea>Defines a multiline input control (text area)STF
<tfoot>Groups the footer content in a tableSTF
<th>Defines a header cell in a tableSTF
<thead>Groups the header content in a tableSTF
<title>Defines a title for the documentSTF
<tr>Defines a row in a tableSTF
<tt>Defines teletype textSTF
<u>Deprecated. Defines underlined textTF
<ul>Defines an unordered listSTF
<var>Defines a variableSTF
<xmp>Deprecated. Defines preformatted text 

HTML Examples


HTML Basic


HTML Headings


HTML Paragraphs


HTML Text Formatting


HTML Styles


HTML Links


HTML Images


HTML Tables


HTML Lists


HTML Forms and Input


HTML IFrame


HTML head Elements


HTML Scripts