HTML attributes

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:

Example tag 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:

Empty attribute

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:

<input disabled>

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 (< and >), in addition the value should not be an empty string.

<input value=yes>

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.

<input type='checkbox'>

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.

With this theme look:

Copying materials from this site is possible only with the permission of the site administration and
when you specify a direct active link to the source.
2011-2018 © | ruen