04.28 · Micro-Interactions
Segmented Control
A highlight slides to the option you pick. Best for switching views.
Click it
Press an option or move with the arrow keys, or press Show me.
Inside, one highlight is shared by all the options: to change option it slides over from where it was and stretches to the new option's width. Press an option, or Show me.
Jumps: the highlight is simply on the new option; Slides: it glides over and stretches to fit, so you see where it came from. Press an option, or Show me.
Try it
Change a setting, then try it again or press Show me.
Speed
How long the highlight takes to slide.
Feel
Springy runs a little past, then settles.
Highlight
A filled pill, or a thin line under the option.
Copy the prompt
Paste it into an AI assistant such as ChatGPT, Claude or Cursor to build this in your own project.
Add a segmented control to [the row of options people switch between, such as Day, Week and Month]. Show the options side by side with one highlight behind the chosen one. When another option is chosen, slide the highlight over to it and stretch or shrink it to that option's width, while the labels' colors cross over as it lands. Measure the chosen option and move the highlight with transforms only, measuring again when fonts load or the window resizes. Make it one group of radio buttons that the arrow keys move through. If the visitor has reduced motion turned on, move the highlight without sliding. 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.