fbpx
Wikipedia

HTML attribute

HTML attributes are special words used inside the opening tag to control the element's behaviour. HTML attributes are a modifier of a 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 a 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 many 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.[1]

Description edit

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:

<element attribute="value">element content</element> 

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).[2][3] Leaving attribute values unquoted is considered unsafe.[4]

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[5] (like the ismap attribute for the img element[6]).

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 blue without being a link, and in most browsers, pointing the cursor at the abbreviation should display the title text "Hypertext Markup Language" within a floating yellow background (tooltip).

<div style="text-align: center;">Centered text</div> 

In this other example, your text will look like this:

Centered text

Most elements also take the language-related attributes lang and dir.

Common attributes edit

Usually, HTML elements can take any of several most common standard attributes (See the complete list):

  • The id attribute provides a document-wide unique identifier for an element.[7][8][9] 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" in http://en.wikipedia.org/wiki/HTML#Attributes (to refer to the section "Attributes" in the "HTML" page).
  • The class attribute provides a way of classifying similar elements. Multiple class names can be added by separating them with spaces.[10][11] Semantically, for example, classes are used in microformats. Additionally authors of style sheets can construct selectors that match elements by class for styling purposes. For example, a HTML document might use the designation class="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 as footnotes on a page—instead of appearing in the place suggested by their position within the HTML source. The style sheet author might also define a rule with the .notation selector and define the property font-size: small;.
  • The style attribute provides a way of applying element-specific style rules. Multiple style declarations can be added by separating them with semicolons and an optional space, where each declaration includes a CSS property name and a value separated by a colon and an optional space (Example: style="color: red; text-align: center;").[12][13][14] The style attribute can be used on any HTML element (it will validate on any HTML element; however, it is not necessarily useful). It is considered better practice to add the style information to a style sheet, often accomplished with selectors that match the element class or ID. Sometimes, however, inline styles are favored where style sheets are considered too cumbersome for a simple and specific or ad hoc style specification.
  • 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.

Varieties edit

HTML attributes are generally classified 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.[15]
  • Event attributes, added in HTML version 4, allow an element to specify scripts to be run under specific circumstances.[16]

Required and optional edit

Used by two elements edit

  • <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 edit

  • 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 edit

Standard attributes are also known as global attributes, and function with a large number of elements.[17] 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.[17] 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.[18] The table below lists some common standard attributes, and some elements they can function with.

Element id class style title dir lang xml:lang accesskey tabindex
<param> id
<head> dir lang xml:lang
<html> dir lang xml:lang
<meta> dir lang xml:lang
<title> dir lang xml:lang
<style> title dir lang xml:lang
<applet> id class style title
<br> id class style title
<frame> id class style title
<frameset> id class style title
<iframe> id class style title
<basefont> id class style title dir lang
<center> id class style title dir lang
<dir> id class style title dir lang
<font> id class style title dir lang
<menu> id class style title dir lang
<s> id class style title dir lang
<strike> id class style title dir lang
<u> id class style title dir lang
<abbr> id class style title dir lang xml:lang
<acronym> id class style title dir lang xml:lang
<address> id class style title dir lang xml:lang
<b> id class style title dir lang xml:lang
<big> id class style title dir lang xml:lang
<blockquote> id class style title dir lang xml:lang
<body> id class style title dir lang xml:lang
<caption> id class style title dir lang xml:lang
<cite> id class style title dir lang xml:lang
<code> id class style title dir lang xml:lang
<col> id class style title dir lang xml:lang
<colgroup> id class style title dir lang xml:lang
<dd> id class style title dir lang xml:lang
<del> id class style title dir lang xml:lang
<dfn> id class style title dir lang xml:lang
<div> id class style title dir lang xml:lang
<dl> id class style title dir lang xml:lang
<dt> id class style title dir lang xml:lang
<em> id class style title dir lang xml:lang
<fieldset> id class style title dir lang xml:lang
<form> id class style title dir lang xml:lang
<hr> id class style title dir lang xml:lang
<h1>, <h2>, <h3>, <h4>, <h5>, <h6> id class style title dir lang xml:lang
<i> id class style title dir lang xml:lang
<img> id class style title dir lang xml:lang
<ins> id class style title dir lang xml:lang
<kbd> id class style title dir lang xml:lang
<li> id class style title dir lang xml:lang
<link> id class style title dir lang xml:lang
<map> id class style title dir lang xml:lang
<noframes> id class style title dir lang xml:lang
<noscript> id class style title dir lang xml:lang
<ol> id class style title dir lang xml:lang
<optgroup> id class style title dir lang xml:lang
<option> id class style title dir lang xml:lang
<p> id class style title dir lang xml:lang
<pre> id class style title dir lang xml:lang
<q> id class style title dir lang xml:lang
<samp> id class style title dir lang xml:lang
<small> id class style title dir lang xml:lang
<span> id class style title dir lang xml:lang
<strong> id class style title dir lang xml:lang
<sub> id class style title dir lang xml:lang
<sup> id class style title dir lang xml:lang
<table> id class style title dir lang xml:lang
<tbody> id class style title dir lang xml:lang
<td> id class style title dir lang xml:lang
<tfoot> id class style title dir lang xml:lang
<th> id class style title dir lang xml:lang
<thead> id class style title dir lang xml:lang
<tr> id class style title dir lang xml:lang
<tt> id class style title dir lang xml:lang
<ul> id class style title dir lang xml:lang
<var> id class style title dir lang xml:lang
<label> id class style title dir lang xml:lang accesskey
<legend> id class style title dir lang xml:lang accesskey
<object> id class style title dir lang xml:lang tabindex
<select> id class style title dir lang xml:lang tabindex
<a> id class style title dir lang xml:lang accesskey tabindex
<area> id class style title dir lang xml:lang accesskey tabindex
<button> id class style title dir lang xml:lang accesskey tabindex
<input> id class style title dir lang xml:lang accesskey tabindex
<textarea> id class style title dir lang xml:lang accesskey tabindex

