π Introduction
CSS provides special global keywords that let you reset, revert, or control how properties behave in the cascade. These four β all, revert, revert-layer, and unset β are extremely powerful for resetting components, fixing unexpected inheritance, and writing clean CSS architecture. β¨
π§ 1. all β Reset ALL CSS Properties
The all property is a special CSS property that targets every CSS property (except unicode-bidi and direction). You can use it with keywords like initial, inherit, unset, or revert.
β¨ Example: Reset a component completely
Using all: initial
button {
all: initial;
font-size: 16px;
padding: 8px 12px;
}This resets everything β box model, font styles, borders, etc., giving you a clean slate.
| Keyword | Effect on all |
|---|---|
| all: initial | Resets everything to browser defaults π |
| all: inherit | Inherits all properties from parent π |
| all: unset | Acts like inherit for inherited properties, else initial βοΈ |
| all: revert | Reverts to author/user-agent stylesheet π |
Note
π 2. revert β Roll Back to Browser or Author Default
revert tells the browser:βIgnore my rule and go back to what the browser or earlier stylesheet said.β
Using revert
p {
color: red;
}
p.override {
color: revert; /* Goes back to default (usually black) */
}β Useful for overriding opinionated frameworks
β Helps undo styles without guessing defaults
π§ When does revert NOT work?
- If no earlier rule defines that property
- If user-agent default is the only fallback
ποΈ 3. revert-layer β Roll Back Within Cascade Layers Only
revert-layer is similar to revert but limited to CSS within the same cascade layer. It ignores rules from other layers completely.
revert-layer Example
@layer framework {
button {
color: blue;
}
}
@layer app {
button {
color: red;
}
.reset-btn {
color: revert-layer; /* Goes back to 'red', not 'blue' */
}
}β revert-layer undoes only styles defined in your own layer
β It does NOT revert to framework or browser defaults
Note
βοΈ 4. unset β Smart Reset
unset works like a hybrid:
- Acts like inherit for inherited properties
- Acts like initial for non-inherited properties
unset Example
p {
color: green; /* inherited property */
margin: 20px; /* non-inherited */
}
.special {
color: unset; /* becomes inherited from parent */
margin: unset; /* becomes initial (0) */
}π§ This makes unset very useful for undoing modifications without breaking layout.
π― Summary Comparison
| Keyword | What It Does | Where It Reverts To |
|---|---|---|
| all | Resets ALL properties at once | Depends on keyword: initial / inherit / revert / unset |
| revert | Undo author rule | Browser defaults or earlier stylesheet |
| revert-layer | Undo rule in current cascade layer | Layer-defined previous values only |
| unset | Smart reset | inherit (for inherited props) or initial |
π§ Real-World Example: Fixing Overly Opinionated Framework CSS
Undo Framework Styles
/* Framework forces big padding */
.card {
padding: 40px;
}
.my-card {
padding: revert; /* Back to browser or earlier stylesheet */
}π§© Example: Creating a Clean Button Reset
Button Reset
button {
all: unset;
padding: 8px 16px;
background: black;
color: white;
cursor: pointer;
}β Removes default borders, fonts, spacing β a perfect blank canvas.