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.

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.

More optionsFewer options

Number of options

Up to five short options fit on one line.

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.

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

  • View switchers
  • Filters
  • Date ranges

Avoid on

  • Many options
  • Long labels