Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 2.5 — Cascade Layers
CSS · Example 2 of 2

Important declarations reverse the layer order; revert-layer

Cascade layers (@layer) group rules into named layers whose order you declare up front; a later layer beats an earlier one before specificity is even compared, so resets, frameworks and your own code stop fighting.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write CSS with three layers, reset, base and components. The reset removes all margins, base gives p a bottom margin of 1em, and a .card p component rule sets its margin to 0.5em. Which margin does a paragraph inside .card get?

02

A framework's .btn { background: blue; } is unlayered and loaded before your stylesheet. You add @layer app { .btn { background: green; } }. What colour is the button, and how do you fix it?

Explain it without notes

01

What is a cascade layer, and at which step of the cascade are layers compared?

02

How is the order of layers decided? What happens if the layer statement comes after some layer blocks?

03

How do unlayered styles rank against layered styles, for normal and for important declarations?

04

How would you use layers to make sure your code always beats a third-party CSS framework?

Important declarations reverse the layer order; revert-layer

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

Paragraph 1: crimson
Paragraph 2: tomato
Paragraph 3: navy