04.24 · Micro-Interactions

Theme Toggle Morph

A sun turns into a moon as the colors switch to dark. Best for theme buttons.

Click it

Press the sun to switch to dark and the moon to switch back, or press Show me.

Try it

Change a setting, then try it again or press Show me.

Speed

How long the sun takes to become a moon.

Feel

Springy overshoots a little, then settles.

Copy the prompt

Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.

Add a theme toggle whose icon turns from a sun into a moon to [the button that switches your site between light and dark]. When it is pressed, the sun's rays shrink into its center while a circle slides across the sun and cuts it into a crescent, so the sun becomes the moon instead of being swapped for another icon. Switch the page's colors at the same moment and at the same pace. Make it a real button whose label says what pressing it will do, and remember the visitor's choice for their next visit. If the visitor has reduced motion turned on, switch the icon and the colors without movement. Match the settings listed below.

Replace the words in brackets with your own element. Your settings are added at the end.

Free and open source. If this helped, a star on GitHub helps other people find it.

Star on GitHub

What it is

The full explanation is in README.md.

Good for

  • Theme buttons
  • Settings
  • Headers

Avoid on

  • Dense forms
  • Icons without labels