Spotlight.js

Installation

Run one of the following commands to install the package:

# Using npm
npm install spotlight.js

# Using pnpm
pnpm install spotlight.js

# Using yarn
yarn add spotlight.js

Alternatively, you can use CDN and include the script in your HTML file:

<script src="https://cdn.jsdelivr.net/npm/spotlight.js@latest/dist/spotlight.js.iife.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/spotlight.js@latest/dist/spotlight.css" />

<!-- Only if you use hints -->
<script src="https://cdn.jsdelivr.net/npm/spotlight.js@latest/dist/hints.iife.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/spotlight.js@latest/dist/hints.css" />

<!-- Only if you use checklists -->
<script src="https://cdn.jsdelivr.net/npm/spotlight.js@latest/dist/checklist.iife.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/spotlight.js@latest/dist/checklist.css" />

Start Using

Once installed, you can import the package in your project. The following example shows how to highlight an element:

import { spotlight } from "spotlight.js";
import "spotlight.js/dist/spotlight.css";

const tour = spotlight();
tour.highlight({
  element: "#some-element",
  popover: {
    title: "Title",
    description: "Description",
  },
});

Hints ship as their own entry with a self-contained stylesheet, so import them only when you use them:

import { hints } from "spotlight.js/hints";
import "spotlight.js/dist/hints.css";

Checklists work the same way. Their items run tours, so keep spotlight.css alongside:

import { checklist } from "spotlight.js/checklist";
import "spotlight.js/dist/checklist.css";

Note on CDN

If you are using the CDN, you can use the package from the window object:

const spotlight = window["spotlight.js"].spotlight;

const tour = spotlight();

tour.highlight({
  element: "#some-element",
  popover: {
    title: "Title",
    description: "Description",
  },
});

The hints build exposes its own global:

const hints = window.spotlightHints.hints;

And so does the checklist build. Load it after the main script, which it uses to run tours:

const checklist = window.spotlightChecklist.checklist;

Continue reading the Getting Started guide to learn more about Spotlight.js.