# CSS Specificity

> The score that picks which CSS rule wins. It counts when two rules hit one part.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** Specificity, Selector Specificity, CSS Specificity Rules

## Think of it like

It is like a game of cards where a king beats any number of jacks.

## Definition

CSS specificity is the score a browser uses to choose between two rules that style the same thing. Each selector gets three counts, written ID-CLASS-TYPE. An ID adds 1-0-0, a class adds 0-1-0, and a tag name adds 0-0-1. The browser compares from the left, so one ID beats any number of classes. If two scores tie, the rule written last wins.

## Example

Emma sets .note to blue, but the text stays red. A rule with #intro .note scores higher, so it wins until she changes it.

## Example code

```css
p { color: black; }        /* 0-0-1 */
.note { color: blue; }     /* 0-1-0 */
#intro p { color: red; }   /* 1-0-1, wins */
```

Three rules hit the same paragraph. The one with an ID has the top score, so the text is red.

## Why it matters

It explains the most common CSS puzzle: a style you wrote that does nothing. Low scores keep styles easy to change.

## Common mistake

Adding !important to win a fight. It beats the score but starts a new fight that only another !important can win.

## Three principles

- **Three counts.** IDs, then classes, then tags.
- **Left column first.** One ID beats any number of classes.
- **Ties go last.** The later rule wins a tie.

## Related terms

- [CSS Selector](https://learn.benibix.com/term/development/css-selector)
- [Cascading Style Sheets (CSS)](https://learn.benibix.com/term/development/css)
- [CSS Pseudo-Class](https://learn.benibix.com/term/development/css-pseudo-class)
- [CSS Custom Properties](https://learn.benibix.com/term/development/css-custom-properties)
- [Tailwind CSS](https://learn.benibix.com/term/development/tailwind-css)

## Taught in

- [CSS Selectors and Specificity](https://learn.benibix.com/learn/development-web/css-selectors-and-specificity): HTML, CSS and JS, 7/14

![A table with three columns, ID, CLASS and TYPE, and four selectors. p scores 0-0-1. .note scores 0-1-0. a:hover scores 0-1-1, since the pseudo-class counts as a class. #intro .note p scores 1-1-1 and is marked the winner, since the left column is compared first.](https://learn.benibix.com/diagrams/dev5-specificity.svg)

---

Source: https://learn.benibix.com/term/development/css-specificity
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
