CSS light-dark() now supports images

💡 CSS massive upgrade: light-dark() now supports images! We've been using light-dark() for colors for a while, but the spec just got a major upgrade: It now supports images. 🖼️ 🛑 The "Old" Way (Boilerplate Alert) Until now, swapping a background pattern or a logo meant jumping back and forth between :root and @media (prefers-color-scheme: dark) :root { --bg: url(light-pattern.png); } @media (prefers-color-scheme: dark) { :root { --bg: url(dark-pattern.png); } } .hero { background-image: var(--bg); } ✨ The "Modern" Way (Clean & Concise) With the new update, you can handle the logic right where the property is defined. It's cleaner, more readable, and easier to maintain. .hero { color-scheme: dark; background-image: light-dark(url(light-pattern.png), url(dark-pattern.png)); } 🛠️ How to experiment safely today Since this is a fresh update, you'll want to use feature detection. Because linear-gradient() is technically an <image>, you can use it to test for support: @supports (background-image: light-dark(linear-gradient(white, white), linear-gradient(black, black))) { /* Modern image-switching logic here */ } Are you still using traditional media queries for theme switching, or have you fully embraced the light-dark() life yet? 👇 Read more: Article by Bramus https://lnkd.in/gsE2KrdA #CSS #CSSTricks #CSSHacks #Frontend #WebDevelopment #CodingTips #WebDev #itsmacr8

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories