Attributes

Attributes were briefly discussed in Overview of HTML. It's time for a deep dive.

Attributes are what make HTML so powerful. Attributes are space-separated names and name/value pairs appearing in the opening tag, providing information about and functionality for the element.

The opening tag, attributes, and closing tag, labelled on an HTML element.

Attributes define the behavior, linkages, and functionality of elements. Some attributes are global, meaning they can appear within any element's opening tag. Other attributes apply to several elements but not all, while other attributes are element-specific, relevant only to a single element. In HTML, all attributes except boolean, and to some extent enumerated attributes, require a value.

If an attribute value includes a space or special characters, the value must be quoted. For this reason and improved legibility, quotations are always recommended.

While HTML isn't case-sensitive, some attribute values are. Values that are part of the HTML specification are case-insensitive. Strings values that are defined, such as class and ID names, are case-sensitive. If an attribute value is case-sensitive in HTML, it's case-sensitive when used as an attribute selector in CSS and in JavaScript; otherwise, it's not.

<!-- the type attribute is case insensitive: these are equivalent -->
<input type="text">
<input type="TeXt">

<!-- the ID attribute is case sensitive: they are not equivalent -->
<div id="myId">
<div id="MyID">

Boolean attributes