HTML attribute is the properties of tag to display the content in efficient manner. In other words, we can say attribute is the constraint of tag. For example we use align attribute with <p> tag to display the paragraph in left or center or right position.
All attribute has two parts: 1st is its name and 2nd is its value.
example <p align="center">This is paragraph tag</p>
Note: Attribute define characteristics of tag.
There are four core attributes that can be used by the majority of HTML elements (although not all) are:
The id attribute is used to identify the same elements uniquely means in a web page we can use many times <p> tag so for uniquely identify the each <p> tag we use id attribute.
<p id="para1" align="left"> This is first paragraph.</p>
<p id="para2" align="left">This is second paragraph
Note: id attribute value should be unique.
Generally the class attribute is used to set the CSS properties for all tag which have same class name. To set the properties of CSS for two or more than two we should use class attribute with same name.
Note: A class attribute may contain one or more than one name separated by space.
<p class="cls1 cls2 cls3">This is first paragraph
<p class=”cls1 cls3”>This is second paragraph
The title attribute is used to give the title of that tag.
The behavior of this attribute will depend upon the element that carries it, although it is often displayed as a tooltip when cursor comes over the element like image or links or while the element is loading.
<p align="center" title="introduction paragraph!"> This is introduction paragraph. </p>
This attribute is used to set the CSS properties within that tag.
It is called inline style to set the CSS properties.
<p style="color:red; size=20px; text-align:center;">This is paragraph using CSS properties. </p>
At this point of time, we are not learning CSS, so just let's proceed without bothering much about CSS. Here, we need to understand what are HTML attributes and how they can be used while formatting content.