Blog Detail

Home Blog Detail

What is the difference between class and id?

Blog Img
  • ID: An ID must be unique within a page. It should only be used for a single element.
  • Class: A class can be applied to multiple elements on the page. Multiple elements can share the same class.
  • IDs have higher specificity compared to classes
<div id="header" class="section">Header</div>
<div id="footer" class="section">Footer</div>
<div class="section">Content</div>

Example:

#header {
background-color:red;
}
.section {
color:#fff;
font-size:16px;
}

© 2025Think4u. All Rights Reserved.