Attributes consist of a name and a value, separated by an "=" (equality) sign and are written within the starting tag of the element. If the attribute is a boolean then the value part and equality sign can be omitted.
Normally the value has to be contained within single (') or double (") quotes. In HTML, if the value does not contain spaces or any of the characters
" ' ` = < >, then quotes are optional.
Data types and microsyntaxes
The different rules that can apply to attributes values are called data types in HTML 4, or microsyntaxes in HTML5.
Main article: Character data.
CDATA or Character data is the most basic data type, used for both attribute values and textual elements. All other data types are derived from CDATA, unless otherwise noted.
The only processing applied to this data type is replacing for character entities by their corresponding characters, and replacing each carriage return and tab with a single space.
HTML 4 describes the Text data type, for human readable text. Attributes that use the Text data type include abbr (
<td> elements), alt (
<img> elements), label (
<option> elements), prompt (
<isindex> element), standby (
<object> element), summary (
<table> element) and title (core attribute).
<abbr title="Conseil Européen pour la Recherche Nucléaire" >CERN</abbr>
Unlike most programming languages, boolean values in HTML are not "true" and "false". Instead, an empty string or a value that matches the attribute name represents true, and the absence of the attribute represents false. The following three examples all represent the true value for the disabled attribute:
<input disabled="disabled">...</input> <input disabled="">...</input> <input disabled>...</input>