- Interaction
- Click toggle
- Category
- Form
- Duration
- 0.50 s
- Frame rate
- 30 fps
- Artboard
- 32 × 32 px
- Lottie size
- 1.3 kB
Toggle
Animated toggle icon
Toggle is a 0.5 s micro animation that toggles between two states on click; use it for checkboxes, radio buttons and switches. Its static SVGs cover the toggle-left and toggle-right states, so the resting icon still shows which one is active.
Free under the MIT license · Markdown version · About the files
Use it
npm install react-useanimationsimport UseAnimations from 'react-useanimations';
import toggle from 'react-useanimations/lib/toggle';
<UseAnimations animation={toggle} size={32} />npx shadcn@latest add https://useanimations.com/r/toggle.jsonimport { AnimatedToggle } from '@/components/animations/toggle';
<AnimatedToggle size={24} /><div id="toggle-icon" style="width: 48px; height: 48px"></div>
<script src="https://cdn.jsdelivr.net/npm/lottie-web@5.13.0/build/player/lottie_light.min.js"></script>
<script>
const el = document.getElementById('toggle-icon');
const a = lottie.loadAnimation({ container: el, renderer: 'svg', loop: false, autoplay: false, path: 'https://useanimations.com/icons/toggle.json' });
const motion = matchMedia('(prefers-reduced-motion: reduce)');
let isOn = true; // Frame 0 is on; the final frame is off.
el.addEventListener('click', () => { isOn = !isOn; if (motion.matches) a.goToAndStop(isOn ? 0 : a.totalFrames - 1, true); else { a.setDirection(isOn ? -1 : 1); a.play(); } });
</script>Toggle runs on the light build, lottie_light.min.js.
import LottieView from 'lottie-react-native';
<LottieView source={{ uri: 'https://useanimations.com/icons/toggle.json' }} autoPlay loop={false} style={{ width: 48, height: 48 }} />import Lottie
LottieView {
await LottieAnimation.loadedFrom(url: URL(string: "https://useanimations.com/icons/toggle.json")!)
}
.playing(loopMode: .playOnce)
.frame(width: 48, height: 48)val composition by rememberLottieComposition(LottieCompositionSpec.Url("https://useanimations.com/icons/toggle.json"))
LottieAnimation(composition, iterations = 1, modifier = Modifier.size(48.dp))import 'package:lottie/lottie.dart';
Lottie.network('https://useanimations.com/icons/toggle.json', width: 48, height: 48, repeat: false)Bundle toggle.json with the app to use it offline.
<img src="https://useanimations.com/icons/toggle/toggle-left.svg" alt="Toggle" width="24" height="24" />
<img src="https://useanimations.com/icons/toggle/toggle-right.svg" alt="Toggle" width="24" height="24" />Inside <img> the SVG draws black; inline it to follow the text color.
Static SVG
Questions about the Toggle icon
›Can my app decide whether Toggle shows toggle-left or toggle-right?
Make it controlled: pass active and flip it in onClick, e.g. active={on} onClick={() => setOn(!on)}. true plays to the last frame and false back to the first; an icon that mounts with active already true starts there without animating, and with reduced motion it jumps instead of playing.
›Should the Toggle icon be a <button>?
Put its events on a real button with the render prop: render={(events, icon) => <button aria-label="Toggle" aria-pressed={on} {...events}><span {...icon} /></button>}. The animation itself stays aria-hidden, and aria-pressed tells screen readers which state is on.