CSS Selectors

Introduction to CSS Selectors

CSS works on the principles of Cascading, Inheritance, and Specificity.

CSS Selectors

Selector Type Description
header

Selects an html element
.caption

Selects an html class
#title

Selects an html id tag
Specificity increases from top to bottom

Chaining Selectors

Selectors can be chained in a number of ways:

  1. Nested elements can be selected by separating selectors with a space
  2. Unrelated elements can be selected by separating the selector names with commas

Specificity

In the table above, specificity increases from top to bottom. Element selectors are the least specific, then class, then ID.