Selectors and the Cascade
Select elements with type, class, ID, and attribute selectors. Understand specificity, inheritance, and the cascade to predict which styles win.
What Is CSS?
CSS (Cascading Style Sheets) is the language that controls visual presentation. You write rules — each rule has a selector that targets elements and a declaration block with property-value pairs.
selector {
property: value;
another-property: value;
}Type, Class, and ID Selectors
The three fundamental selectors: type targets all elements of a tag (p), class targets elements with a class (.card), ID targets one element by id (#logo). Prefer classes — IDs have very high specificity.
p { color: #333; } /* type */
.card { padding: 16px; } /* class */
#logo { width: 200px; } /* ID */