CSS if() Function: Build a Theme-Aware Component

UX-UI Creative Conection on YouTubeWatch on YouTube

SaveMark complete

Sign in to save videos and track what you’ve finished.

IntermediateDesign Engineering3 min

About this video

This tutorial shows how to use the experimental CSS if() function with a single custom property to switch a card component between light and dark themes. It covers conditional custom properties, fallbacks and semantic HTML, and checks WCAG AA contrast in CodePen.

What you’ll learn

  • Write conditional custom properties with the CSS if() function
  • Set fallbacks for a theme-aware card component
  • Check WCAG AA contrast in light and dark modes