HTML class attribute

HTML Class Attribute

The HTML class attribute is used to style multiple elements in the same way.

Examples
				
					<!DOCTYPE html>
<html>
<head>
<title>HTML class attribute</title>
<style>
.cities {
background-color:MediumPurple;
color: white;
margin: 20px 0 20px 0;
padding: 25px;
}
</style>
</head>
<body>

<div class="cities">
<div id="ez-toc-container" class="ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction">
<div class="ez-toc-title-container">
<p class="ez-toc-title" style="cursor:inherit">Table of Contents</p>
<span class="ez-toc-title-toggle"><a href="#" class="ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle" aria-label="Toggle Table of Content"><span class="ez-toc-js-icon-con"><span class=""><span class="eztoc-hide" style="display:none;">Toggle</span><span class="ez-toc-icon-toggle-span"><svg style="fill: #999;color:#999" xmlns="http://www.w3.org/2000/svg" class="list-377408" width="20px" height="20px" viewBox="0 0 24 24" fill="none"><path d="M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z" fill="currentColor"></path></svg><svg style="fill: #999;color:#999" class="arrow-unsorted-368013" xmlns="http://www.w3.org/2000/svg" width="10px" height="10px" viewBox="0 0 24 24" version="1.2" baseProfile="tiny"><path d="M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z"/></svg></span></span></span></a></span></div>
<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-1" href="#Dhaka" >Dhaka</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-2" href="#Chandpur" >Chandpur</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-3" href="#Rajshahi" >Rajshahi</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-4" href="#Dhaka-2" >Dhaka</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-5" href="#Chandpur-2" >Chandpur</a></li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class="ez-toc-link ez-toc-heading-6" href="#Rajshahi-2" >Rajshahi</a></li></ul></li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class="ez-toc-link ez-toc-heading-7" href="#My_Important_title" >My Important title</a></li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class="ez-toc-link ez-toc-heading-8" href="#My_Important_title-2" >My Important title</a></li></ul></nav></div>
<h2><span class="ez-toc-section" id="Dhaka"></span>Dhaka<span class="ez-toc-section-end"></span></h2>
<p> Dhaka is the capital of Bangladesh
and the main city of Dhaka Division. Dhaka is a
megacity and one of the major cities in South Asia.
Located on the banks of the Buriganga River,
it is the largest city in Bangladesh.
The Dhaka
metropolitan area has a population of about 15 million.

</div>

<div class="cities">
<h2><span class="ez-toc-section" id="Chandpur"></span>Chandpur<span class="ez-toc-section-end"></span></h2>
<p>An administrative district of Chittagong
Division in southeastern Bangladesh.
This district is located on the banks of the Meghna
River. The people of Chandpur are famous for their hospitality.</p>
</div>

<div class="cities">
<h2><span class="ez-toc-section" id="Rajshahi"></span>Rajshahi<span class="ez-toc-section-end"></span></h2>
<p>Rajshahi is a major city in the northern region
(North Bengal) of Bangladesh. Rajshahi city is located on the banks of the famous Padma River. It is the divisional city of Rajshahi division.</p>
</div>

</body>
</html>
				
			
Output
HTML class attribute

Dhaka

Dhaka is the capital of Bangladesh and the main city of Dhaka Division. Dhaka is a megacity and one of the major cities in South Asia. Located on the banks of the Buriganga River, it is the largest city in Bangladesh. The Dhaka metropolitan area has a population of about 15 million.

Chandpur

An administrative district of Chittagong Division in southeastern Bangladesh. This district is located on the banks of the Meghna River. The people of Chandpur are famous for their hospitality.

Rajshahi

Rajshahi is a major city in the northern region (North Bengal) of Bangladesh. Rajshahi city is located on the banks of the famous Padma River. It is the divisional city of Rajshahi division.

Using the class attribute on inline elements

class The attribute can also be used on HTML inline elements .

				
					<!DOCTYPE html>
<html>
<head>
<title>HTML class attribute</title>
<style>
.note {
font-size: 120%;
color: Crimson;
}
</style>
</head>
<body>

<h1><span class="ez-toc-section" id="My_Important_title"></span>My <span class="note">Important</span> title<span class="ez-toc-section-end"></span></h1>
<p>Some <span class="note">Important</span> text.</p>

</body>
</html>
				
			
Output
HTML class attribute

My Important title

Some Important text.

HTML Class Attribute

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *