Two quizzes, one blind spot

Both of these puzzles hinge on the same confusion: the property you think you're reading is not the property actually in play. The first comes from Lea Verou's widely shared quiz, which 82% of respondents got wrong.

:root {
  --accent-color: skyblue;
}

div {
  --accent-color: revert; 
  background: var(--accent-color, orange);
}

A reasonable line of reasoning runs like this: --accent-color is declared, so the orange fallback is irrelevant; the value is revert, so treat it as background: revert;; background doesn't inherit, and if forced to it would inherit from <body> rather than the root; therefore the result is transparent.

That is not the outcome. As Verou explains, revert cancels author styles and rolls the property back to whatever the user stylesheet and UA stylesheet would provide. Absent a --accent-color declaration in the user stylesheet — and UA stylesheets don't set custom properties — the property ends up with no value at all. Custom properties are inherited (unless registered with inherits: false, which this one is not), so the inherited value comes through: skyblue.

The second brain twister

Stephen's variant follows the same pattern of mistaken identity.

CSS variable riddle: What color will the <p> element be? pic.twitter.com/NpIi1IY3dw

— Shaw ( front-end.social/@shshaw ) (@shshaw) June 4, 2021

The intuitive reading: --color is declared, so the blue fallback is out; red is overridden by the second declaration; the result is effectively p { color: inherit; }; the paragraph inherits yellow from <body>.

Wrong again. Here inherit pulls from the next ancestor up the tree that actually sets the value — html — so the answer is green. Normal inheritance works exactly this way; the difficulty is purely that color and --color are easy to conflate.

Registration changes the rules

Declaring a custom property with @property lets you specify whether it inherits, which alters the outcome of puzzles like these.

@property --property-name {
  syntax: '<color>';
  inherits: false;
  initial-value: #c0ffee;
}