Animated Toggle

Open in v0
~8.5 kB

Last updated: September 20, 2026

A toggle switch component with smooth animations and multiple variants including morph and icon transitions.

Installation

npx smoothui-cli add animated-toggle

Features

A toggle switch with spring motion, controlled or uncontrolled, three sizes, and full keyboard access. Pick a variant below — the panel beside this column shows that one alone.

Variants

Default

A smooth sliding thumb. The usual on/off control.

Morph

The thumb changes shape while it travels — borderRadius animates with the position.

Icon

Crossfades and scales between custom icons. Pass icons={{ on, off }}.

Sizes

sm, md, and lg scale the track and the thumb together.

Accessibility

Keyboard Interactions

KeyDescription
SpaceToggles the switch on/off
EnterToggles the switch on/off

ARIA Attributes

AttributeElementPurpose
role="switch"ButtonIdentifies the element as a toggle switch
aria-checkedButtonReflects the current on/off state
aria-labelButtonProvides an accessible name via the label prop
disabledButtonIndicates when the toggle is non-interactive

Screen Reader

  • The role="switch" with aria-checked communicates the toggle state to assistive technologies.
  • Focus is visually indicated with a focus-visible ring style.

Reduced Motion

This component respects the prefers-reduced-motion media query via useReducedMotion from Motion. When reduced motion is preferred, all spring animations, icon transitions, and morph effects are disabled instantly.

Props

Created by

Powered by

motion.dev

© 2026 SmoothUI. Built by Eduardo Calvo.