<p id="my-id" class="a b">
    This is a paragraph element.
</p>
* {
    color: red;
}
p {
    color: blue;
}
#my-id {
    color: green;
}
.a {
    color: olive;
}
.b {
    color: pink;
}
This shows the applied CSS styles on the <p> element. Although multiple selectors target the <p> element, the style from the #my-id selector—setting the color to green—is the one that takes effect.
h2 {color: red;} /* Specificity = 0,0,0,1 */

p em {color: purple;} /* Specificity = 0,0,0,2 */

.grape {color: purple;} /* Specificity = 0,0,1,0 */

* .bright {color: yellow;} /* Specificity = 0,0,1,0 */

p.bright em.dark {color: maroon;} /* Specificity = 0,0,2,2 */

#id216 {color: blue;} /* Specificity = 0,1,0,0 */

p#addr [href] {color: gray;} /* Specificity = 0,1,1,1 */
<p id="my-id" class="a b">
    This is a paragraph element.
</p>
* {  /* Specificity = 0,0,0,0 */
    color: red;
}
p {  /* Specificity = 0,0,0,1 */
    color: blue;
}
#my-id {  /* Specificity = 0,1,0,0 */
    color: green;
}
.a {  /* Specificity = 0,0,1,0 */
    color: olive;
}
.b {  /* Specificity = 0,0,1,0 */
    color: pink;
}
This shows the applied CSS styles on the <p> element. The style from the selector with the highest specificity value — #my-id — is applied, resulting in the text color being green.
<!-- Specificity = 1,0,0,0 -->
<h1 id="green-color" style="color:red;">This is a heading selected by an ID.</h1>
<p id="my-id" class="a b">
    This is a paragraph element.
</p>
* {  /* Specificity = 0,0,0,0 */
    color: red;
}
p {  /* Specificity = 0,0,0,1 */
    color: blue;
}
#my-id {  /* Specificity = 0,1,0,0 */
    color: green;
}
.a {  /* Specificity = 0,0,1,0 */
    color: olive !important; /* Overrides other styles using !important */
}
.b {  /* Specificity = 0,0,1,0 */
    color: pink;
}
This shows the applied CSS styles on the <p> element. The style from the selector using !important was applied, overriding the normal specificity rules.
<p class="a b">
    This is a paragraph element.
</p>
.a {  /* Specificity = 0,0,1,0 */
    color: olive;
}
.b {  /* Specificity = 0,0,1,0 */
    color: pink;
}
This shows the applied CSS styles on the <p> element. The style from the selector defined later in the stylesheet will be applied. This is called an override.
<p class="a b">
    This is a paragraph element.
</p>
.a {
    color: olive; /* The same property is declared more than once */
    color: red;   /* The last one will be applied */
}
This shows the applied CSS styles on the <p> element. The final value, red, is applied because it was defined last within the selector.
<p class="a b">
    This is a paragraph element.
</p>
.a {  /* Specificity = 0,0,1,0 */
    color: olive !important;
}
.b {  /* Specificity = 0,0,1,0 */
    color: blue !important;
}
This shows the applied CSS styles on the <p> element. When multiple !important declarations have the same specificity, the one declared last will take precedence. In other words, it overrides the previous ones.