Sun Morphs Into Moon: Dark Mode Toggle in HTML, CSS & Javascript

Axolobit on YouTubeWatch on YouTube

SaveMark complete

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

BeginnerDesign Engineering18 min

About this video

A step-by-step build of a dark mode toggle in vanilla HTML, CSS and JavaScript, where a sun morphs into a moon. It covers CSS variables, responsive layout, saving the theme with localStorage and basic accessibility attributes.

What you’ll learn

  • Switch a whole page between light and dark mode with one data-theme attribute
  • Re-theme a design with CSS custom properties instead of repainting each element
  • Save the chosen theme with localStorage and handle storage errors with try/catch