HTML attribute
HTML attributes are modifiers of HTML elements. They generally appear as name-value pairs, separated by "=", and are written within the start tag of an element, after the element's name:
- <''tag'' ''attribute''="''value''">(content to be modified by the tag)</tag>
- Where tag names the HTML element, 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).[1][2] Leaving attribute values unquoted is considered unsafe.[3]
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[4] (like the ismap
attribute for the img
element[5]).
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 by stylesheets 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, it provides a globally-unique identifier for an element; 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 or 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. - 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:
<abbr id="anId" class="aClass" style="color:blue;" title="Hypertext Markup Language">HTML</abbr>
This example displays as HTML; 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
.
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.[6] Event attributes, added in HTML version 4, allow an element to specify scripts to be run under specific circumstances.[7]
Required and optional HTML attributes
Used by one tag
- Template:W3schools: Template:W3schools, Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools, Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools, Template:W3schools, Template:W3schools
- Template:W3schools: Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools, Template:W3schools
- Template:W3schools: Template:W3schools
- Template:W3schools: Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- Template:W3schools: Template:W3schools
Used by two tags
- Template:W3schools and Template:W3schools:
- coords — coordinates of an Template:W3schools or a Template:W3schools within it.
- shape — shape of an Template:W3schools or a Template:W3schools within it. Values: default, rect, circle, poly.
- Template:W3schools and Template:W3schools:
- hreflang — Language code of the linked document. (Template:W3schools, Template:W3schools)
- rel — Nature of the linked document (relative to the page currently displayed). Free text for Template:W3schools, but Template:W3schools 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 Template:W3schools and Template:W3schools as for rel.
- Template:W3schools and Template:W3schools:
- archive — archive URL(s) (Template:W3schools, Template:W3schools)
- codebase — base URL (Template:W3schools, Template:W3schools)
- Template:W3schools and Template:W3schools:
- color — text color (deprecated) (Template:W3schools, Template:W3schools)
- face — font family (deprecated) (Template:W3schools, Template:W3schools)
- Template:W3schools and Template:W3schools:
- span — number of columns spanned (Template:W3schools, Template:W3schools)
- Template:W3schools and Template:W3schools:
- datetime — date and time of text Template:W3schools or Template:W3schools.
- Template:W3schools and Template:W3schools:
- accept — types of files accepted when uploading Template:W3schools or Template:W3schools
- Template:W3schools and Template:W3schools:
- frameborder — value (0 or 1) specifies whether to display a border around the Template:W3schools or Template:W3schools.
- marginheight — top and bottom margins in pixels around the Template:W3schools or Template:W3schools.
- scrolling — value (yes, no, auto) specifies whether to display scroll bars around the Template:W3schools or Template:W3schools.
- marginwidth — left and right margins in pixels around the Template:W3schools or Template:W3schools.
- Template:W3schools and Template:W3schools:
- cols — number of visible columns in Template:W3schools or Template:W3schools (some variation)
- rows — number of visible rows in Template:W3schools or Template:W3schools (some variation)
- Template:W3schools and Template:W3schools:
- usemap — specifies name of a map tag to use with Template:W3schools -or- URL of an image-map to use with Template:W3schools.
- Template:W3schools and Template:W3schools:
- readonly — specifies read-only text for Template:W3schools and Template:W3schools.
- Template:W3schools and Template:W3schools:
- media — specifies display device for Template:W3schools and Template:W3schools. Values: all, aural, braille, handheld, print, projection, screen, tty, tv.
- Template:W3schools and Template:W3schools:
- label — description text for an Template:W3schools or Template:W3schools.
- Template:W3schools and Template:W3schools:
- abbr — abbreviated version of a table Template:W3schools or Template:W3schools.
- axis — category name for a table Template:W3schools or Template:W3schools.
- colspan — number of columns spanned by a table Template:W3schools or Template:W3schools.
- nowrap — (deprecated) prevents wrapping of a table Template:W3schools or Template:W3schools.
- rowspan — number of rows spanned by a table Template:W3schools or Template:W3schools.
- scope — no effect on normal browser display, but marks a table Template:W3schools or Template:W3schools as a logical header for other cells. Values: col, colgroup, row, rowgroup.
Used by multiple tags
- align — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- alt — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- bgcolor — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- border — Template:W3schools, Template:W3schools, Template:W3schools
- char — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- charoff — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- charset — Template:W3schools, Template:W3schools, Template:W3schools
- cite — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- compact — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- disabled — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- height - Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools — also (deprecated) Template:W3schools, Template:W3schools
- href — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- hspace — Template:W3schools, Template:W3schools — also (deprecated) Template:W3schools
- longdesc — Template:W3schools, Template:W3schools, Template:W3schools
- name — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- size — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- src — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools)
- target — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- type — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- valign — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- value — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
- vspace — Template:W3schools, Template:W3schools, Template:W3schools
- width — Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools, Template:W3schools
References
- ^ "On SGML and HTML". World Wide Web Consortium. Retrieved November 16, 2008.
- ^ "XHTML 1.0 - Differences with HTML 4". World Wide Web Consortium. Retrieved November 16, 2008.
- ^ Korpela, Jukka (July 6, 1998). "Why attribute values should always be quoted in HTML". Cs.tut.fi. Retrieved November 16, 2008.
- ^ "Objects, Images, and Applets in HTML documents". World Wide Web Consortium. December 24, 1999. Retrieved November 16, 2008.
- ^ "HTML / XHTML Standard Attributes". w3schools.com.
- ^ "HTML / XHTML Standard Event Attributes". w3schools.com.