Skip to main content

Attribute

Attribute it is a definition that is used in various fields of IT. Generally, an attribute is used to describe a file or data field in more detail. In object-oriented programming, attributes are a property or characteristic that can be assigned to an object (element). Through the use of attributes, specific values can be assigned to certain items.

Application areas

The three most common areas in which attributes are used in the IT field are:

  • Data processing: Here attributes are used to specify files. Common file attributes include size or creation date.
  • HTML: In HTML, attributes serve as tags to further define objects.
  • XML or SGML: In these languages, the properties of the items or variables are defined by means of attributes.

600x400-Attribute-en-01.png

Attributes in HTML tags

Attributes are commonly used in HTML tags and have different characteristics. Regardless, only certain attributes are allowed as part of the W3C standards.

Structure

Inside an element (here an h2 tag) an attribute is defined directly at the beginning followed by an equal sign. The value of the attribute is enclosed in quotation marks.

<h2 id="my id">...</h2>

There are some common attributes that can be used for all HTML items:

  • title attribute: This attribute assigns a title to the particular HTML element. This title can appear on the web as a tool tip, for example, when the user moves the cursor over it.
  • href / src: This specifies a URL for a web address or an image contained in the HTML code.
  • width / height attribute: These attributes define the size of the graphics (width / height).
  • alt attribute: This attribute is used to define alternative description text for graphics in source code. Appears when the browser cannot load the file. ALT attributes are also used for equal access websites (that is, accessible to people with disabilities).

Use of various attributes

It is feasible to accommodate multiple attributes in one tag. Individual attributes are separated by spaces.

<h2 class="textwhite backgroundpurple"id="heading2">...</h2>

Attributes like class attribute and id attribute are usually applied to the visual design of HTML items using CSS (Cascading Style Sheets).

It should be noted that the formatting of the webs should always be done through style sheets. The reason for this is that the W3C considers attributes that only serve for formatting to be "obsolete". Good HTML styling separates content from layout.

Examples

Most of the HTML attributes are optional. If you embed an image on a website with an img tag, while specifying its origin with a src tag, an ALT attribute should also be assigned to display an alternative text if the image cannot be displayed.

An example of optional but very interesting attributes are the title attributes. If an Internet user briefly hovers over a link, he will get a brief description of the link's destination through this attribute. This would make it easier to use and navigate. This title attribute could be implemented as follows.

<p>...at the <a href="http://chocolate-expert.tld/path/to/preparation/" title="The chocolate experts – 100 possible ways to prepare chocolate">Preparation</a>of chocolate...</p>

The attributes are definitely relevant for online store operators as well. Users can compare and find multiple products through Google Shopping. Correct HTML markup is very important if an online store offers its products through the Google Base Product Feed. Google describes all possible attributes, which are important to the Product Feed Specification in your Google Merchant Center.

Importance for SEO

As a general rule, Google considers the correct use of attributes as an indication of the quality of a website. The Title and Alt attributes can be beneficial for SEO OnPage. The alt attribute, for example, has a great influence on SEO for images, since this attribute provides a reference to the content of the image, which otherwise the crawler could only get through the embedded content. Title attributes have long been considered an important optimization factor for the relationship. The keywords were not only used in the anchor text, but also in the title as part of the link building. Currently, SEOs must be careful when using anchor text and titles for external links to avoid keyword stuffing. Still, in the case of internal links, title attributes can be advantageous, as they give users and Googlebot an indication of what to expect from the landing page.