Lordicon Web Player makes it easy to add and control animated icons on your website. It uses the <lord-icon> custom HTML element, allowing you to display and interact with icons in Lottie JSON format just like any other HTML element.
Web
The player works with plain HTML and popular frameworks like Angular, Vue, Svelte, and Astro, as well as platforms like WordPress.
To get started, you need the Web Player script and your icon's Lottie JSON file.
Looking for inspiration? Explore our UI Components showcase to see animated icons in action. Discover free, open-source examples of interactive buttons, menus, forms, and more, ready to copy, customize, and use in your projects.
Install the package in your project.
Import and register the icon to make it available in your code.
import { defineElement } from "@lordicon/element";
// define "lord-icon" custom element with default properties
defineElement();
Drop it into your HTML and adjust as you like!
Quick start
Add the script once, anywhere on the page:
<script
type="module"
src="https://cdn.jsdelivr.net/npm/@lordicon/element@3"
></script>
Then put the icon where you want it:
<lord-icon src="/icons/lock.json" trigger="hover"></lord-icon>
Move the pointer over it and it plays. That's all you need to get started.
src points to the icon's JSON. Download it from the icon's page on Lordicon and put it next to your other assets. The icon is 32 × 32 px by default; set width and height in CSS to change it:
lord-icon {
width: 48px;
height: 48px;
}
Quick start
See it running in your browser.
This content requires cookies. You must accept cookies to view it.
With npm
If your project uses a bundler (Vite, webpack and so on), install the package instead of loading the script:
npm install @lordicon/element
import { defineElement } from "@lordicon/element";
defineElement();
Call defineElement() once, at the start of your app. After that <lord-icon> works everywhere on the page. If you use a framework, see Frameworks for where this line goes.
States
Most icons hold more than one animation. We call them states, and their names tell you what they are for:
in-…for an entrance, likein-revealhover-…for a short effect that plays once, likehover-jumploop-…for an animation that repeats nicelymorph-…for a change into another look and back
You can see an icon's states on its page on Lordicon. Pick one with state:
<lord-icon src="/icons/coins.json" trigger="loop" state="loop-spin"></lord-icon>
Without state the icon plays its default one. Triggers that morph (morph, boomerang, follow) work best with a morph-… state.
By default Lordicon downloads the icon with only the animation you picked, to keep the file small. If you want to use several states of one icon (for an intro, a sequence or follow), or change its stroke on the page, choose the "Raw" format when you download it. Colors work either way.
Triggers
The trigger attribute decides when the icon plays:
Trigger |
Plays |
|---|---|
|
|
once, when the pointer enters the icon (or it gets keyboard focus) |
|
|
once per click |
|
|
over and over |
|
|
over and over, while the pointer is on the icon |
|
|
once, when the icon scrolls into view |
|
|
to a second look on hover, and back when the pointer leaves |
|
|
there and straight back, on hover |
|
|
in step with an attribute, for example a pressed button (see below) |
|
|
a short script of steps you write (see below) |
Without a trigger the icon stays still, until you play it from JavaScript.
Some triggers take an option in parentheses. For example, a loop with a one-second pause between rounds:
<lord-icon src="/icons/lock.json" trigger="loop(1000)"></lord-icon>
Play on the whole card
Usually you want the icon to react when someone hovers the button or card it sits in, not just the icon itself. Point target at that parent:
<a class="card" href="/pricing">
<lord-icon
src="/icons/coins.json"
trigger="hover"
target=".card"
></lord-icon>
Pricing
</a>
Follow a button or a state
follow keeps the icon in step with an attribute on its target. You change the attribute, as you would anyway, and the icon animates by itself.
The most common case is a toggle button. By default follow watches aria-pressed, so a morph-… state goes to its second look when the button is pressed, and back when it isn't:
<button id="lock" aria-pressed="false">
<lord-icon
src="/icons/lock.json"
trigger="follow"
target="button"
state="morph-unlocked"
></lord-icon>
</button>
<script>
const lock = document.querySelector("#lock");
lock.addEventListener("click", () => {
lock.setAttribute(
"aria-pressed",
lock.getAttribute("aria-pressed") !== "true",
);
});
</script>
You can follow any other attribute too. Name it in parentheses:
follow(aria-selected)for the selected item in a menu or a listfollow(data-count)for a number: the icon enters when it goes above zero, and gives a little nudge each time it grows, like a cart badgefollow(data-stage, busy=loop-cycle, done=morph-check)for the stages of a task: a loop while it's busy, a check mark when it's done
Play an entrance first
intro plays an entrance the first time the icon comes into view. After that the trigger takes over as usual:
<lord-icon src="/icons/lock.json" trigger="hover" intro></lord-icon>
Without a value it plays the icon's first in-… state. You can also name a state, intro="hover-jump", wait a moment first, intro="delay=800", or wait until a parent stops moving, intro="in-reveal, after=.card", which helps when the icon sits in a card that slides in.
Write a sequence
sequence plays a script of steps, separated by commas:
<lord-icon
src="/icons/coins.json"
trigger="sequence(play in-reveal, wait 500, play hover-jump, wait 1000)"
></lord-icon>
There are four steps: play a state, show one frame of it, wait some milliseconds, and stop. The script repeats until it reaches stop. The README covers playing part of a state, the two halves of a morph and the rest.
Colors and stroke
Colors have names, such as primary and secondary. Change them with colors:
<lord-icon
src="/icons/lock.json"
trigger="hover"
colors="primary:#e5484d,secondary:#3e63dd"
></lord-icon>
Or from CSS, which is handy for dark mode and hover effects:
.dark lord-icon {
--lord-icon-primary: #ffffff;
--lord-icon-secondary: #30c9e8;
}
To make the whole icon one color, the same as the text around it, add current-color:
<a href="/account">
<lord-icon src="/icons/lock.json" trigger="hover" current-color></lord-icon>
Account
</a>
Two more attributes change how the icon looks and moves:
strokesets the line width:light,regularorbold.speedspeeds it up or slows it down:2is twice as fast,0.5half as fast.
Loading
Each icon is a separate file. With a few icons on a page you don't have to think about it. With many, load them only when they are needed:
<lord-icon src="/icons/lock.json" trigger="hover" loading="lazy"></lord-icon>
Value |
Loads the icon |
|---|---|
|
|
when it scrolls into view |
|
|
on the first hover, click or focus |
|
|
a moment after the page, here one second |
Anything you put inside <lord-icon> shows until the icon is ready. A static SVG of the same icon (you can download it from Lordicon too) makes the switch almost invisible:
<lord-icon src="/icons/lock.json" trigger="hover" loading="interaction">
<img src="/icons/lock.svg" alt="" />
</lord-icon>
Keep the page still
Until the script runs, the browser doesn't know what <lord-icon> is, so it has no size and a placeholder shows at its own size. If the page jumps while it loads (common with server rendering), give the element its size in your CSS:
lord-icon {
display: inline-block;
width: 48px;
height: 48px;
}
lord-icon:not(:defined) > * {
width: 100%;
height: 100%;
}
CSS can also tell when the icon is ready. For an icon without a placeholder, you can fade it in:
lord-icon {
opacity: 0;
transition: opacity 0.3s;
}
lord-icon:state(ready) {
opacity: 1;
}
JavaScript
You can also play the icon from your code. The snippets below use coins.json, which has an in-reveal and a hover-jump state:
const icon = document.querySelector("lord-icon");
icon.play(); // plays the icon's state
icon.play({ state: "hover-jump" }); // plays another one
icon.pause(); // stops where it is
icon.stop(); // goes back to the first frame
You don't have to wait for the icon to load first; the calls wait for it. play() returns a promise, so you can play one state after another:
await icon.play({ state: "in-reveal" });
icon.play({ state: "hover-jump" });
Events tell you what the icon is doing:
icon.addEventListener("ready", () => console.log(icon.states));
icon.addEventListener("complete", () => console.log("finished"));
icon.addEventListener("error", () => console.log("could not load the icon"));
The full list of attributes, methods and events is in the package README.
Your own trigger
When none of the built-in triggers fits, write one. A trigger is a small class that listens for something and plays the icon. This needs the npm package (see Quick start); the script tag doesn't export anything.
import { BaseTrigger, defineElement } from "@lordicon/element";
class DoubleClick extends BaseTrigger {
constructor(context) {
super(context);
this.listen(this.target, "dblclick", () =>
this.player.play({ from: "start" }),
);
}
}
defineElement({ triggers: { "double-click": DoubleClick } });
<lord-icon src="/icons/lock.json" trigger="double-click"></lord-icon>
Listeners added with this.listen() are removed for you when the icon goes away. The README lists everything a trigger can react to, and the examples below include a trigger driven by page scroll.
Frameworks
<lord-icon> is a standard custom element, so it works in any framework. Install the package, call defineElement() once in the browser, and use the tag in your templates. Each framework has one small thing to know:
Framework |
Where |
What else |
|---|---|---|
|
|
Add |
|
|
a client plugin, |
Tell Vue it's not a component: |
|
|
|
Nothing; write the closing tag, |
|
|
a |
Nothing; no |
Each framework name links to a complete demo app with its own README: triggers and colors, icons that follow the framework's state, and loading with server rendering.
Using React? We have a package for it, @lordicon/react. See the React guide and the Next.js demo.
On WordPress you don't need any code: our plugin adds icons in the block editor.
Player
<lord-icon> is built on @lordicon/web, a player you can use on its own. It draws the icon in any element on your page and plays it when you tell it to. No attributes, no triggers: everything happens in your code.
Reach for it when you build your own icon component, or need full control over the animation. For everything else, <lord-icon> is simpler, and you can always reach the player behind it through icon.player.
npm install @lordicon/web
import { Player } from "@lordicon/web";
const container = document.querySelector("#icon");
const data = await (await fetch("/icons/lock.json")).json();
const player = new Player(container, data);
container.addEventListener("pointerenter", () => player.play());
container can be any element; the player draws the icon inside it. States, colors and stroke work as on the element:
player.play({ state: "in-reveal" });
player.colors.primary = "#08a88a";
player.stroke = "bold";
Playback is yours to control: pause(), stop(), seek(), loop, speed and direction. play() returns a promise that tells you whether the animation played to its end:
if (await player.play({ state: "in-reveal" })) {
player.play({ state: "hover-jump" });
}
With many icons on a page, create a player when its icon comes into view and call player.destroy() when it leaves. The player keeps the animation in memory until then.
Everything else, including events and morph states, is in the player README.
Examples
Every example runs in your browser on StackBlitz, so you can change the code and see what happens.
Basics
One script and one tag
Every built-in trigger side by side
An icon that plays when you hover the row around it
Toggle buttons, a selected item, a counter and the stages of a task
Scripts of steps: states in a row, pauses, still frames
Looks
The colors attribute, CSS variables and current-color
Line width and playback speed
An icon behind other content
States and intro
The different animations inside one icon
An entrance before the trigger takes over
An icon that waits for its card to slide in
An entrance that waits until you scroll to the icon
Loading
Icons that load a moment after the page, with an image in their place
Icons that load on the first hover, click or focus
Icons that load when they scroll into view
Styling the icon while it loads, plays or fails, with :state()
JavaScript
Play, pause and listen to the icon
One state after another, with the promise of play()
An icon from data you already have, without src
A preview of a JSON file picked by the user
Moving an icon between cards without loading it again
What each trigger does when the visitor asks for less motion
Your own triggers
A trigger that plays the other way on every click
A trash can that fills or empties on click, with its own states
An icon that plays along with the page scroll
Player (@lordicon/web)
Playing an icon on pointer enter
Every state of an icon, and the whole file
Changing colors by name, by value, and back
Pause, stop, progress, loop, speed and direction
Going to a second look and back
States in a row, with the promise of play()
Every event and what it tells you
Players only for the icons on screen
Apps
Complete apps on GitHub, each with a README that walks through the setup.
Best practices
One animation or all of them
When you download an icon, the default format keeps only the animation you picked. The file is small and that's usually all you need. Choose "Raw" only when you want to switch between the icon's states, or change its stroke, on the page.
Reduced motion
When a visitor has asked their system for less motion, icons respect it: they show their final frame instead of playing, and loops stand still. To animate a particular icon anyway, add motion="always" to it.
Screen readers
Screen readers skip icons. If an icon means something on its own, without text next to it, give it an aria-label.