# Moon animated icon

> Free Moon animated icon that plays once on hover. MIT-licensed for React, shadcn/ui, Lottie JSON and SVG.

Use the Moon icon for light and dark theme switches: it plays once on hover and takes 1.33 s. Hover-to-play icons typically liven up arrow links, feature lists, toolbar buttons and landing page cards. Also known as dark mode and night.

## Facts

- Interaction: [Hover replay](https://useanimations.com/interactions/hover-replay). Plays once on mouseenter unless reduced motion is preferred. Leaving does not stop it; entering during playback does not restart it.
- Category: [Weather](https://useanimations.com/categories/weather)
- Duration: 1.33 s at 30 fps
- Artboard: 32 × 32 px
- Lottie size: 1.5 kB
- License: MIT, attribution optional ([Licencing & Terms](https://useanimations.com/licencing-and-terms))

## Files

- Lottie JSON: https://useanimations.com/icons/moon.json
- Static SVG (moon): https://useanimations.com/icons/moon/moon.svg
- ZIP (Lottie JSON and SVGs): https://useanimations.com/icons/moon.zip
- shadcn registry item: https://useanimations.com/r/moon.json
- Web page: https://useanimations.com/icons/moon

## React

```bash
npm install react-useanimations
```

```jsx
import UseAnimations from 'react-useanimations';
import moon from 'react-useanimations/lib/moon';

<UseAnimations animation={moon} size={32} />
```

## shadcn/ui

```bash
npx shadcn@latest add https://useanimations.com/r/moon.json
```

```tsx
import { AnimatedMoon } from '@/components/animations/moon';

<AnimatedMoon size={24} />
```

## HTML and lottie-web

```html
<div id="moon-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('moon-icon');
  const a = lottie.loadAnimation({ container: el, renderer: 'svg', loop: false, autoplay: false, path: 'https://useanimations.com/icons/moon.json' });
  const motion = matchMedia('(prefers-reduced-motion: reduce)');
  el.addEventListener('mouseenter', () => { if (!motion.matches && a.isPaused) a.playSegments([0, a.totalFrames], true); });
</script>
```

## FAQ

### Does Moon restart when the pointer comes back mid-animation?

A run that has started plays its 1.33 s to the end, so moving in and out quickly doesn't make it stutter; the next enter after that plays it again. Taps on touch screens are ignored, but keyboard focus plays it.

### Will screen readers read the Moon icon?

By default it is aria-hidden. Pass aria-label="Moon" to announce it as an image, or leave it hidden when the link or button it sits in has its own text.

### Can Moon play on click instead?

Yes: pass interaction="click-replay". It then replays once from the start on every click unless reduced motion is preferred.

## Related icons

- [Zap](https://useanimations.com/icons/zap) (hover-replay)
- [Sun](https://useanimations.com/icons/sun) (hover-replay)
- [Sunrise](https://useanimations.com/icons/sunrise) (hover-replay)
- [Droplet](https://useanimations.com/icons/droplet) (hover-replay)
- [Cloud Drizzle](https://useanimations.com/icons/cloud-drizzle) (hover-replay)
- [Cloud Snow](https://useanimations.com/icons/cloud-snow) (hover-replay)
- [Thermometer](https://useanimations.com/icons/thermometer) (hover-replay)
- [Cloud Lightning](https://useanimations.com/icons/cloud-lightning) (hover-replay)
- [Wind](https://useanimations.com/icons/wind) (hover-replay)
- [Cloud Rain](https://useanimations.com/icons/cloud-rain) (hover-replay)
- [Sunset](https://useanimations.com/icons/sunset) (hover-replay)
- [Umbrella](https://useanimations.com/icons/umbrella) (hover-replay)

[All weather icons](https://useanimations.com/categories/weather) · [All icons](https://useanimations.com/icons)
