Cascading Style Sheets (CSS) is the styling language of the web, responsible for controlling the visual presentation of HTML documents. Introduced in 1996 and continuously evolved through modular specifications, CSS enables developers to separate content from presentation, creating responsive, accessible, and visually compelling user interfaces. While HTML provides structure and JavaScript adds interactivity, CSS bridges the gap between raw markup and polished design. The key mental model is that CSS is a cascade: origin, importance, layers, specificity, and source order together decide which rule actually wins, and inheritance fills in the rest. Modern CSS adds native nesting, cascade layers, container queries, anchor positioning, scroll-driven animations, and view transitions, so a working grasp of the whole cascade is what keeps a stylesheet maintainable as it grows.
What This Cheat Sheet Covers
This topic spans 38 focused tables and 347 indexed concepts, 238 flashcards, 12 practice tests with 420 questions. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Selectors — Element, Class, and ID
These are the building blocks you reach for first, the patterns that tell the browser which elements a rule applies to. Class selectors carry most of the day-to-day load because they're reusable, while ID selectors stay deliberately rare given the specificity they drag into every later override. The attribute variants at the bottom target elements by what's written in their HTML, matching a value exactly, by substring, by prefix or suffix, or as a whole word in a space-separated list.
| Selector | Example | Description | |
|---|---|---|---|
.btn { padding: 10px; } | • Targets elements with a specific class attribute • reusable across multiple elements. | ||
p { color: blue; } | • Targets all elements of a specific HTML tag • applies broadly across the document. | ||
#header { height: 80px; } | • Targets a single unique element with a specific ID • high specificity, use sparingly. | ||
* { margin: 0; } | • Matches every element in the document • adds zero specificity, which is what makes it safe for CSS resets. | ||
[type="text"] { border: 1px solid; } | Targets elements based on the presence or exact value of an attribute. | ||
[class*="btn"] { cursor: pointer; } | Matches elements whose attribute value contains the specified substring anywhere. | ||
[href^="https"] { color: green; } | Matches elements whose attribute value begins with the specified string. | ||
[src$=".jpg"] { border: 2px solid; } | Matches elements whose attribute value ends with the specified string. | ||
[class~="active"] { font-weight: bold; } | Matches elements whose space-separated attribute value list contains the exact word. | ||
[lang|="en"] { font-style: italic; } | Matches an attribute value that is exactly the term or begins with it followed by a hyphen, commonly used for language subcodes. |