HTML attribute: Difference between revisions

Content deleted Content added
m Varieties: HTTP -> HTTPS for W3Schools using AWB
Differentiate between "tag" and "element".
Line 1:
{{Html series}}
The attributes are special words used inside the opening tag to control the tagelement's behaviour. '''HTML attribute''' is a modifier of an ''[[HTML element|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 tags|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.
Line 9:
HTML attributes generally appear as name-value pairs, separated by <code>=</code>, and are written within the start tag of an element, after the element's name:
 
:<source lang="html4strict"><tagelement attribute="value">element content to be modified by the tag</tagelement></source>
 
Where <code>tagelement</code> names the HTML element type, and <code>attribute</code> is the name of the attribute, set to the provided <code>value</code>. 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).<ref>{{cite web|url=http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.2.2 |title=On SGML and HTML |publisher=World Wide Web Consortium |date=|accessdate=November 16, 2008}}</ref><ref>{{cite web|url=http://www.w3.org/TR/xhtml1/diffs.html#h-4.4|title=XHTML 1.0 - Differences with HTML&#160;4|publisher=World Wide Web Consortium|date=|accessdate=November 16, 2008}}</ref> Leaving attribute values unquoted is considered unsafe.<ref>{{cite web|first=Jukka|last=Korpela|url=http://www.cs.tut.fi/~jkorpela/qattr.html|title=Why attribute values should always be quoted in HTML|publisher=Cs.tut.fi |date=July 6, 1998|accessdate=November 16, 2008}}</ref>
 
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<ref name="tagshtml">{{cite web|url=http://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html |title=Tags used in HTML |publisher=World Wide Web Consortium |date=November 3, 1992 |accessdate=November 16, 2008}}</ref> (like the <code>ismap</code> attribute for the <code>img</code> element<ref>{{cite web|url=http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#adef-ismap|title=Objects, Images, and Applets in HTML documents |publisher=World Wide Web Consortium |date=December 24, 1999|accessdate=November 16, 2008}}</ref>).
Line 36:
==Required and optional==
 
===Used by one tagelement===
* {{MDNHTMLRef|applet}}: {{MDNHTMLRef|applet|code}}, {{MDNHTMLRef|applet|object}}
* {{MDNHTMLRef|area}}: {{MDNHTMLRef|area|nohref}}
Line 58:
* {{MDNHTMLRef|td}}: {{MDNHTMLRef|td|headers}}
 
===Used by two tagselement===
* {{MDNHTMLRef|a}} and {{MDNHTMLRef|area}}:
** coords — coordinates of an {{MDNHTMLRef|area|coords|v=1}} or a {{MDNHTMLRef|link|coords|v=1}} within it.
Line 87:
** rows — number of visible rows in {{MDNHTMLRef|frameset|rows|v=1}} or {{MDNHTMLRef|textarea|rows|v=1}} ''(some variation)''
* {{MDNHTMLRef|img}} and {{MDNHTMLRef|object}}:
** usemap — specifies name of a map tagelement to use with {{MDNHTMLRef|img|usemap|v=1}} -or- URL of an image-map to use with {{MDNHTMLRef|object|usemap|v=1}}.
* {{MDNHTMLRef|input}} and {{MDNHTMLRef|textarea}}:
** readonly — specifies read-only text for {{MDNHTMLRef|input|readonly|v=1}} and {{MDNHTMLRef|textarea|readonly|v=1}}.
Line 102:
** scope — no effect on normal browser display, but marks a table {{MDNHTMLRef|td|scope|t=cell}} or {{MDNHTMLRef|td|scope|t=header}} as a logical header for other cells. Values: col, colgroup, row, rowgroup.
 
===Used by multiple tagselement===
* '''align''' — {{MDNHTMLRef|applet|align|v=1}}, {{MDNHTMLRef|col|align|v=1}}, {{MDNHTMLRef|colgroup|align|v=1}}, {{MDNHTMLRef|object|align|v=1}}, {{MDNHTMLRef|tbody|align|v=1}}, {{MDNHTMLRef|td|align|v=1}}, {{MDNHTMLRef|tfoot|align|v=1}}, {{MDNHTMLRef|th|align|v=1}}, {{MDNHTMLRef|thead|align|v=1}}
:*align also deprecated in {{MDNHTMLRef|caption|align|v=1}}, {{MDNHTMLRef|div|align|v=1}}, {{MDNHTMLRef|h1|align|v=1}} to {{MDNHTMLRef|h6|align|v=1}}, {{MDNHTMLRef|hr|align|v=1}}, {{MDNHTMLRef|iframe|align|v=1}}, {{MDNHTMLRef|img|align|v=1}}, {{MDNHTMLRef|input|align|v=1}}, {{MDNHTMLRef|legend|align|v=1}}, {{MDNHTMLRef|p|align|v=1}}, {{MDNHTMLRef|table|align|v=1}}
Line 132:
''Standard attributes'' are also known as ''global attributes'', and function with a large number of elements.<ref name="globalattribute">{{cite web|url=https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes |title=Global attributes - HTML (HyperText Markup Language) MDN |date=|accessdate=2015-02-12}}</ref> 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.<ref name="globalattribute"/> 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.<ref name="HTMLReference">{{cite web | url=https://developer.mozilla.org/en-US/docs/Web/HTML/Reference | title=HTML reference - HTML (HyperText Markup Language) MDN | accessdate=13 February 2015}}</ref> The table below lists some common standard attributes, and some tagselements they can function with.
 
{| class="wikitable sortable"
!Element
!Tag
!id
!class
Line 1,053:
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.''<ref name="globalattribute"/>
 
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 tagselements they can function with.
 
{| class="wikitable sortable" style="font-size:80%;"
|-
!Element
!Tag
!At
!At