Repaso
EspaƱol
Frontend & WebIntermediateFE-16

Which CSS selector has the highest specificity?

Options

  1. div p
  2. .card .title
  3. #header (Correct option)
  4. p

Answer

#header

Why

When several CSS rules target the same element, the more specific selector wins. Ranking: inline styles > IDs > classes, attributes and pseudo-classes > element names.

#header (one ID) beats .card .title (two classes), which beats div p (two elements).

If specificity is equal, the rule written last wins. Avoid !important.

Remember

ID > class > element.

Key terms

Practice this question in Repaso