ID and Class are the selectors in the CSS.
When to Use ID and Class selector?
When we want to select specific element on the page. you can select through ID and Class name.
Similarity Between ID and Class Selector::
ID and Class selector can be used on multiple elements at the same time.
Sample Program of ID selector: | Output of ID selector: |
Sample Program of Class selector: | Output of Class selector: |
Differences between ID and Class Selector::
1)ID's are unique
2)Each element can have only one ID.
3)If You specify multiple ID's for single element then it won't execute. see the below example.
Sample Program of Multiple ID selector: | Output of Multiple ID selector: |
5)Class selectors are not unique.
5)If You specify multiple Class for single element then it will execute properly.
Sample Program of Multiple Class selector: | Output of Multiple Class selector: |