Basic CSS Selectors
CSS selectors are patterns used to select and style HTML elements. The three fundamental selectors are the element selector, the class selector, and the ID selector.
Element Selector
Targets every instance of an HTML tag on the page. For example, p { color: navy; } styles all paragraph elements.
Class Selector
Prefixed with a dot (.), a class selector targets any element that carries that class attribute. Classes are reusable — multiple elements can share the same class.
ID Selector
Prefixed with a hash (#), an ID selector targets the single element with that unique identifier. IDs must be unique within a document.
Specificity
When multiple rules compete, specificity decides which wins: ID (1-0-0) beats class (0-1-0) beats element (0-0-1).