Lordicon
  • Icons
  • Docs
  • Resources
  • Pricing
Log in Sign up Log in
Web
  • Foundations
  • Icon styles
  • Animation
  • Formats
  • Best practices
  • Integrations
  • Web
  • React
  • React Native
  • Plugins
  • WordPress
  • Figma
  • Google Docs & Slides
  • Support
  • Licenses
  • Account and Billing
  • Library
  • Troubleshooting

Web

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.

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 package

Install the package in your project.

npm install @lordicon/element
Set it up

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();
Use & Customize

Drop it into your HTML and adjust as you like!

Heart, Animated Icon, Outline

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.

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, like in-reveal
  • hover-… for a short effect that plays once, like hover-jump
  • loop-… for an animation that repeats nicely
  • morph-… 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

hover

once, when the pointer enters the icon (or it gets keyboard focus)

click

once per click

loop

over and over

loop-on-hover

over and over, while the pointer is on the icon

in

once, when the icon scrolls into view

morph

to a second look on hover, and back when the pointer leaves

boomerang

there and straight back, on hover

follow

in step with an attribute, for example a pressed button (see below)

sequence

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 list
  • follow(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 badge
  • follow(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:

  • stroke sets the line width: light, regular or bold.
  • speed speeds it up or slows it down: 2 is twice as fast, 0.5 half 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

lazy

when it scrolls into view

interaction

on the first hover, click or focus

delay:1000

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 defineElement() goes

What else

Angular

src/main.ts, before the app starts

Add CUSTOM_ELEMENTS_SCHEMA to the components that use the icon

Vue, Nuxt

a client plugin, app/plugins/lordicon.client.ts

Tell Vue it's not a component: isCustomElement: (tag) => tag === 'lord-icon'

Svelte, SvelteKit

src/hooks.client.ts

Nothing; write the closing tag, <lord-icon></lord-icon>

Astro

a <script> in your layout

Nothing; no client: directive needed

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

Getting started

One script and one tag

Triggers

Every built-in trigger side by side

Target

An icon that plays when you hover the row around it

Follow

Toggle buttons, a selected item, a counter and the stages of a task

Sequence

Scripts of steps: states in a row, pauses, still frames

Looks

Colors

The colors attribute, CSS variables and current-color

Stroke and speed

Line width and playback speed

Background

An icon behind other content

States and intro

States

The different animations inside one icon

Intro

An entrance before the trigger takes over

Intro after an animation

An icon that waits for its card to slide in

Intro out of view

An entrance that waits until you scroll to the icon

Loading

Loading after a delay

Icons that load a moment after the page, with an image in their place

Loading on interaction

Icons that load on the first hover, click or focus

Lazy loading

Icons that load when they scroll into view

States in CSS

Styling the icon while it loads, plays or fails, with :state()

JavaScript

Methods and events

Play, pause and listen to the icon

Chaining states

One state after another, with the promise of play()

Icon data

An icon from data you already have, without src

An icon from a file

A preview of a JSON file picked by the user

Moving an icon

Moving an icon between cards without loading it again

Reduced motion

What each trigger does when the visitor asks for less motion

Your own triggers

A custom trigger

A trigger that plays the other way on every click

A custom trigger with states

A trash can that fills or empties on click, with its own states

A custom trigger on scroll

An icon that plays along with the page scroll

Player (@lordicon/web)

Hover

Playing an icon on pointer enter

States

Every state of an icon, and the whole file

Colors and stroke

Changing colors by name, by value, and back

Playback

Pause, stop, progress, loop, speed and direction

Morph

Going to a second look and back

Sequence

States in a row, with the promise of play()

Events

Every event and what it tells you

Many icons

Players only for the icons on screen

Apps

Complete apps on GitHub, each with a README that walks through the setup.

Angular

Icons in templates, icons that follow signals, loading with @defer

Nuxt

Icons that follow Vue state, server rendering without a jump

SvelteKit

Icons that follow Svelte state, server rendering and streamed data

Astro

Icons without a framework, scripts, server islands

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.

  • Intro
  • Quick start
  • States
  • Triggers
  • Colors and stroke
  • Loading
  • JavaScript
  • Frameworks
  • Player
  • Examples
  • Best practices
Best practices React