If you find this helpful, please click the Google Button to the left, if it is white, to make it turn blue or red. Thank you! (It also helps find this page again more easily.) |
Coding HTML Attributes
An attribute is a named property associated with an element. In a marked-up document, attributes are coded in a starting tag or standalone tag between the element name and the tag's terminating />
or >
delimiter. The code for an HTML attribute consists of the attribute name, an equal sign (=
) and the value of the property enclosed in quotes:
<elemname attrname="value">...</elemname> <elemname attrname="value"/>
Coding Boolean Attributes
Boolean attributes should be coded in their full form using the attribute name in quotes (attribute="attribute"
) when the value is true and completely omitting the attribute when the value is false. The full form will be properly understood by web browsers parsing polyglot documents with either the HTML syntax or the XML syntax of HTML 5. Avoid using minimized attributes, such as selected
, or values with an empty string, such as in selected=""
, which XPath treats as false rather than true.
<input type="text" readonly="readonly"/> <input type="text" required="required"/> <option selected="selected"/> <video autoplay="autoplay" ...>
WARNING: Be careful when looking for web sites for learning HTML, especially when it comes to things that are treated differently by different browsers. For instance, the examples on some very popular web sites show the value "false"
as valid for boolean attributes, which is treated as false by browsers that look at the attribute value and as true by other browsers that only look for the presence or absence of the attribute, resulting in very inconsistent behavior, since that is incorrect coding per the HTML specification:
The values "true" and "false" are not allowed on boolean attributes.
To determine what version of HTML a web page is actually using, enter its URL in the W3C Markup Validation Service and look for the Doctype. If it's not HTML5, change it to HTML5 in the drop-down box and then Revalidate. The pages on this site are Valid HTML 5.
Global Attributes List
Global (Common) Attributes
These are the common (global) HTML attributes that can be used on most HTML tags.
- The
accesskey
Attribute - The
class
Attribute - The
contenteditable
Attribute - The Author-Defined
data-*
Attributes - The
dir
Attribute - The
draggable
Attribute - The
dropzone
Attribute - The
id
Attribute - The Microdata
item...
Attributes - The
lang
Attribute - The
on...
Event Attributes - The
spellcheck
Attribute - The
style
Attribute - The
tabindex
Attribute - The
title
Attribute - XML Atttributes in HTML
- xmlns and xml:space
The other HTML attributes are limited to specific HTML tags.
Element Attribute Index
The table below uses the <tag attribute>
notation indicating the namespace partition as described in the HTML Namespaces and Namespace Declarations Tutorial.