The attributes are special words used inside the opening tag to control the element's behaviour. HTML attribute is a modifier of an HTML element type. An attribute either modifies the default functionality of an element type or provides functionality to certain element types unable to function correctly without them. In HTML syntax, an attribute is added to an HTML start tag.
Several basic attributes types have been recognized, including: (1) required attributes, needed by a particular element type for that element type to function correctly; (2) optional attributes, used to modify the default functionality of an element type; (3) standard attributes, supported by a large number of element types; and (4) event attributes, used to cause element types to specify scripts to be run under specific circumstances.
Some attribute types function differently when used to modify different element types. For example, the attribute name is used by several element types, but has slightly different functions in each.
Video HTML attribute
Description
HTML attributes generally appear as name-value pairs, separated by =
, and are written within the start tag of an element, after the element's name:
Where element
names the HTML element type, and attribute
is the name of the attribute, set to the provided value
. The value may be enclosed in single or double quotes, although values consisting of certain characters can be left unquoted in HTML (but not XHTML). Leaving attribute values unquoted is considered unsafe.
Although most attributes are provided as paired names and values, some affect the element simply by their presence in the start tag of the element (like the ismap
attribute for the img
element).
Most elements can take any of several common attributes:
- The
id
attribute provides a document-wide unique identifier for an element. This can be used as CSS selector to provide presentational properties, by browsers to focus attention on the specific element, or by scripts to alter the contents or presentation of an element. Appended to the URL of the page, the URL directly targets the specific element within the document, typically a sub-section of the page. For example, the ID "Attributes" inhttp://en.wikipedia.org/wiki/HTML#Attributes
- The
class
attribute provides a way of classifying similar elements. This can be used for semantic purposes, or for presentation purposes. Semantically, for example, classes are used in microformats. Presentationally, for example, an HTML document might use the designationclass="notation"
to indicate that all elements with this class value are subordinate to the main text of the document. Such elements might be gathered together and presented as footnotes on a page instead of appearing in the place where they occur in the HTML source. Another presentation use would be as a CSS selector. - An author may use the
style
non-attributal codes presentational properties to a particular element. It is considered better practice to use an element'sid
orclass
attributes to select the element with a stylesheet, though sometimes this can be too cumbersome for a simple and specific or ad hoc application of styled properties. - The
title
attribute is used to attach subtextual explanation to an element. In most browsers this attribute is displayed as what is often referred to as a tooltip.
The abbreviation element, abbr
, can be used to demonstrate these various attributes:
This example displays as HTML, and in most browsers, pointing the cursor at the abbreviation should display the title text "Hypertext Markup Language."
Most elements also take the language-related attributes lang
and dir
.
Maps HTML attribute
Varieties
HTML attributes are generally classed as required attributes, optional attributes, standard attributes, and event attributes. Usually the required and optional attributes modify specific HTML elements, while the standard attributes can be applied to most HTML elements. Event attributes, added in HTML version 4, allow an element to specify scripts to be run under specific circumstances.
Required and optional
Used by one element
- <applet>: code, object
- <area>: nohref
- <body>: alink, background, link, text, vlink
- <form>: accept-charset, action, enctype, method
- <frame>: noresize
- <head>: profile
- <hr>: noshade
- <html>: xmlns
- <img>: ismap
- <input>: checked, maxlength
- <label>: for
- <meta>: content, http-equiv, scheme
- <object>: classid, codetag, data, declare, standby
- <ol>: start
- <option>: selected
- <param>: valuetype
- <script>: defer, xml:space
- <select>: multiple
- <table>: cellpadding, cellspacing, frame, rules, summary
- <td>: headers
Used by two elements
- <a> and <area>:
- coords -- coordinates of an <area> or a <link> within it.
- shape -- shape of an <area> or a <link> within it. Values: default, rect, circle, poly.
- <a> and <link>:
- hreflang -- Language code of the linked document. (<a>, <link>)
- rel -- Nature of the linked document (relative to the page currently displayed). Free text for <a>, but <link> uses a set of terms (alternate, appendix, bookmark, chapter, contents, copyright, glossary, help, home, index, next, prev, section, start, stylesheet, subsection).
- rev -- Nature of the currently displayed page (relative to the linked document). Varies for <a> and <link> as for rel.
- <applet> and <object>:
- archive -- archive URL(s) (<applet>, <object>)
- codebase -- base URL (<applet>, <object>)
- <basefont> and <font>:
- color -- text color (deprecated) (<basefont>, <font>)
- face -- font family (deprecated) (<basefont>, <font>)
- <col> and <colgroup>:
- span -- number of columns spanned (<col>, <colgroup>)
- <del> and <ins>:
- datetime -- date and time of text deletion or insertion.
- <form> and <input>:
- accept -- types of files accepted when uploading <form> or <input>
- <frame> and <iframe>:
- frameborder -- value (0 or 1) specifies whether to display a border around the <frame> or <iframe>.
- marginheight -- top and bottom margins in pixels around the <frame> or <iframe>.
- scrolling -- value (yes, no, auto) specifies whether to display scroll bars around the <frame> or <iframe>.
- marginwidth -- left and right margins in pixels around the <frame> or <iframe>.
- <frameset> and <textarea>:
- cols -- number of visible columns in <frameset> or <textarea> (some variation)
- rows -- number of visible rows in <frameset> or <textarea> (some variation)
- <img> and <object>:
- usemap -- specifies name of a map element to use with <img> -or- URL of an image-map to use with <object>.
- <input> and <textarea>:
- readonly -- specifies read-only text for <input> and <textarea>.
- <link> and <style>:
- media -- specifies display device for <link> and <style>. Values: all, aural, braille, handheld, print, projection, screen, tty, TV.
- <optgroup> and <option>:
- label -- description text for an <optgroup> or <option>.
- <td> and <th>:
- abbr -- abbreviated version of a table cell or header.
- axis -- category name for a table cell or header.
- colspan -- number of columns spanned by a table cell or header.
- nowrap -- (deprecated) prevents wrapping of a table cell or header.
- rowspan -- number of rows spanned by a table cell or header.
- scope -- no effect on normal browser display, but marks a table cell or header as a logical header for other cells. Values: col, colgroup, row, rowgroup.
Used by multiple elements
- align -- <applet>, <col>, <colgroup>, <object>, <tbody>, <td>, <tfoot>, <th>, <thead>
- align also deprecated in <caption>, <div>, <h1> to <h6>, <hr>, <iframe>, <img>, <input>, <legend>, <p>, <table>
- alt -- <applet>, <area>, <img>, <input>
- bgcolor -- <body>, <table>, <td>, <th>, <bgcolor>
- border -- <img>, <object>, <table>
- char -- <char>, <colgroup>, <tbody>, <td>, <tfoot>, <th>, <thead>, <tr>
- charoff -- <col>, <colgroup>, <tbody>, <td>, <tfoot>, <th>, <thead>, <tr>
- charset -- <a>, <link>, <script>
- cite -- <blockquote>, <del>, <ins>, <q>
- compact -- <dir>, <menu>, <ol>, <ul>
- disabled -- <button>, <input>, <optgroup>, <option>, <select>, <textarea>
- height - <applet>, <iframe>, <img>, <object> . Also deprecated in <td>, <th>
- href -- <a>, <area>, <base>, <link>
- hspace -- <applet>, <object>. Also deprecated in <img>
- longdesc -- <frame>, <iframe>, <img>
- name -- <a>, <applet>, <button>, <form>, <frame>, <iframe>, <input>, <map>, <meta>, <object>, <param>, <select>, <textarea>
- size -- <basefont>, <font>, <hr>, <input>, <select>
- src -- <frame>, <iframe>, <img>, <input>, <script>
- target -- <a>, <area>, <base>, <form>, <link>
- type -- <button>, <input>, <li>, <link>, <object>, <ol>, <param>, <script>, <style>, <ul>
- valign -- <col>, <colgroup>, <tbody>, <td>, <tfoot>, <th>, <thead>, <tr>
- value -- <button>, <input>, <li>, <option>, <param>
- vspace -- <applet>, <img>, <object>
- width -- <applet>, <col>, <colgroup>, <hr>, <iframe>, <img>, <object>, <pre>, <table>, <td>, <th>
Standard attributes
Standard attributes are also known as global attributes, and function with a large number of elements. They include the basic standard attributes: these include accesskey, class, contenteditable, contextmenu, data, dir, hidden, id, lang, style, tabindex, title. There are also some experimental ones. Both xml:lang and xml:base have been deprecated. The multiple aria-* attributes improve accessibility. The event handler attributes are listed later on.
Technically all standard attributes must be accepted by all elements, though they will not function with some elements. The table below lists some common standard attributes, and some elements they can function with.
Event attributes
The standard attributes include the event handler attributes. They are all prefixed on-. They are: onabort, onautocomplete, onautocompleteerror, onblur, oncancel, oncanplay, oncanplaythrough, onchange, onclick, onclose, oncontextmenu, oncuechange, ondblclick, ondrag, ondragend, ondragenter, ondragexit, ondragleave, ondragover, ondragstart, ondrop, ondurationchange, onemptied, onended, onerror, onfocus, oninput, oninvalid, onkeydown, onkeypress, onkeyup, onload, onloadeddata, onloadedmetadata, onloadstart, onmousedown, onmouseenter, onmouseleave, onmousemove, onmouseout, onmouseover, onmouseup, onmousewheel, onpause, onplay, onplaying, onprogress, onratechange, onreset, onresize, onscroll, onseeked, onseeking, onselect, onshow, onsort, onstalled, onsubmit, onsuspend, ontimeupdate, ontoggle, onvolumechange, onwaiting.
Event attributes, added in HTML version 4, allow an element to specify scripts to be run under specific circumstances. The table below lists some common event handler attributes, and some elements they can function with.
References
Source of article : Wikipedia