×

css · level 1 · unit 4 · lesson 4

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A more exact selector beats a later one.

In lesson 8 the later rule won. That only happens when the selectors are equally exact. How exact a selector is has a name: .

A tag like p picks lots of elements, so it is the least exact. A class is more exact. An id, which picks one element, is the most exact of all.

So an id beats a class, and a class beats a tag, wherever they sit in the CSS. Only when two selectors are equally exact does the later one win.

<p id="intro" class="tip">Who wins?</p>
#intro {
  color: green;
}
.tip {
  color: orange;
}
p {
  color: blue;
}

Press show my page to see it here.

The id rule comes first but still wins, so the words are green.