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.
Inside, the dashed circle, hidden in Normal, slides over the sun and cuts a bite out of it, leaving a moon, while the rays shrink to the center. Press the button, or Show me.
Swaps at once: the moon simply replaces the sun; Becomes a moon: the same sun is cut into a moon while the card flips. Press the button, or 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.
Your settings
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 GitHubWhat it is
The full explanation is in README.md.