What is the difference between id and class in HTML?

An id must be unique, so it identifies only one element on the page. A class can be used on many elements, and one element can have many classes.

Pointidclass
ElementsOnly oneMany
CSS selector#name.name
Many on one elementNoYes, separated by a space
<style>
  #title { color: navy; }
  .note  { background: #fff3cd; }
</style>

<h1 id="title">Heading</h1>
<p class="note">Note one</p>
<p class="note">Note two</p>

An id is also used as the target of a link (#id). See HTML Class and ID.


Learn more about the similar topics:
Tutorials
List of common HTML Tags
HTML Elements and Tags
HTML Attributes
HTML Block and Inline Elements
HTML Div and Span
HTML Class and ID
Exercises & Assignments
No Content Found.
Interview Questions & Answers
Do all HTML tags require both a begin and end tag?
What is the difference between HTML tags and elements?
What is an attribute in HTML?
What is the difference between DIV, SPAN and paragraph tag in HTML?
What is the difference between inline and block elements in HTML?
What are void (empty) elements in HTML?
What is the difference between id and class in HTML?