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.
| Point | id | class |
|---|
| Elements | Only one | Many |
| CSS selector | #name | .name |
| Many on one element | No | Yes, 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 |
| No Content Found. |
| Exercises & Assignments |
| No Content Found. |
| Interview Questions & Answers |
| No Content Found. |