- Empty attribute
- Attribute with value without quotation marks
- Attribute with a value in single quotes
- Attribute with a value in double quotation marks
HTML elements can have attributes. Attributes are intended to add additional information about an element and/or to change its standard behavior. Attributes are always specified inside the opening tag. In most cases, attributes are optional and are specified only when necessary. One element must never contain two or more attributes that have the same name. element syntax with attribute:
Attributes consist of a pair: attribute_name = "value". Attribute names are not case sensitive and can be written with any combination of lowercase and uppercase letters. The value of an attribute can consist of text, numbers, and other characters (the only exception is the ampersand (&) symbol, and its use is prohibited). Additional restrictions on the use of different characters in the attribute value depend on how the value is written. When you specify multiple attributes in a single element, they must be separated by a space character. The order of the attributes is irrelevant.
<!-- When you specify multiple attributes for a single tag, they must be separated by a space character --> <p attr1="value" attr="value">content</p> <!-- combination of lowercase and capital letters in an attribute name --> <p AtTrIbUt="value">content</p>
Attributes can be written in four different ways:
Attributes whose values match the name of an attribute are called Boolean or empty. For Boolean attributes, the syntax is supported, where you can omit the attribute value explicitly by writing only its name, in which case the value will be an implicitly specified empty string:
The actual presence in the Boolean attribute element is true, and the absence of this attribute is set to false. If an attribute is present, its value can be either an empty string or the value must match the name of the attribute.
<!-- all options work the same way, just differently recorded --> <input disabled> <input disabled=""> <input disabled=disabled>
Attribute with value without quotation marks
The syntax without the quotation marks around the attribute value implies that the attribute name, after the
= character, will be followed by an attribute value that should not contain space characters, double quotation marks (
" "), apostrophes (
' ') and other types of quotation marks,
= characters, angle brackets (
>), in addition the value should not be an empty string.
Attribute with a value in single quotes
The value of an attribute, taken in single quotation marks, must not contain apostrophe characters ('), but the contents of double quotation marks (") are allowed.
Attribute with a value in double quotation marks
An attribute value surrounded by double quotation marks can contain any characters, including apostrophes ('), except for double quotation marks (").
<input name="be evil">
Note: one element must never contain two or more attributes that have the same name.