Animated Toggle

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

Open in v0~8.5 kB

Last updated: April 21, 2026

Installation

npx smoothui-cli add animated-toggle

Features

  • Three variants: default (smooth sliding), morph (shape changes during travel), and icon (transitions between icons)
  • Three sizes: sm, md, and lg
  • Controlled and uncontrolled modes
  • Smooth spring animations with Motion
  • Icon variant supports custom icons with crossfade and scale transitions
  • Morph variant animates borderRadius during travel
  • Full keyboard accessibility (Space/Enter to toggle)
  • Proper ARIA attributes with role="switch" and aria-checked
  • Respects reduced motion preferences
  • Disabled state support

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

On this page

Created by

Powered by

motion.dev
Open source & free

Support SmoothUI

Help keep SmoothUI free and actively maintained. Every sponsor helps ship more components, blocks, and animation recipes.