Structure-aware skeleton loader. One Web Component, every framework.
Structure-aware skeleton loader. One Web Component, every framework.
Structure-aware skeleton loader. One Web Component. Every framework.
Documentation · Live Demo
Stop building skeleton screens by hand. Wrap your real UI in `` and it generates shimmer placeholders automatically by measuring your actual DOM at runtime.
No separate skeleton components to maintain. No copy-pasting layouts. The real component is the skeleton template.
Traditional skeleton loaders require you to build and maintain a second version of every component, just for the loading state. When the real component changes, the skeleton drifts out of sync.
phantom-ui takes a different approach. It renders your real component with invisible text, measures the position and size of every leaf element (getBoundingClientRect), and overlays animated shimmer blocks at the exact same coordinates. Container backgrounds and borders stay visible, giving a natural card outline while loading.
Because it is a standard Web Component (built with Lit), it works in React, Vue, Svelte, Angular, Solid, Qwik, HTMX, or plain HTML. No framework adapters needed.
bun add @aejkatappaja/phantom-ui # bun
npm install @aejkatappaja/phantom-ui # npm
pnpm add @aejkatappaja/phantom-ui # pnpm
yarn add @aejkatappaja/phantom-ui # yarnOr drop in a script tag with no build step:
If you cannot install from a registry, or you would rather keep a copy in your repo, there is a standalone ES module with Lit bundled in. One file, 34 kB minified, 11.5 kB gzipped, no runtime dependency:
import "@aejkatappaja/phantom-ui/standalone";Or, if you cannot reach a registry at all, copy two files into your project and import by path:
phantom-ui.standalone.js # the component, unminified so a review can read it
phantom-ui.standalone.min.js # the same code, minified
phantom-ui.standalone.d.ts # its types, no imports of any kindTake the first and the third. TypeScript pairs a declaration to a module by exact filename, so those two names go together and the types apply with nothing to configure.
import "./phantom-ui.standalone.js";
import type { PhantomUi } from "./phantom-ui.standalone.js";That is the whole install. The element registers itself on import, and the declarations reference nothing external, so a project with no node_modules at all still type-checks under strict with skipLibCheck: false.
The declared class extends HTMLElement rather than LitElement, which is a narrower view of the same object, so updateComplete is declared explicitly and the rest of the public API is unchanged.
Those are the release assets, which is the channel for people who cannot reach a registry at all. Inside the npm package the same builds are phantom-ui.standalone.js and phantom-ui.standalone.dev.js, resolved through the exports map rather than by filename. Either build is the same code, and both are bundled output rather than the original TypeScript: the sources import Lit, so they cannot be compiled on their own.
The library is MIT, so vendoring is fine. Note the version you copied somewhere near the file, since a vendored copy does not get updates.
The component works with zero setup. For an extra convenience pass, run the bundled init command once from your project root:
npx @aejkatappaja/phantom-ui init # npm
bunx @aejkatappaja/phantom-ui init # bun
pnpx @aejkatappaja/phantom-ui init # pnpm
yarn dlx @aejkatappaja/phantom-ui init # yarnIt detects your project setup and handles two things:
JSX type declarations: For React, Solid, and Qwik, it generates a phantom-ui.d.ts in your src/ directory so `` is recognized in JSX. Vue, Svelte, and Angular work out of the box without any type declaration.
SSR pre-hydration CSS: For Next.js, Nuxt, SvelteKit, Remix, and Qwik, it adds import "@aejkatappaja/phantom-ui/ssr.css" to your layout file to prevent content flash before hydration (see Pre-hydration CSS).
Nothing runs on install: the library deliberately has no postinstall hook, so your source is never modified unless you ask for it. Prefer not to run the command at all? Both steps are tiny and documented below for manual setup.
Manual JSX type declarations
React / Next.js / Remix
import type { PhantomUiAttributes } from "@aejkatappaja/phantom-ui";
declare module "react/jsx-runtime" {
export namespace JSX {
interface IntrinsicElements {
"phantom-ui": PhantomUiAttributes;
}
}
}Solid
import type { SolidPhantomUiAttributes } from "@aejkatappaja/phantom-ui";
declare module "solid-js" {
namespace JSX {
interface IntrinsicElements {
"phantom-ui": SolidPhantomUiAttributes;
}
}
}Qwik
import type { PhantomUiAttributes } from "@aejkatappaja/phantom-ui";
declare module "@builder.io/qwik" {
namespace QwikJSX {
interface IntrinsicElements {
"phantom-ui": PhantomUiAttributes & Record;
}
}
}Manual SSR CSS import
Add this import to your root layout file:
import "@aejkatappaja/phantom-ui/ssr.css";| Framework | Layout file |
|---|---|
| Next.js (App Router) | app/layout.tsx |
| Next.js (Pages) | pages/_app.tsx |
| Nuxt | app.vue |
| SvelteKit | src/routes/+layout.svelte |
| Remix | app/root.tsx |
| Qwik | src/root.tsx |
Set loading to show the shimmer. Remove it to reveal the real content. All child elements (including deeply nested images and media) are automatically hidden during loading.
phantom-ui works with any data fetching approach. The pattern: render placeholder content while loading, real content when done. The placeholder text is invisible (CSS transparent) and only used to generate the skeleton shape.
import { useQuery } from "@tanstack/react-query";
import "@aejkatappaja/phantom-ui";
function UserProfile({ userId }: { userId: string }) {
const { data: user, isLoading } = useQuery({
queryKey: ["user", userId],
queryFn: () => fetch(`/api/users/${userId}`).then((r) => r.json()),
});
return (
);
}While isLoading is true, the placeholder text ("Placeholder Name", "A short bio goes here.") is rendered invisibly and phantom-ui generates shimmer blocks matching their exact position and size. When the query resolves, loading is removed and the real content appears.
import useSWR from "swr";
import "@aejkatappaja/phantom-ui";
function UserProfile({ userId }: { userId: string }) {
const { data: user, isLoading } = useSWR(`/api/users/${userId}`);
return (
);
}For dynamic lists where the data hasn't loaded yet, use count to repeat a single template row:
const { data: users, isLoading } = useQuery({
queryKey: ["users"],
queryFn: () => fetch("/api/users").then((r) => r.json()),
});
return (
{isLoading ? (
) : (
users?.map((u) => (
))
)}
);Safe to import multiple times. The custom element registration is guarded against duplicate customElements.define() calls, so phantom-ui works reliably in micro-frontends, lazy-loaded modules, dynamic imports, and HMR / hot reload environments where the package can end up being initialized more than once.
import "@aejkatappaja/phantom-ui";
function ProfileCard({ user, isLoading }: Props) {
return (
);
}
// List with repeat mode
function UserList({ users, isLoading }: Props) {
return (
);
}
import { Component, signal, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import "@aejkatappaja/phantom-ui";
@Component({
selector: "app-profile",
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
`,
})
export class ProfileComponent {
loading = signal(true);
}import { createSignal } from "solid-js";
import "@aejkatappaja/phantom-ui";
function ProfileCard() {
const [loading, setLoading] = createSignal(true);
return (
);
}The component needs browser APIs to measure the DOM. Import it client-side only:
// Next.js
"use client";
import { useEffect } from "react";
export default function Page() {
useEffect(() => { import("@aejkatappaja/phantom-ui"); }, []);
return ...;
}
...
// Qwik
import { component$, useVisibleTask$ } from "@builder.io/qwik";
export default component$(() => {
// eslint-disable-next-line qwik/no-use-visible-task
useVisibleTask$(async () => {
import("@aejkatappaja/phantom-ui");
});
return ...;
});The `` tag can exist in server-rendered HTML. The browser treats it as an unknown element until hydration, then the Web Component activates and measures the DOM. Content renders normally on the server, which is good for SEO.
Before JavaScript loads, content inside `` can briefly flash as visible text. The package ships a small CSS file that hides this content immediately, with no JS needed:
import "@aejkatappaja/phantom-ui/ssr.css";Running npx @aejkatappaja/phantom-ui init detects SSR frameworks and adds this import to your layout file (e.g. app/layout.tsx for Next.js, app.vue for Nuxt, +layout.svelte for SvelteKit). Or add the line yourself. If you use the CDN build, add the rules directly in your ``:
| Attribute | Type | Default | Description |
|---|---|---|---|
loading |
boolean |
false |
Show shimmer overlay or real content |
animation |
string |
shimmer |
Animation mode: shimmer, pulse, breathe, or solid |
mode |
string |
skeleton |
skeleton (hide content, show blocks) or overlay (keep content dimmed, sweep light over it for refresh) |
shimmer-direction |
string |
ltr |
Direction of the shimmer sweep: ltr, rtl, ttb, or btt (shimmer mode only) |
shimmer-color |
string |
rgba(128,128,128,0.3) |
Color of the animated gradient sweep (shimmer mode only) |
background-color |
string |
rgba(128,128,128,0.2) |
Background of each shimmer block (all modes) |
duration |
number |
1.5 |
Animation cycle in seconds |
stagger |
number |
0 |
Delay in seconds between each block's animation start |
reveal |
number |
0 |
Fade-out duration in seconds when loading ends |
count |
number |
1 |
Number of skeleton rows to repeat from a single template |
count-gap |
number |
0 |
Gap in pixels between repeated rows |
fallback-radius |
number |
4 |
Border radius (px) for flat elements like text |
debug |
boolean |
false |
Outline each measured block with an index for inspection |
loading-label |
string |
Loading |
Accessible label announced by screen readers while loading (set as aria-label) |
pierce-shadow |
boolean |
false |
Measure inside open shadow roots of slotted components (Stencil, Lit design systems) |
Using a Web Component design system? See the Shadow DOM guide for how
pierce-shadowmeasures inside your components.
mode="overlay")The default skeleton mode is for the first load: it hides the content and shows placeholder blocks. For a refresh / stale-while-revalidate state, where you already have a result and are refetching, use mode="overlay":
The existing content stays visible and dimmed while a light glint sweeps over each element (structure-aware, just like the skeleton). It is not clickable during the refresh
No open issues yet, or sync has not completed.