Skip to main content
InterviewHubPRO
Section Overview
Q37

Question 37 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

74%
CSS3 & Modern Layouts (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

CSS Cascade Layers (`@layer`): Solving Specificity Wars.

senior LevelCode ExampleSystem Design

In Simple Words: Cascade Layers give developers explicit control over which style sheets override each other, regardless of CSS specificity or file order. Styles in a higher layer always override styles in a lower layer:

  • Normal Layer Order: reset -> base -> components -> utilities.
  • A simple class selector in the utilities layer .text-center overrides a high-specificity selector #sidebar .card .title in the components layer!
css
@layer reset, base, components, utilities;

@layer reset {
  * { box-sizing: border-box; margin: 0; }
}

@layer components {
  .btn { background: #3b82f6; color: white; padding: 0.5rem 1rem; }
}

@layer utilities {
  .bg-red { background: #ef4444; } /* Overrides .btn without !important */
}