Promptles
Frontend & Responsive Design

CSS Specificity

intermediate

Definition

The way a webpage decides which style wins when several styling rules try to apply to the same element. The more precise a rule is, naming a particular item by ID rather than a whole group, the higher its priority. It's why a designer's careful tweak sometimes loses to an older, more specific rule they forgot existed.

In the wild

A designer writes 'all links should be blue.' But there's an older rule that says 'links inside the navigation bar should be red.' The older rule is more specific, it's targeting a particular spot, so the navigation links stay red even after the new blue rule is added.

More from Frontend & Responsive Design