HTML class attribute

HTML class attribute is used to style the content that is inside other HTML elements.

<style>
.style{
	font-size:20px;
	font-transform:uppercase;
	color:white;
	background-color:lightgreen;
}
</style>

<div class="style">This is the division element. Its background-color is light green and the font size of text is 20px. The color of text is blue. Here, the class attribute is being used that styles the div element.</div>

</>
This is the division element. Its background-color is light green and the font size of text is 20px. The color of text is blue. Here, the class attribute is being used that styles the div element.

Attribute values

All possible values of class attribute

The value of the class attribute is simple text that is obtained from the style tag. In the above example, the text after a full stop (.style) in the style tag is the value of the class attribute.

More than one class names are written in the value of class attribute separated by spaces.

<style>
.style1{
	font-size:20px;
	font-transform:uppercase;
	
}
.style2{
	color:blue;
	background-color:lightgreen;
}
</style>

<div class="style1 style2">This is the division element. Its background-color is light green and the font size of text is 20px.</div>
Try</>

Related Tags

The tags that support class attribute

class attribute can be applied on all HTML elements.



Was this article helpful?

 

Email:

Message: