Difference between class and id in css

The id Selector

The id selector is used to specify a style for a single, unique element.

The id selector uses the id attribute of the HTML element, and is defined with a "#".





The class Selector

The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements.
This allows you to set a particular style for many HTML elements with the same class.
The class selector uses the HTML class attribute, and is defined with a "."
 
Classes used multiple times in the same HTMl document but If you use ID more than one time it will cuase validation error. while using class we use (".") and in other hand Id preceded by ("#")

Sample

#top {
background-color: #FFFF;
padding: 36px
}

.intro {
color: Blue;
font-weight: bold;
}
 
Back
Top