Home/CSS Complete Masterclass 2026/Advanced @-Rules (@supports, @scope)

Advanced @-Rules (@supports, @scope)

Learn how to build resilient and encapsulated CSS. Master feature queries to support older browsers and the new @scope rule for component isolation.

Expert Answer & Key Takeaways

Learn how to build resilient and encapsulated CSS. Master feature queries to support older browsers and the new @scope rule for component isolation.

1. The Safety Net: @supports

Feature Queries (@supports) allow you to check if the user's browser supports a specific CSS property-value pair before applying it.

The Example: Modern Glassmorphism Fallback

.card { background: white; } @supports (backdrop-filter: blur(10px)) { /* Only run this if the browser supports blur */ .card { background: rgba(255, 255, 255, 0.4); backdrop-filter: blur(10px); } }
RulePurposeKey Concept
@supportsDetects browser features.'If support X, then apply Y.'
@scopeLimits CSS to a component.'Only apply these rules INSIDE this div.'
@mediaChecks device state.Screen width, dark mode, orientation.
@containerChecks parent size.Component-driven responsiveness.

2. Component Isolation: @scope

Previously, we used BEM logic to keep styles from leaking. In 2026, we use @scope. It tells the browser where to start and stop applying styles.
/* Start at .card, but STOP at any nested .section */ @scope (.card) to (.section) { /* Only applies to p tags inside the card BUT outside child sections */ p { color: blue; } }
[!TIP] The Donut Scope: This 'Stopping' logic is called 'Donut Scoping.' It allows you to style a container and its immediate children while leaving any 'slotted' or 'nested' components perfectly untouched.

3. Structural @-rules

  • @import: Pulls in another CSS file. (Performance warning!).
  • @font-face: Loads custom web fonts from a server.
  • @keyframes: Defines the steps of an animation timeline.
[!IMPORTANT] Avoid @import in production: Every @import triggers a new HTTP request and blocks the page from loading. It is much better to bundle your CSS files into one during development or use @layer for organization.

🎯 Practice Challenge: The Feature Switch

  1. Create an OKLCH color (a very vibrant one).
  2. Task 1: Use @supports to apply that OKLCH color only if the browser supports it.
  3. Task 2: Provide a standard HSL or RGB color as a 'Base' fallback outside the rule.
  4. Task 3: Observe how the browser 'gracefully degrades' to the simpler color on older systems while showing the 'neon' color on modern ones.

4. Senior Interview Corner

Q: What is the difference between @media and @supports?
A: @media checks the Environment (Is the screen narrow? Is it a printer? Is it dark mode?). @supports checks the Capability (Can the browser process this specific piece of CSS code?). You use @media for responsive design and @supports for modern feature implementation.
Q: Why was @scope created if we already have Shadow DOM?
A: Shadow DOM (used in Web Components) is a 'Hard' barrier that is difficult for global CSS to cross. @scope is a 'Soft' barrier built natively for standard CSS. It provides the same benefits (isolation) without the complexity of JavaScript or the inability to share global brand variables.

Top Interview Questions

?Interview Question

Q:Which @-rule is used to check if a browser is capable of rendering a specific CSS feature?
A:
@supports

?Interview Question

Q:What is the primary benefit of the @scope rule?
A:
It limits styles to a specific part of the DOM tree

Course4All Engineering Team

Verified Expert

Frontend Architects

Focused on layout performance, modern CSS4+ features, and responsive design, our team provides the blueprint for professional web interfaces.

Pattern: 2026 Ready
Updated: Weekly