Event attributes edit

The standard attributes include the event handler attributes. They are all prefixed on-:[17]

  • 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.

Element At At At At At At At At At At At At At At At At At
<frameset> onload onunload
<body> onload onunload onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<abbr> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<acronym> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<address> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<b> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<big> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<blockquote> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<caption> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<center> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<cite> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<code> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<col> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<colgroup> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<dd> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<del> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<dfn> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<dir> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<div> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<dl> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<dt> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<em> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<fieldset> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<h1>, <h2>, <h3>, <h4>, <h5>, <h6> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<hr> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<i> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<ins> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<kbd> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<legend> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<li> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<link> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<map> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<menu> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<noframes> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<noscript> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<object> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<ol> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<optgroup> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<option> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<p> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<pre> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<q> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<s> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<samp> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<small> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<span> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<strike> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<strong> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<sub> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<sup> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<table> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<tbody> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<td> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<tfoot> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<th> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<thead> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<tr> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<tt> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<u> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<ul> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<var> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<img> onabort onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup
<a> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
<area> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
<button> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
<form> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
<label> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus
<select> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus onchange
<input> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus onchange onselect
<textarea> onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus onchange onselect

See also edit

References edit

  1. ^ "Index of the HTML 4 Attributes". W3C. Retrieved 13 February 2015.
  2. ^ "On SGML and HTML". World Wide Web Consortium. Retrieved November 16, 2008.
  3. ^ "XHTML 1.0 – Differences with HTML 4". World Wide Web Consortium. Retrieved November 16, 2008.
  4. ^ Korpela, Jukka (July 6, 1998). "Why attribute values should always be quoted in HTML". Cs.tut.fi. Retrieved November 16, 2008.
  5. ^ "Tags used in HTML". World Wide Web Consortium. November 3, 1992. Retrieved November 16, 2008.
  6. ^ "Objects, Images, and Applets in HTML documents". World Wide Web Consortium. December 24, 1999. Retrieved November 16, 2008.
  7. ^ However, multiple identifiers may apply to the same element; in particular an element may be inside another element, each having an identifier.
  8. ^ "HTML id". W3Schools. from the original on Apr 27, 2020. Retrieved 2020-04-27.
  9. ^ "HTML Global id Attribute". W3Schools. Retrieved 2020-04-27.
  10. ^ "HTML Classes". W3Schools. Retrieved 2020-04-27.
  11. ^ "HTML Global class Attribute". W3Schools. Retrieved 2020-04-27.
  12. ^ "HTML Styles". W3Schools. Retrieved 2023-05-12.
  13. ^ "HTML Global style Attribute". W3Schools. Retrieved 2023-05-12.
  14. ^ "CSS Syntax". W3Schools. Retrieved 2023-05-12.
  15. ^ "HTML Global Attributes". W3Schools.
  16. ^ "HTML Event Attributes". W3Schools.
  17. ^ a b c "Global attributes – HTML (HyperText Markup Language)". MDN Web Docs. Retrieved 2015-02-12.
  18. ^ "HTML reference – HTML (HyperText Markup Language)". MDN Web Docs. Retrieved 13 February 2015.

