HTML & CSS · Junior · Question 8 of 75

What is the main difference between the id and class attributes?

Explanation

An id value must be unique in the document: anchors (#section), label for and ARIA attributes reference it. Classes are reused across many elements, and one element can have several. An id selector weighs (1,0,0) versus (0,1,0) for a class, which is why classes are usually preferred for styling.

Further reading

Problem with a question

HTML & CSS · Junior · question 8

Test yourself

Take the HTML & CSS · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz