What is the difference between classes and IDs in CSS?

1 Answers
Answered by suresh

What is the difference between classes and IDs in CSS?

Classes and IDs are both used in CSS to apply styles to elements, but they have some key differences:

  • Classes: Classes can be used multiple times in an HTML document. This means that you can apply the same styles to multiple elements by assigning them the same class. To apply a class to an element in CSS, you use a period (.) followed by the class name.
  • IDs: IDs are used to uniquely identify a single element on a page. This means that each element can only have one ID, and that ID should be unique on the page. To apply an ID to an element in CSS, you use a hash symbol (#) followed by the ID name.

Overall, classes are more versatile and can be used multiple times, while IDs are used for unique identification of elements on a page.

Answer for Question: What is the difference between classes and IDs in CSS?