motion-components 1.1: Animate Any SVG Icon With One HTML Tag
Version 1.1 of motion-components adds a new category: Icons. It has two elements.
You can try them now on the home page. Click any icon in the icon grid to see a preview and copy its code.
One line per icon
This is a complete page. Save it as
Hover the heart and its outline draws in, line by line. Hover the bell and it wiggles.
Four ways to add an icon
| Way | Use it when | Example |
|---|---|---|
| You want one line of HTML and no files to manage. | ||
| You keep your icons as files in your site, or you drew your own. | ||
| Inline SVG | You copied the SVG from an icon website. | |
| You use a bundler and want the icon inside your bundle. |
The
Icons from your own folder
This works for icons from any set and for icons you drew yourself. A stroke icon can use
A path without a leading slash, such as
Inline SVG
Inline SVG works well when you want the icon in your HTML with no extra request:
From an npm package
With a bundler such as Vite, import the icon as a string.
Vite can also import any SVG file as a string with the
Works with the icon library you already use
Every library in this table publishes its icons as SVG files on the jsDelivr CDN. Find an icon on the library’s website and put its name at the end of the URL.
| Library | URL after | |
|---|---|---|
| Lucide | Yes | |
| Tabler | Yes | |
| Heroicons | Yes | |
| Iconoir | Yes | |
| Feather | Yes | |
| Phosphor | Pops instead | |
| Bootstrap Icons | Pops instead | |
| Material Symbols | Pops instead | |
| Font Awesome Free | Pops instead | |
| Simple Icons | Pops instead |
The
Some icon sets do not set a color in their SVG files. Material Symbols and Simple Icons are two examples. A plain
Six animations, five triggers
| Animation | What it does |
|---|---|
| Draws the lines in, one after another. This is the default. | |
| Scales up from small on a spring. | |
| Drops in from above and bounces. | |
| Turns half a circle and settles. | |
| Shakes from side to side, like a ringing bell. | |
| Grows and shrinks once, like a heartbeat. |
| Trigger | When the animation runs |
|---|---|
| When the pointer enters the icon. This is the default. | |
| When the icon is clicked. | |
| When the icon scrolls into view. | |
| When the page loads. | |
| Again and again, with a pause set by |
Icons inside buttons
Most icons on a website sit inside a button or a link. So when
The “Read the docs” and “Star on GitHub” buttons at the bottom of the home page work this way.
Color, fill and background
Three CSS custom properties control how an icon looks:
| Property | What it changes | Default |
|---|---|---|
| The color of the lines | The text color | |
| The color inside an outline icon | No fill | |
| The width and height |
Icons with two states
| Without | With | |
|---|---|---|
| menu | close | |
| play | pause | |
| copy | check | |
| plus | minus | |
| chevron down | chevron up | |
| empty heart | filled heart | |
| spinner | check | |
| eye | eye with a line through it |
There are two ways to switch the state. In the first way, the icon is the button. Add
In the second way, your own button controls the icon. This menu button changes to a close icon when it opens:
The state changes on a spring. If you click again in the middle of a change, the icon turns around from where it is. It does not jump to the end first.
State Icons: Menu to Close, Play to Pause, on a Spring explains this element in detail. It has complete recipes for a copy button, a save button with a spinner, a show password button and an accordion.
React and Vue
Both elements work in every framework. React 19 passes properties to custom elements directly, so
You can also wrap the icon component from your icon library. Any component that renders an
In Vue, tell the compiler that
Safe by default
An SVG file can contain more than drawing instructions. It can contain scripts, links and references to other files. Before
Accessibility
| Element | Default | How to give it a name |
|---|---|---|
| Decorative and hidden from screen readers | Add | |
| A button with | Add | |
| Decorative | Give the surrounding button a name. |
When a user turns on reduced motion in their system settings, both elements skip the animation. They show the final state at once, and the loading spinner stands still.
Get started
Read the motion-icon docs and the motion-icon-state docs. Every code example on those pages works when you paste it into a page.