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 ExampleThe below table contains complete list of commomnly used attributes and their description which is supported by HTML version.
Attribute Name | Attribute Description |
---|---|
Id | This events will encounter when page loads. |
Alt | This events will encounter when page loads. |
Class | This events will encounter when page unloads. |
Style | This events will encounter when page loads. |
Width | This events will encounter when page unloads. |
Height | This events will encounter when page loads. |
Align | This events will encounter when page unloads. |
Valign | This events will encounter when page loads. |
Bgcolor | This events will encounter when page unloads. |
Background | This events will encounter when page loads. |
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
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
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