Applying Attributes in HTML Tags

1.1 Definition

An attribute is used to define the characteristics of an HTML element and is placed inside the element's opening tag. All attributes are made up of two parts − a name and a value.

1.2 Syntax

‹tagname attributename="value"› tag content ‹/tagname›

‹p align="center"› Hello World! ‹/p›

1.) The name is the property you want to set. For example, the paragraph ‹p› element in the example carries an attribute whose name is align, which you can use to indicate the alignment of paragraph on the page.

2.) The value is what you want the value of the property to be set and always put within single or double quotations. In above example we can use three possible values of align attribute: left, center and right.

1.3 Some Attributes

A title attribute is added to the ‹p› tag. The value of the title attribute will be displayed as a tooltip when you mouse over the paragraph.

A bgcolor attribute is added to the ‹body› tag. The value of the bgcolor attribute can be name, hexadecimal, RGB values. According to the value chosen the background color of the page will appear in the browser.

A text attribute is added to the ‹body› tag. The value of the text attribute can be name, hexadecimal, RGB values. According to the value chosen the background color of the page will appear in the browser.

Note:

  • Attribute names and attribute values are case-insensitive.
  • Using double quotes are the most common but you can also use single quotes. Omitting quotes can produce errors. We always use quotes around attribute values.