In the previous tutorial, we have seen HTML elements. In this tutorial, we will take a step forward and understand HTML attributes that provides some extra details for an HTML element.
Let us understand HTML attributes with the below example :
<html> <body> <p>Hello World</p> <p align = "right">Hello World shifts right</p> </body> </html>
In the above example, we have a tag called <p>,
<p>Hello World</p>
That is used to print Hello World.
Next, we have used the 'align' attribute with the <p> tag,
<p align = "right">Hello World shifts right</p>
The align = "right" in the <p> tag shifts the text Hello World shifts right to the right side of the screen.
The most commonly used attributes in HTML are :
The style attribute is used to define CSS properties like font, color, text aligning e.t.c. to an HTML element.
<html> <body> <p style = "text-align:right; color:green;">Hello World</p> </body> </html>
In the above example, we have used the 'style' attribute to set the text aligning to right and color to green to the text Hello World.
<p style = "text-align:right; color:green;">Hello World</p>
We will be explaining id attribute in coming tutorials. For now just understand that the id attribute used to define a single id for an HTML element.
<html> <body> <p id = "myId">Hello World</p> </body> </html>
The class attribute is used to associate an HTML with CSS. We will be learning more about class in the coming tutorials.