Plain HTML and Web Components
Copy pageTo show a skeleton loader in plain HTML, wrap the part of the page that loads in <dotquilt-region>, put a loader such as <dotquilt-skeleton-text> inside it with slot="placeholder", and set the region’s state from your data: pending, refreshing or ready.
dotquilt is the native Web Components themselves, with no runtime dependencies. The React, Vue, Svelte and Angular packages are thin wrappers over these same elements, so everything on this page also works in a framework without its own Dotquilt package, wherever custom elements render.
Install and register
Section titled “Install and register”npm install dotquiltRegister each element once, before it appears on the page. Each component has its own entry point, so a page ships only what it uses:
import { registerLoadingRegion } from 'dotquilt/region';import { registerSkeletonText } from 'dotquilt/skeleton';
registerLoadingRegion();registerSkeletonText();| Entry point | Registers |
|---|---|
dotquilt/region |
registerLoadingRegion(): <dotquilt-region> |
dotquilt/skeleton |
registerSkeletonBlock(), registerSkeletonLine(), registerSkeletonCircle(), registerSkeletonText() |
dotquilt/text |
registerTextLoader(): <dotquilt-text-loader> |
dotquilt/chart |
registerChartLoader(): <dotquilt-chart-loader> |
dotquilt/table |
registerTableLoader(): <dotquilt-table-loader> |
dotquilt/typing |
registerTypingDots(): <dotquilt-typing-dots> |
dotquilt/register-all |
registerAll(): every element at once |
Bundlers such as Vite and webpack resolve these imports for you.
A complete example
Section titled “A complete example”A team member’s card that loads from an API. The placeholder holds the card’s shape, a stale answer can’t settle a newer request, and an error replaces the placeholder at once:
<dotquilt-region id="member" state="pending" aria-label="Team member"> <div slot="placeholder" class="member-skeleton"> <dotquilt-skeleton-circle></dotquilt-skeleton-circle> <dotquilt-skeleton-line></dotquilt-skeleton-line> <dotquilt-skeleton-line style="width: 60%"></dotquilt-skeleton-line> </div> <article class="member"> <h3 data-field="name">Team member</h3> <p data-field="role"></p> <p data-field="bio"></p> </article></dotquilt-region>import { type LoadingRegion, registerLoadingRegion } from 'dotquilt/region';import { registerSkeletonCircle, registerSkeletonLine,} from 'dotquilt/skeleton';
registerLoadingRegion();registerSkeletonCircle();registerSkeletonLine();
const region = document.getElementById('member') as LoadingRegion | null;
export async function showMember(id: string): Promise<void> { if (!region) return; // Each request is a new cycle; the placeholder shows until it settles. // Each load starts with the default handoff; an error below swaps at once. region.update({ state: 'pending', cycle: id, timing: undefined }); try { const response = await fetch(`/api/members/${id}`); if (!response.ok) throw new Error(`Request failed: ${response.status}`); const member: Record<string, string> = await response.json(); // A newer request took over while this one was in flight. if (region.cycle !== id) return; for (const field of region.querySelectorAll<HTMLElement>('[data-field]')) field.textContent = member[field.dataset.field ?? ''] ?? ''; region.update({ state: 'ready' }); } catch { if (region.cycle !== id) return; const card = region.querySelector('article'); if (card) card.textContent = "We couldn't load this member. Try again later."; // An error replaces the placeholder at once, without the handoff. region.update({ state: 'ready', timing: { duration: 0 } }); }}
void showMember('ada');- One cycle per request.
update({ state: 'pending', cycle: id })names the load. When the answer arrives, checkregion.cyclefirst: if a newer request took over, drop the old answer. refreshingkeeps content on screen. Use it when you already show data and are fetching a newer copy.- Errors swap at once. Show your message with
state: 'ready'andtiming: { duration: 0 }, and resettimingtoundefinedwhen the next load starts.
Attributes and properties
Section titled “Attributes and properties”Strings and numbers can be written as attributes in your HTML: state, aria-label, a skeleton’s lines, a region’s delay. Objects, such as a table’s columns or a region’s timing, are properties: set them on the element, or several at once with update(). document.querySelector('dotquilt-region') is typed as the element, so TypeScript checks what you pass.
The API reference lists every element’s attributes, properties, events, slots, CSS parts and custom properties.
Server-rendered pages
Section titled “Server-rendered pages”With a JavaScript server (Node, Bun, Deno or an edge function), renderStatic from dotquilt/server writes a loader’s markup into the first HTML, so the placeholder is there before any script runs. See Server rendering.
From any other server, such as a Rails, Django, Laravel or Go template, write the elements into the HTML as above. The placeholder draws once the elements register in the browser, so reserve the region’s space with min-height.
Events
Section titled “Events”Listen with addEventListener. A region, and a TextLoader, dispatch dotquilt-handoff-start, dotquilt-handoff-end (its detail.reason says how the handoff ended) and dotquilt-handoff-cancel. Every element dispatches dotquilt-error when an option is invalid or an animation fails; its detail.code says which. The LoadingRegion page says when each one fires.
Styles and CSP
Section titled “Styles and CSP”By default each element adds its own styles. If your site has a Content Security Policy, give each element a stylePolicy before it connects: a nonce, or an external stylesheet from dotquilt/styles/. See Content Security Policy.
Editor support
Section titled “Editor support”The package describes every element in custom-elements.json (the Custom Elements Manifest) and web-types.json. JetBrains IDEs read web-types.json and complete the tags and attributes in your HTML; tools that read the Custom Elements Manifest find the other.