html, attribute, special, words, used, inside, opening, control, element, behaviour, modifier, html, element, type, attribute, either, modifies, default, functionality, element, type, provides, functionality, certain, element, types, unable, function, correctl. HTML attributes are special words used inside the opening tag to control the element s behaviour HTML attributes are a modifier of a 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 a 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 many 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 1 Contents 1 Description 1 1 Common attributes 2 Varieties 3 Required and optional 3 1 Used by two elements 3 2 Used by multiple elements 4 Standard attributes 5 Event attributes 6 See also 7 ReferencesDescription editHTML attributes generally appear as name value pairs separated by and are written within the start tag of an element after the element s name lt element attribute value gt element content lt element gt 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 2 3 Leaving attribute values unquoted is considered unsafe 4 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 5 like the ismap attribute for the img element 6 The abbreviation element abbr can be used to demonstrate these various attributes lt abbr id anId class aClass style color blue title Hypertext Markup Language gt HTML lt abbr gt This example displays as HTML in blue without being a link and in most browsers pointing the cursor at the abbreviation should display the title text Hypertext Markup Language within a floating yellow background tooltip lt div style text align center gt Centered text lt div gt In this other example your text will look like this Centered text Most elements also take the language related attributes lang and dir Common attributes edit Usually HTML elements can take any of several most common standard attributes See the complete list The id attribute provides a document wide unique identifier for an element 7 8 9 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 in http en wikipedia org wiki HTML Attributes to refer to the section Attributes in the HTML page The class attribute provides a way of classifying similar elements Multiple class names can be added by separating them with spaces 10 11 Semantically for example classes are used in microformats Additionally authors of style sheets can construct selectors that match elements by class for styling purposes For example a HTML document might use the designation class 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 as footnotes on a page instead of appearing in the place suggested by their position within the HTML source The style sheet author might also define a rule with the notation selector and define the property font size small The style attribute provides a way of applying element specific style rules Multiple style declarations can be added by separating them with semicolons and an optional space where each declaration includes a CSS property name and a value separated by a colon and an optional space Example style color red text align center 12 13 14 The style attribute can be used on any HTML element it will validate on any HTML element however it is not necessarily useful It is considered better practice to add the style information to a style sheet often accomplished with selectors that match the element class or ID Sometimes however inline styles are favored where style sheets are considered too cumbersome for a simple and specific or ad hoc style specification 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 Varieties editHTML attributes are generally classified 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 15 Event attributes added in HTML version 4 allow an element to specify scripts to be run under specific circumstances 16 Required and optional editUsed by two elements edit lt a gt and lt area gt coords coordinates of an lt area gt or a lt link gt within it shape shape of an lt area gt or a lt link gt within it Values default rect circle poly lt a gt and lt link gt hreflang Language code of the linked document lt a gt lt link gt rel Nature of the linked document relative to the page currently displayed Free text for lt a gt but lt link gt 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 lt a gt and lt link gt as for rel lt applet gt and lt object gt archive archive URL s lt applet gt lt object gt codebase base URL lt applet gt lt object gt lt basefont gt and lt font gt color text color deprecated lt basefont gt lt font gt face font family deprecated lt basefont gt lt font gt lt col gt and lt colgroup gt span number of columns spanned lt col gt lt colgroup gt lt del gt and lt ins gt datetime date and time of text deletion or insertion lt form gt and lt input gt accept types of files accepted when uploading lt form gt or lt input gt lt frame gt and lt iframe gt frameborder value 0 or 1 specifies whether to display a border around the lt frame gt or lt iframe gt marginheight top and bottom margins in pixels around the lt frame gt or lt iframe gt scrolling value yes no auto specifies whether to display scroll bars around the lt frame gt or lt iframe gt marginwidth left and right margins in pixels around the lt frame gt or lt iframe gt lt frameset gt and lt textarea gt cols number of visible columns in lt frameset gt or lt textarea gt some variation rows number of visible rows in lt frameset gt or lt textarea gt some variation lt img gt and lt object gt usemap specifies name of a map element to use with lt img gt or URL of an image map to use with lt object gt lt input gt and lt textarea gt readonly specifies read only text for lt input gt and lt textarea gt lt link gt and lt style gt media specifies display device for lt link gt and lt style gt Values all aural braille handheld print projection screen tty TV lt optgroup gt and lt option gt label description text for an lt optgroup gt or lt option gt lt td gt and lt th gt 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 edit align lt applet gt lt col gt lt colgroup gt lt object gt lt tbody gt lt td gt lt tfoot gt lt th gt lt thead gt align also deprecated in lt caption gt lt div gt lt h1 gt to lt h6 gt lt hr gt lt iframe gt lt img gt lt input gt lt legend gt lt p gt lt table gt alt lt applet gt lt area gt lt img gt lt input gt bgcolor lt body gt lt table gt lt td gt lt th gt lt bgcolor gt border lt img gt lt object gt lt table gt char lt char gt lt colgroup gt lt tbody gt lt td gt lt tfoot gt lt th gt lt thead gt lt tr gt charoff lt col gt lt colgroup gt lt tbody gt lt td gt lt tfoot gt lt th gt lt thead gt lt tr gt charset lt a gt lt link gt lt script gt cite lt blockquote gt lt del gt lt ins gt lt q gt compact lt dir gt lt menu gt lt ol gt lt ul gt disabled lt button gt lt input gt lt optgroup gt lt option gt lt select gt lt textarea gt height lt applet gt lt iframe gt lt img gt lt object gt Also deprecated in lt td gt lt th gt href lt a gt lt area gt lt base gt lt link gt hspace lt applet gt lt object gt Also deprecated in lt img gt longdesc lt frame gt lt iframe gt lt img gt name lt a gt lt applet gt lt button gt lt form gt lt frame gt lt iframe gt lt input gt lt map gt lt meta gt lt object gt lt param gt lt select gt lt textarea gt size lt basefont gt lt font gt lt hr gt lt input gt lt select gt src lt frame gt lt iframe gt lt img gt lt input gt lt script gt target lt a gt lt area gt lt base gt lt form gt lt link gt type lt button gt lt input gt lt li gt lt link gt lt object gt lt ol gt lt param gt lt script gt lt style gt lt ul gt valign lt col gt lt colgroup gt lt tbody gt lt td gt lt tfoot gt lt th gt lt thead gt lt tr gt value lt button gt lt input gt lt li gt lt option gt lt param gt vspace lt applet gt lt img gt lt object gt width lt applet gt lt col gt lt colgroup gt lt hr gt lt iframe gt lt img gt lt object gt lt pre gt lt table gt lt td gt lt th gt Standard attributes editStandard attributes are also known as global attributes and function with a large number of elements 17 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 17 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 18 The table below lists some common standard attributes and some elements they can function with Element id class style title dir lang xml lang accesskey tabindex lt param gt id lt head gt dir lang xml lang lt html gt dir lang xml lang lt meta gt dir lang xml lang lt title gt dir lang xml lang lt style gt title dir lang xml lang lt applet gt id class style title lt br gt id class style title lt frame gt id class style title lt frameset gt id class style title lt iframe gt id class style title lt basefont gt id class style title dir lang lt center gt id class style title dir lang lt dir gt id class style title dir lang lt font gt id class style title dir lang lt menu gt id class style title dir lang lt s gt id class style title dir lang lt strike gt id class style title dir lang lt u gt id class style title dir lang lt abbr gt id class style title dir lang xml lang lt acronym gt id class style title dir lang xml lang lt address gt id class style title dir lang xml lang lt b gt id class style title dir lang xml lang lt big gt id class style title dir lang xml lang lt blockquote gt id class style title dir lang xml lang lt body gt id class style title dir lang xml lang lt caption gt id class style title dir lang xml lang lt cite gt id class style title dir lang xml lang lt code gt id class style title dir lang xml lang lt col gt id class style title dir lang xml lang lt colgroup gt id class style title dir lang xml lang lt dd gt id class style title dir lang xml lang lt del gt id class style title dir lang xml lang lt dfn gt id class style title dir lang xml lang lt div gt id class style title dir lang xml lang lt dl gt id class style title dir lang xml lang lt dt gt id class style title dir lang xml lang lt em gt id class style title dir lang xml lang lt fieldset gt id class style title dir lang xml lang lt form gt id class style title dir lang xml lang lt hr gt id class style title dir lang xml lang lt h1 gt lt h2 gt lt h3 gt lt h4 gt lt h5 gt lt h6 gt id class style title dir lang xml lang lt i gt id class style title dir lang xml lang lt img gt id class style title dir lang xml lang lt ins gt id class style title dir lang xml lang lt kbd gt id class style title dir lang xml lang lt li gt id class style title dir lang xml lang lt link gt id class style title dir lang xml lang lt map gt id class style title dir lang xml lang lt noframes gt id class style title dir lang xml lang lt noscript gt id class style title dir lang xml lang lt ol gt id class style title dir lang xml lang lt optgroup gt id class style title dir lang xml lang lt option gt id class style title dir lang xml lang lt p gt id class style title dir lang xml lang lt pre gt id class style title dir lang xml lang lt q gt id class style title dir lang xml lang lt samp gt id class style title dir lang xml lang lt small gt id class style title dir lang xml lang lt span gt id class style title dir lang xml lang lt strong gt id class style title dir lang xml lang lt sub gt id class style title dir lang xml lang lt sup gt id class style title dir lang xml lang lt table gt id class style title dir lang xml lang lt tbody gt id class style title dir lang xml lang lt td gt id class style title dir lang xml lang lt tfoot gt id class style title dir lang xml lang lt th gt id class style title dir lang xml lang lt thead gt id class style title dir lang xml lang lt tr gt id class style title dir lang xml lang lt tt gt id class style title dir lang xml lang lt ul gt id class style title dir lang xml lang lt var gt id class style title dir lang xml lang lt label gt id class style title dir lang xml lang accesskey lt legend gt id class style title dir lang xml lang accesskey lt object gt id class style title dir lang xml lang tabindex lt select gt id class style title dir lang xml lang tabindex lt a gt id class style title dir lang xml lang accesskey tabindex lt area gt id class style title dir lang xml lang accesskey tabindex lt button gt id class style title dir lang xml lang accesskey tabindex lt input gt id class style title dir lang xml lang accesskey tabindex lt textarea gt id class style title dir lang xml lang accesskey tabindexEvent attributes editThe standard attributes include the event handler attributes They are all prefixed on 17 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 Element At At At At At At At At At At At At At At At At At lt frameset gt onload onunload lt body gt onload onunload onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt abbr gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt acronym gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt address gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt b gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt big gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt blockquote gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt caption gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt center gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt cite gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt code gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt col gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt colgroup gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt dd gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt del gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt dfn gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt dir gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt div gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt dl gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt dt gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt em gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt fieldset gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt h1 gt lt h2 gt lt h3 gt lt h4 gt lt h5 gt lt h6 gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt hr gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt i gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt ins gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt kbd gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt legend gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt li gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt link gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt map gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt menu gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt noframes gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt noscript gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt object gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt ol gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt optgroup gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt option gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt p gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt pre gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt q gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt s gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt samp gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt small gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt span gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt strike gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt strong gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt sub gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt sup gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt table gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt tbody gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt td gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt tfoot gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt th gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt thead gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt tr gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt tt gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt u gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt ul gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt var gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt img gt onabort onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup lt a gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus lt area gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus lt button gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus lt form gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus lt label gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus lt select gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus onchange lt input gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus onchange onselect lt textarea gt onclick ondblclick onmousedown onmousemove onmouseout onmouseover onmouseup onkeydown onkeypress onkeyup onblur onfocus onchange onselectSee also editHTML elementReferences edit Index of the HTML 4 Attributes W3C Retrieved 13 February 2015 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 Tags used in HTML World Wide Web Consortium November 3 1992 Retrieved November 16 2008 Objects Images and Applets in HTML documents World Wide Web Consortium December 24 1999 Retrieved November 16 2008 However multiple identifiers may apply to the same element in particular an element may be inside another element each having an identifier HTML id W3Schools Archived from the original on Apr 27 2020 Retrieved 2020 04 27 HTML Global id Attribute W3Schools Retrieved 2020 04 27 HTML Classes W3Schools Retrieved 2020 04 27 HTML Global class Attribute W3Schools Retrieved 2020 04 27 HTML Styles W3Schools Retrieved 2023 05 12 HTML Global style Attribute W3Schools Retrieved 2023 05 12 CSS Syntax W3Schools Retrieved 2023 05 12 HTML Global Attributes W3Schools HTML Event Attributes W3Schools a b c Global attributes HTML HyperText Markup Language MDN Web Docs Retrieved 2015 02 12 HTML reference HTML HyperText Markup Language MDN Web Docs Retrieved 13 February 2015 Retrieved from https en wikipedia org w index php title HTML attribute amp oldid 1219370562 Description, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.