What is "attributes"

Code decoration

It is used to indicate a feature of a part of the code, it can be a field, method, type, or other code elements. Some call it a note.

Source.

HTML (Hyper Text Markup Language)

To tag at first may contain additional information, as in the previous example. Such information is called attributes. Attributes usually consist of two parts:

  • An attribute name;
  • An attribute value.

Some few attributes may have only one value. They are Boolean attributes and can be abbreviated by specifying only their name or leaving their value blank. Thus, the following 3 examples have the same meaning:

<input required="required">

<input required="">

<input required>

Attribute values consisting of a single word or number can be written immediately after the sign of equality (=), without the use of quotation marks, on the other hand, if the value consists of two or more words, the use of quotation marks is mandatory. Both single (') and double (") quotes are permitted. Many developers always opt for quotation marks to make the code less ambiguous and to avoid errors. In the following example a mistake is made:

<p class=foo bar>

(Careful, it probably doesn’t mean what you think it means.)

In this example, the value should be "foo bar", but since no quotes were used in the code, it is interpreted as if it were:

<p class="foo" bar="">

Source.

Object orientation

Controversially some people say that the attribute is the same as a field. There are several objections to this. Probably the wrong information was disseminated by ambiguous text interpretation error.

Source.