CSS selectors and specificity

Let's start with Basic CSS Selectors

Type Selectors

Element Selector Specificity
<body> body{} 0-0-1
<html> html{} 0-0-1
<h1> h1{} 0-0-1
<p> p{} 0-0-1
<span> span{} 0-0-1
<em> em{} 0-0-1

Class selectors

Element Selector Specificity
<body class= "highlight"> body.highlight{} 0-1-1
<span class= "highlight"> span.highlight{} 0-1-1
<h1 class= "highlight"> h1.highlight{} 0-1-1
<div class= "notebox"> div.notebox{} 0-1-1
<div class= "notebox warning"> div.notebox.warning{} 0-2-1

ID selectors

Element Selector Specificity
<h1 id="heading"> h1#heading{} 1-0-1
<p id="one"> p#one{} 1-0-1
<h1 id="heading"> #heading{} 1-0-0
<h1 id="one"> #one{} 1-0-0
<p id="header"> p[id="header"]{} 1-0-1
<h1 id="header"> h1,
#header{}
0-0-1
1-0-0
Basic CSS selectors
CSS selectors
Pseudo-classes and pseudo-elements
Handling conflicts
Combinators
Descendant combinator
Child combinator