Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




HTML - Attributes


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 :


Example :



<html>
	<body>
		<p>Hello World</p>
		<p align = "right">Hello World shifts right</p>
	</body>
</html>


Output :




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.


Commonly used attributes in HTML


The most commonly used attributes in HTML are :

  1. style

  2. id

  3. class


Style attribute


The style attribute is used to define CSS properties like font, color, text aligning e.t.c. to an HTML element.


Example :



<html>
	<body>
		<p style = "text-align:right; color:green;">Hello World</p>
	</body>
</html>


Output :




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>

id attribute


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.


Example :



<html>
	<body>
		<p id = "myId">Hello World</p>
	</body>
</html>


Output :




class attribute


The class attribute is used to associate an HTML with CSS. We will be learning more about class in the coming tutorials.