CHAPTER 83
CSS Cascade Layers
Learn how @layer organizes CSS rules into explicit cascade layers.
01. What is CSS Cascade Layers?
Cascade layers provide a structured way to control the order of CSS rules.
@layer can separate reset, components and utility styles.
Layers can make large CSS projects easier to manage.
02. Syntax
@layer reset, components, utilities;
@layer components {
.card {
padding: 20px;
}
}
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
@layer base, components, utilities;
@layer base {
body {
margin: 0;
}
}
@layer components {
.card {
padding: 25px;
background: #dbeafe;
}
}
@layer utilities {
.text-center {
text-align: center;
}
}
</style>
</head>
<body>
<div class="card text-center">
AIFA Coding Lab
</div>
</body>
</html>
04. Important Points
✓
@layer creates explicit cascade layers.
✓
Layers are useful for organizing large stylesheets.
✓
You can define layer order explicitly.
✓
Layers can reduce specificity management problems.
05. Common Mistakes
⚠
Creating too many unnecessary layers.
⚠
Not understanding layer order.
⚠
Mixing layered and unstructured CSS without a plan.
06. Real World Use
Cascade layers are useful in large websites, design systems and projects with third-party styles.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Create CSS Layers
Create base, component and utility layers and style a simple card.