1 Answers
What is the difference between class and ID in CSS?
In CSS, both class and ID are used to apply styles to elements on a web page, but they have some key differences:
- Class: Classes can be used multiple times on different elements within a page. They are denoted by a period (.) followed by the class name in CSS.
- ID: IDs should be unique within a page and are denoted by a hash symbol (#) followed by the ID name in CSS.
While a class can be applied to multiple elements to style them consistently, an ID should only be used once per page to uniquely style a specific element. Classes are typically used for styling multiple elements with similar characteristics, while IDs are more suitable for targeting a specific element for unique styling or JavaScript manipulation.
Please login or Register to submit your answer