HTML Page Structure

HTML Elements
HTML Attributes


HTML Tag Attributes

In HTML, tags can have their own attribures a key value pair inside element start tag. You can think of an attribute as a piece of code attached to a tag which supplies additional information. The attribute always consists of attribute name with equal sign (=) and the value of the attribute which is enclosed in quotes, even if the attribute is a boolean attribute.

Example

In HTML, attributes are very useful when you want to perform some operation with the help of javascript or apply some visual effects using CSS on HTML element. Let's assume that if you want to change text color when mouse over your paragraph or change the image size when mouse over the image. You can achieve this by attaching attribute to the elements.

Example

In above example "id" attribute is using javascript to access the element and perform text color operation on span element.

See Live Example

HTML Tag Common Attributes List

The below table contains complete list of commomnly used attributes and their description which is supported by HTML version.

Attribute NameAttribute Description
IdThis events will encounter when page loads.
AltThis events will encounter when page loads.
ClassThis events will encounter when page unloads.
StyleThis events will encounter when page loads.
WidthThis events will encounter when page unloads.
HeightThis events will encounter when page loads.
AlignThis events will encounter when page unloads.
ValignThis events will encounter when page loads.
BgcolorThis events will encounter when page unloads.
BackgroundThis events will encounter when page loads.

HTML Id Attribute

This is very common attribute of HTML element to distinguish each element from others. In HTML web page, multiple element may have same name but id cannot it must be unique.

Example

HTML Alt Attribute

This is very common attribute of HTML element to display brief information about that element. Let's assume that you have web page that content list of "img" element and you want to display some brief information about each image when user mouse over on particular image.

Example

HTML Width and Height Attribute

This is very common attribute of HTML element to display set width and height for element. Let's assume that you have web page that contains a list of "img" elements and you want to display all images in equal width and height. In HTML, width and height can be set in "px" for example width="100px" or in percentage as width="100%".

Example