What is the difference between id and class selectors in CSS?

Subh Prakash Singh
Invent the Future
An ID selector targets a single, unique element on the page and must be used only once, whereas a class selector can be assigned to multiple elements across the page. The ID selector is more specific and overrides class selectors in case of conflicts.
For example,
#primary { color: blue; } /* Targets an element with the id 'primary' */
.button { color: red; } /* Can be used on multiple elements with the class 'button' */









