HTML Attributes: Attribute of an Element

Introduction

In previous article we have learn what an HTML is and what are the meaning of the tags used in this language. In this article we will explore the more about “HTML Attributes”.

Attribute of an Element

The elements discussed here can also have its own properties called attributes. An attribute of an element contains extra information regarding it and is not displayed with the actual content. In the above cases you have seen <a> tag with href attribute. These attributes enhance the features of an element.

Examples

The attribute of an element can be easily understood by below examples:

Example 1: Image tag consists of an attribute src which specifies the source of the image.

Code:

Image tag

Output:

Image tag Output

Example 2: We can use attribute to fix height and width of an image too.
Code:

Image tag attribute

Note: Every tag must be closed so that it doesn’t affect other tags. Some tags are empty elements i.e. it doesn’t have separate opening and closing tags, e.g. <Image/> tag, hence it has no content to be shown apart from the image fetched from the source.

Output:

Image tag attribute Output

HTML Attributes

From above examples, we can derive that an attribute includes the following:

HTML Attributes

  1. A space: A space between the element tag name and an attribute or between two attributes.
  2. The attribute name: These are predefined for each html tags. These are followed by an equal to sign “=”.
  3. The attribute value: These are the values assigned to the attribute names. These are wrapped within quotation marks “ ”.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.