04.06 ยท Micro-Interactions

Toggle / Switch Slide

The knob slides across as the switch turns on or off. Best for settings.

Click it

Click or tap a switch to turn it on or off, or press Show me.

Try it

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

Speed

Fast feels mechanical; slow can feel sluggish.

Feel

Gentle gives the knob weight; Even feels robotic.

More optionsFewer options

The third switch's knob goes past the end, then settles.

On color

The track color when a switch is on.

Copy the prompt

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

Add an animated toggle switch to [the on/off setting you want to control]. Build it on a real checkbox so it works with the keyboard and screen readers. When it is turned on, the round knob slides across the track and the track fills with color; when it is turned off, both go back. When the settings ask for it, let the knob go slightly past the end and settle, so it feels springy. Make the whole switch and its label easy to tap. If the visitor has reduced motion turned on, move the knob without sliding. 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

  • Settings
  • Preferences
  • Dark mode switches

Avoid on

  • Forms sent later
  • More than two options