Jump to content

diffrence between class and id


anandgp

Recommended Posts

Hi,

 

I am not able to understand the difference between a class and an id. Both of them define property and it's value.

 

 

.container {
min-width: 900px;
}
#top {
background-color: #84c754;
color: #ffffff;
padding: 15px;
}
--------------------------------------
<div class="container">
<div id="top">
<h1>Welcome to My Homepage</h1>
</div>
</div>

Regards,

-Anand

 

 

Link to comment
Share on other sites

The id is used when you want to reference an element that is unique, when there is only one on the page. A class can be used to give a same style to multiple different elements.

 

The id is also used by Javascript to easily access an element.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...