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).23 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 element5 (like the ismap attribute for the img element6).
The abbreviation element, abbr, can be used to demonstrate these various attributes:
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).
In this other example, your text will look like this:
Most elements also take the language-related attributes lang and dir.
Usually, HTML elements can take any of several most common standard attributes (See the complete list):
HTML attributes are generally classified as required attributes, optional attributes, standard attributes, and event attributes:
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.18 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.19 The table below lists some common standard attributes, and some elements they can function with.
The standard attributes include the event handler attributes. They are all prefixed on-:20
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.
"Index of the HTML 4 Attributes". W3C. Retrieved 13 February 2015. http://www.w3.org/TR/html4/index/attributes.html ↩
"On SGML and HTML". World Wide Web Consortium. Retrieved November 16, 2008. http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.2.2 ↩
"XHTML 1.0 – Differences with HTML 4". World Wide Web Consortium. Retrieved November 16, 2008. http://www.w3.org/TR/xhtml1/diffs.html#h-4.4 ↩
Korpela, Jukka (July 6, 1998). "Why attribute values should always be quoted in HTML". Cs.tut.fi. Retrieved November 16, 2008. https://jkorpela.fi/qattr.html ↩
"Tags used in HTML". World Wide Web Consortium. November 3, 1992. Retrieved November 16, 2008. http://www.w3.org/History/19921103-hypertext/hypertext/WWW/MarkUp/Tags.html ↩
"Objects, Images, and Applets in HTML documents". World Wide Web Consortium. December 24, 1999. Retrieved November 16, 2008. http://www.w3.org/TR/1999/REC-html401-19991224/struct/objects.html#adef-ismap ↩
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. https://www.w3schools.com/html/html_id.asp ↩
"HTML Global id Attribute". W3Schools. Retrieved 2020-04-27. https://www.w3schools.com/tags/att_global_id.asp ↩
"HTML Classes". W3Schools. Retrieved 2020-04-27. https://www.w3schools.com/html/html_classes.asp ↩
"HTML Global class Attribute". W3Schools. Retrieved 2020-04-27. https://www.w3schools.com/tags/att_global_class.asp ↩
"HTML Styles". W3Schools. Retrieved 2023-05-12. https://www.w3schools.com/html/html_styles.asp ↩
"HTML Global style Attribute". W3Schools. Retrieved 2023-05-12. https://www.w3schools.com/tags/att_global_style.asp ↩
"CSS Syntax". W3Schools. Retrieved 2023-05-12. https://www.w3schools.com/Css/css_syntax.asp ↩
"HTML Global Attributes". W3Schools. https://www.w3schools.com/tags/ref_standardattributes.asp ↩
"HTML Event Attributes". W3Schools. https://www.w3schools.com/tags/ref_eventattributes.asp ↩
"Global attributes – HTML (HyperText Markup Language)". MDN Web Docs. Retrieved 2015-02-12. https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes ↩
"HTML reference – HTML (HyperText Markup Language)". MDN Web Docs. Retrieved 13 February 2015. https://developer.mozilla.org/en-US/docs/Web/HTML/Reference ↩