CSS Hack: Toggle Dark Mode with :has()

Web Bae on YouTubeWatch on YouTube

SaveMark complete

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

IntermediateUI3 min

About this video

A short CSS tutorial showing how to toggle dark mode, light mode and themes using the :has() selector with only HTML and CSS, no JavaScript. It assumes familiarity with writing HTML and CSS.

What you’ll learn

  • Build a dark mode toggle using the CSS :has() selector
  • Switch themes with HTML and CSS alone, without JavaScript
  • Apply a theme toggle to a Webflow or other web page