The essentials

Quick reference

One focused task per row. Jump to the related section for complete, working examples.

UseSyntaxExamples
Declare layer order@layer reset, base, components, utilities;View examples
Add rules to a layer@layer components { .button { color: white; } }View examples
Layer an import@import url('vendor.css') layer(vendor);View examples
Match with zero specificity:where(nav a) { color: inherit; }View examples
Use strongest branch specificity:is(#app, .shell) button { padding: .5rem; }View examples
Force inheritancebutton { font: inherit; }View examples
Use property initial value.panel { display: initial; }View examples
Inherit or initialize.item { color: unset; }View examples
Roll back the current origin.widget { all: revert; }View examples
Roll back the current layer.button { color: revert-layer; }View examples
Mark an important declaration.sr-only { position: absolute !important; }View examples

The cascade selects one declared value before inheritance and defaulting produce a value for every property. Organize author rules into intentional layers, keep selectors easy to override, and treat !important as a narrowly scoped exception rather than a specificity strategy.

Step by step

Detailed examples

01

Design layer order before component rules

For normal author declarations, unlayered rules outrank layered rules and later layers outrank earlier ones. Important declarations reverse layer priority. Declare a stable order once, put third-party CSS in a low layer, and avoid leaving routine application rules unlayered by accident.

Predictable architecture
@layer vendor, reset, base, components, utilities;
@import url('/vendor.css') layer(vendor);
@layer base { body { color: #1e293b; } }
@layer components { .button { color: white; background: #2563eb; } }
@layer utilities { .text-danger { color: #b91c1c; } }
Back to quick reference ↑
02

Keep specificity low and intentional

Specificity compares ID, class/attribute/pseudo-class, and type/pseudo-element columns only after origin, importance, layer, and encapsulation order. :where() always contributes zero; :is(), :not(), and :has() take the strongest argument. Source order breaks ties.

Overrideable component defaults
@layer components {
  :where(.card) { padding: 1rem; color: #334155; }
}
@layer utilities {
  .compact { padding: .5rem; }
}
Back to quick reference ↑
03

Know which values inherit

Text properties commonly inherit; layout and box properties commonly do not. inherit forces the parent value, initial uses the property's defined initial value, and unset selects between those behaviors. The all shorthand resets most properties but not custom properties or direction-related exceptions.

Make controls follow document typography
button, input, select, textarea { font: inherit; color: inherit; }
.component-reset { all: unset; display: block; }
Back to quick reference ↑
04

Roll back without guessing old values

revert rolls the declaration back to a lower-priority origin, often exposing user-agent or user styles. revert-layer rolls back only the current cascade layer, revealing an earlier layer or origin. These differ from initial, which may discard useful platform defaults.

Remove one utility override
@layer base, components, utilities;
@layer components { .button { color: white; } }
@layer utilities { .button.quiet { color: revert-layer; } }
Back to quick reference ↑
05

Reserve important declarations for defined contracts

!important participates before specificity and reverses layer order, making earlier important layers stronger. It can be appropriate for user overrides, safety utilities, or integration boundaries. Do not use it to compensate for uncontrolled selectors; first inspect origin, layer, and specificity in developer tools.

Isolate exceptional overrides
@layer important-overrides, base, components;
@layer important-overrides {
  .visually-hidden { position: absolute !important; inline-size: 1px !important; block-size: 1px !important; overflow: hidden !important; }
}
Back to quick reference ↑

Local code tester

Explore cascade layers

Reorder layers and adjust selector specificity to see which declaration wins.

Runs in your browser
Preview

Sources and further reading

References

Authoritative documentation used to verify and expand this cheat sheet.

  1. World Wide Web ConsortiumCSS Cascading and Inheritance Level 5w3.org
  2. World Wide Web ConsortiumSelectors Level 4: Specificityw3.org
  3. World Wide Web ConsortiumCSS Values and Units Level 4w3.org

Help us improve

Found a typo or missing example?

Tell us what would make this cheat sheet clearer, more complete, or more useful.

Share feedback