Course contentsShow
← Web Development
Lesson 456 of 2,9828. Advanced CSS Selectors and FeaturesFree lesson

Browser Support and Progressive Enhancement

Check compatibility for modern pseudo-classes and implement fallbacks using @supports and feature detection.

Browser Support and Progressive Enhancement

You'll learn how to check whether modern pseudo-classes are supported by a browser and provide fallback styles for older browsers.

The Challenge of Cutting-Edge CSS

Modern pseudo-classes like :has(), :is(), :focus-visible(), and :user-valid are powerful, but not all browsers support them yet. If you use these features without checking support, some users might see broken layouts or missing functionality. That's where progressive enhancement comes in—building a solid baseline experience first, then layering on advanced features for browsers that support them.

Using @supports for Feature Detection

The @supports rule lets you test if a browser understands a specific CSS feature before applying it:

/* Baseline styles everyone gets */
button:focus {
  outline: 2px solid blue;
}

/* Enhanced styles only for supporting browsers */
@supports selector(:focus-visible) {
  button:focus {
    outline: none;
  }
  
  button:focus-visible {
    outline: 2px solid blue;
    outline-offset: 2px;
  }
}

Think of @supports like a safety net—it asks "Can you do this trick?" before attempting it.

Testing Pseudo-Class Support

For pseudo-classes specifically, use the selector() function:

@supports selector(:has(> img)) {
  .card:has(> img) {
    padding-top: 0;
  }
}

This ensures :has() styles only apply when the browser understands them.

The Progressive Enhancement Mindset

Always start with styles that work everywhere, then enhance. Older browsers get a functional experience; modern browsers get the polish. Never make core functionality depend on cutting-edge features alone.

Key Takeaway: Use @supports selector() to detect modern pseudo-class support and provide fallback styles for browsers that don't understand them—build a baseline first, enhance second.