How to make a website light/dark toggle with CSS & JS

Kevin Powell on YouTubeWatch on YouTube

SaveMark complete

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

IntermediateUI17 min

About this video

Shows how to build a light and dark mode toggle switch for a website using JavaScript, saving the visitor's preference in localStorage so it persists on later visits. The description also points to a media query alternative for matching the system setting.

What you’ll learn

  • Build a light and dark mode toggle switch with JavaScript
  • Save a visitor's theme preference in localStorage
  • Apply theme changes across a page with CSS