# Options > Options for the whole app, and functions. ## Setting them ```ts [nuxt.config.ts] export default defineNuxtConfig({ modules: ['boneprint/nuxt'], boneprint: { reveal: 'sequence', }, }) ``` ```ts [main.ts (Vue)] import { boneprint } from 'boneprint' app.use(boneprint, { reveal: 'sequence' }) ```
Option Default Purpose
persist true remember shapes between visits
debug false outline every skeleton and report whether the page moved, see Debugging
reveal fade how content replaces the skeleton: fade , sequence or sweep
`persist` and `reveal` can also be set on one skeleton as props. ## forgetSkeletons() Clears the remembered shapes. Whatever is on screen won't be written back, even as it unmounts. Call it on sign-out. ```ts forgetSkeletons() ``` Auto-imported in Nuxt. In Vue, `import { forgetSkeletons } from 'boneprint'`, or add it to auto-imports as shown in [Vue + Vite](https://kukson777.github.io/boneprint/docs/getting-started/vue#auto-import). ## useInSkeleton() `true` inside the copy of the slot a skeleton is measured from, `false` everywhere else. Use it to keep a component in the slot from fetching or observing twice, see [Side effects in the slot](https://kukson777.github.io/boneprint/docs/guide/markup#side-effects-in-the-slot). ```ts const inSkeleton = useInSkeleton() ``` Auto-imported in Nuxt. In Vue, `import { useInSkeleton } from 'boneprint'`. ## Entry points
Import For
boneprint/nuxt the Nuxt module
boneprint Vue: the components, forgetSkeletons , useInSkeleton and the boneprint plugin
boneprint/resolver boneprintResolver() for unplugin-vue-components
# Skeleton > Props, slots and events of the component. ## Props
Prop Purpose
of the result of useFetch , useAsyncData or useQuery : anything with data , status and error
data , loading , empty , error set by hand, instead of or on top of of
sample sample data that draws the shape
id key for the remembered shape; defaults to the page plus the order skeletons appear on it
label read to screen readers while loading
persist whether to remember the shape between visits; defaults to the module option
reveal fade , sequence or sweep ; defaults to the module option
## Slots
Slot Props Shown for
default { data } content and the skeleton
skeleton none instead of the measured skeleton
empty none an empty response
error { error } an error
## Events `reveal` fires when content has replaced the skeleton. ## SkeletonBox One placeholder box in the same style as the measured bones.
Prop Default
width 60%
height 1em
radius --skeleton-radius
## SkeletonSuspense A Suspense boundary with a measured fallback. Takes the suspending component in the default slot, sample markup in `#skeleton`, and a `label`. It fires `reveal` when the component has resolved. # Theming > CSS variables for color, shape and animation. ## Variables
Variable Purpose
--skeleton-color bone color
--skeleton-line-color color of remembered borders and dividers; by default each keeps its own border color
--skeleton-radius bar corner radius
--skeleton-highlight shimmer color
--skeleton-shimmer none turns the shimmer off
--skeleton-pulse skeleton-pulse turns pulsing on
--skeleton-hold how long to wait before showing a skeleton, 150ms by default
--skeleton-text-top where a text bar starts: cap-height by default, ascender or x-height
--skeleton-text-bottom where a text bar ends: descender by default, or baseline
## Dark mode Variables are plain CSS, so dark mode works like everything else: ```css :root { --skeleton-color: rgb(0 0 0 / 0.08); } .dark { --skeleton-color: rgb(255 255 255 / 0.09); } ``` With `prefers-reduced-motion`, animation turns itself off. # AI agents > Point your coding agent at these docs. The module is easy to use from an AI coding agent: the props, slots and functions carry JSDoc, the slot's `data` is typed from your request, and this site serves its content in machine-readable form. ## llms.txt
URL
/llms.txt An index of every page with a short description.
/llms-full.txt The whole documentation in one Markdown file.
/raw/docs/.md Any page as Markdown, e.g. /raw/docs/guide/states.md .
## A prompt that works ```md Add boneprint to this app (docs: https://kukson777.github.io/boneprint/llms-full.txt). Wrap the list in in with a sample of typical text length, add #empty and #error slots, and skip requests inside the slot where useInSkeleton() is true. ``` ## The cheat sheet - **Install:** `npm install boneprint`. Nuxt: `modules: ['boneprint/nuxt']`, everything auto-imported. Vue: `import { Skeleton } from 'boneprint'`, or `app.use(boneprint, options)`. - **Wrap:** `` with `#default="{ data }"`, `#empty` and `#error="{ error }"`. `request` is a `useFetch`, `useAsyncData` or TanStack Query result. - **By hand:** `:data`, `:loading`, `:empty`, `:error` instead of or on top of `:of`. - **Sample:** mirrors the response, with text of typical length. It only draws the first visit, after that the remembered shape is used. - **Memory:** kept per `id`. Set one on a skeleton inside tabs or anything else that remounts; `forgetSkeletons()` on sign-out. - **Slot runs twice:** once measured, once as content. Fetch outside ``, or skip it where `useInSkeleton()` is `true`. - **Steer:** `data-skeleton-block` (one block), `data-skeleton-skip` (left out), `#skeleton` slot with `` for charts and canvases. - **Style:** `--skeleton-*` CSS variables, see [Theming](https://kukson777.github.io/boneprint/docs/customization/theming). # Introduction > What Boneprint does and how it differs from ordinary skeletons. An ordinary skeleton has to be built twice: you repeat the card in gray rectangles and keep both versions in sync. Change the card, and the loading state no longer matches it. Boneprint uses the markup you already have. It lays that markup out invisibly with sample data, measures where each line of text and each image lands, and draws bones on top. What that gives you: - a bar for every line of text and a block for every image, button and chip; - a skeleton that shows up before JavaScript loads when rendering on the server; - a remembered shape on reload, so blocks are the right size from the first paint; - ``, or a TanStack Query result, handles loading, empty responses and errors for you. It works in Nuxt 3 and 4 as a module and in Vue 3 with Vite as a plugin: see [Nuxt module](https://kukson777.github.io/boneprint/docs/getting-started/nuxt) or [Vue + Vite](https://kukson777.github.io/boneprint/docs/getting-started/vue) to install it. See it live on the [home page](https://kukson777.github.io/boneprint/). The approach is inspired by [skullet](https://github.com/lochie/skullet). # Nuxt module > Add Boneprint to a Nuxt 3 or Nuxt 4 app. ## Install ```bash [npm] npm install boneprint ``` ```bash [pnpm] pnpm add boneprint ``` ```bash [yarn] yarn add boneprint ``` ```bash [bun] bun add boneprint ``` Then add the module: ```ts [nuxt.config.ts] export default defineNuxtConfig({ modules: ['boneprint/nuxt'], }) ``` That's all. ``, ``, ``, `forgetSkeletons()` and `useInSkeleton()` are auto-imported, and the styles are added for you. Works with Nuxt 3 and Nuxt 4. ## Options ```ts [nuxt.config.ts] export default defineNuxtConfig({ modules: ['boneprint/nuxt'], boneprint: { reveal: 'sequence', }, }) ``` Every option is listed on the [Options](https://kukson777.github.io/boneprint/docs/api/options) page. ## What you get with server rendering The server sends the skeleton in the HTML, and a small inline script draws a remembered shape before the app loads. So even before JavaScript runs, blocks are the size the content will be. Next: [Quick Start](https://kukson777.github.io/boneprint/docs/getting-started/quick-start). # Quick Start > Your first skeleton in a minute. The examples use Nuxt's `useFetch`. In Vue, pass a TanStack Query result to `:of` instead, as shown in [Vue + Vite](https://kukson777.github.io/boneprint/docs/getting-started/vue#loading-the-data). ### Load the data on the client A skeleton is only needed while the data isn't there yet, so the request shouldn't hold up the server: ```ts const posts = useFetch('/api/posts', { lazy: true, server: false }) ``` ### Describe a sample The sample mirrors the shape of the response, with text of about the real length. It draws the shape on the first visit: ```ts const sample: Post[] = [{ id: 1, title: 'A title of about this length' }] ``` ### Wrap your markup ```vue ``` `data` in the slot is typed from `useFetch`, so a typo in a field is a compile error. ## The result A real request to [DummyJSON](https://dummyjson.com), delayed by 1.2 seconds: # Vue + Vite > Add Boneprint to a Vue 3 app built with Vite. ## Install ```bash [npm] npm install boneprint ``` ```bash [pnpm] pnpm add boneprint ``` ```bash [yarn] yarn add boneprint ``` ```bash [bun] bun add boneprint ``` The package ships `.vue` files, so the app needs `@vitejs/plugin-vue`, which every Vue + Vite app already has. The styles come with the components: there's no CSS file to import. Pick one of three ways to make the components available. ## Import where you use it The simplest way, nothing to set up: ```vue ``` ## Register globally ```ts [main.ts] import { createApp } from 'vue' import { boneprint } from 'boneprint' import App from './App.vue' createApp(App).use(boneprint).mount('#app') ``` ``, `` and `` then work in every template. The plugin also takes the [options](https://kukson777.github.io/boneprint/docs/api/options): `.use(boneprint, { reveal: 'sequence' })`. It's the only way to change the defaults for the whole app, so it works alongside the other two ways as well. ## Auto-import If the app auto-imports components, add the resolver. With `unplugin-vue-components`: ```ts [vite.config.ts] import Components from 'unplugin-vue-components/vite' import AutoImport from 'unplugin-auto-import/vite' import { boneprintResolver } from 'boneprint/resolver' export default defineConfig({ plugins: [ vue(), Components({ resolvers: [boneprintResolver()] }), AutoImport({ imports: ['vue', { boneprint: ['forgetSkeletons', 'useInSkeleton'] }] }), ], }) ``` ```ts [vite.config.ts (Nuxt UI)] import ui from '@nuxt/ui/vite' import { boneprintResolver } from 'boneprint/resolver' // ui() runs unplugin-vue-components and unplugin-auto-import itself export default defineConfig({ plugins: [ vue(), ui({ components: { resolvers: [boneprintResolver()] }, autoImport: { imports: ['vue', { boneprint: ['forgetSkeletons', 'useInSkeleton'] }] }, }), ], }) ``` The generated `components.d.ts` keeps the slot's data typed, as with a direct import. ## Loading the data `:of` takes anything with `data`, `status` and `error`, so a TanStack Query result goes in as it is: ```vue ``` With anything else, set the state by hand: `:data`, `:loading`, `:empty` and `:error`. See [States](https://kukson777.github.io/boneprint/docs/guide/states). ## Compared with Nuxt Everything works the same, except one thing a single-page app doesn't need: without a server there's no HTML to draw a remembered shape into before JavaScript loads. The shape appears when the component mounts, which in a single-page app is the first moment anything is on screen at all. The remembered shape is keyed by the page, read from vue-router when there is one, or from the address otherwise. # Debugging > See where a skeleton came from and whether the page moved. A skeleton that doesn't match its content makes the page jump when the content arrives. The debug overlay finds those places. It outlines every skeleton in blue while it loads and says where its shape came from. When the content arrives, the outline turns green if nothing moved, or red with how many pixels it moved. ## Turning it on Add `?skeleton-debug` to the URL, or turn it on for the whole app: ```ts [nuxt.config.ts] export default defineNuxtConfig({ boneprint: { debug: true }, }) ``` ```ts [main.ts (Vue)] app.use(boneprint, { debug: true }) ``` To outline one part of the page, put `data-skeleton-debug` on any element around it. ## Where a shape comes from
Label Source
memory the shape remembered from an earlier load
data the data already on screen, with :loading over it
sample your sample
slot the slot as it is, without data or of
generic lines nothing to measure: pass a sample or an id
## Seeing what was measured Put `data-skeleton-xray` on any element around a skeleton. The hidden markup then shows through the bones in red, so you can check that the bars sit on the real lines. ```vue
``` ## When the page moves Most often the sample is shorter or longer than the real data, so give it text of typical length. If an image moves when it loads, it had no size to begin with: give it a `width` and `height`, or an `aspect-ratio`. # Markup > How the module reads your markup and how to steer it. ## What becomes what - Text becomes one bar per line. - `img`, `video`, `canvas`, `svg`, `iframe` and form fields become a block, and so do CSS icons drawn through a mask, like Nuxt UI's `UIcon`. - A painted element with text, up to about three lines tall, counts as a chip or button and becomes one block. - Table cells and elements with a divider on one side become bars. Toggle the switches to see each rule at work: ## Attributes
Attribute Effect
data-skeleton-block draw the element as one block
data-skeleton-skip leave the element out
## Your own skeleton A chart, a logo or a canvas doesn't measure well. Use the `#skeleton` slot to draw your own instead, and build it from ``, which follows the same colors and shimmer as every other skeleton. It takes `width`, `height` and `radius`. ## Height To fill the height of the parent, give the root a height: Margins of the content stay inside `` and don't collapse with its neighbours. ## Side effects in the slot Slot content mounts once for the skeleton and again for the content. Keep data fetching and subscriptions outside ``. When a component in the slot can't avoid them, `useInSkeleton()` tells it which copy it is in. It's `true` in the copy the skeleton is measured from: ```vue [PosterCard.vue] ``` Text that's only read to screen readers, like Tailwind's `sr-only`, sits in a clipped 1px box and draws no bone. # Real Screens > How it looks on the pages you actually build. Every example here makes a real request to [DummyJSON](https://dummyjson.com). Press Reload to see the loading state again. ## A product card Click the card to load another product. Descriptions differ in length, so a new product eases to its own height, and one you've already seen comes back at the right size. The photo opens full size with [nuxt-image-viewer](https://github.com/kukson777/nuxt-image-viewer). ```vue ``` ## A profile with two requests Each request gets its own ``, so the header appears as soon as it's ready and the posts follow. ```vue ``` ## An admin dashboard One request fills the stats and the table. Table cells become bars, so the rows don't merge into one gray block. ```vue ``` ## An inbox Avatars take the shape of their round frame, and truncated text gets a bar no wider than the line. ```vue ``` # Reveal > How content replaces the skeleton. ## Modes
Mode What happens
fade the content crossfades over the skeleton, the default
sequence each piece comes in where its skeleton was, top to bottom
sweep the content is uncovered from left to right
Set it on one skeleton, or for the whole app: ```vue ``` ```ts [nuxt.config.ts] export default defineNuxtConfig({ boneprint: { reveal: 'sequence' }, }) ``` ```ts [main.ts (Vue)] app.use(boneprint, { reveal: 'sequence' }) ``` With `prefers-reduced-motion`, every mode falls back to a plain swap. ## Fast responses A response that lands within 150 ms never shows a skeleton. Whatever is on screen waits that long before giving way, so a fast request doesn't flash. Change the wait with the `--skeleton-hold` CSS variable. ## Images Images never hold the content back. A photo still loading when the content appears keeps a pulsing placeholder in its box until it has loaded. Give images a `width` and `height`, or an `aspect-ratio`, so that box exists. # Sample and Memory > Where the shape comes from on the first and later visits. ## First visit There's no real data yet, so `sample` sets the shape. If the real text turns out longer or shorter, the block eases to its new height. Matching the size exactly on a first visit isn't possible: nobody knows the length of the response yet. Here the sample is shorter than the real post, so the block grows when the response arrives: If the data can be fetched on the server, remove `server: false`. The content then arrives in the HTML and no skeleton is needed. ## Later visits The shape of the last content is saved in `localStorage` and applied before the first paint. Memory is kept per `id`, which defaults to the page plus the order skeletons appear on it. Give an `id` to a skeleton that mounts and unmounts while the page stays, such as one inside tabs. A shape is only used at the same window width. At another width the text would wrap differently, so the sample is used again. If the layout depends on something else too, such as the window height or a setting, put that into the `id`: `:id="`shelf:${rows}`"`. Besides text and blocks, memory keeps the outlines of the layout: borders, dividers, and the fill of cards and panels in their own colors. A surface drawn with a gradient or an image is kept only when it's marked with `data-skeleton-block`. This example has no `sample` at all. The first load shows generic lines, and every load after it uses the remembered shape. Below it is exactly what's stored: ## What's stored Geometry only: fractions of the width and heights in pixels, for up to 50 shapes. No text, markup or attributes. ## Turning it off and clearing it ```vue ``` ```ts [nuxt.config.ts] export default defineNuxtConfig({ boneprint: { persist: false }, }) ``` ```ts [main.ts (Vue)] app.use(boneprint, { persist: false }) ``` On sign-out, call `forgetSkeletons()`. Memory is cleared, and whatever is on screen won't be written back. # States > Loading, content, empty responses and errors. ## What the component decides With `:of`, the state comes from the result of `useFetch`, `useAsyncData` or TanStack Query's `useQuery`: anything with `data`, `status` and `error`.
What arrived What's shown
no data yet, or [] while the request is still on its way the skeleton
an error the #error slot
a successful null or [] the #empty slot
data the default slot
An empty list before the answer is the data layer's placeholder, as with `default: () => []` or `data ?? []`. The skeleton is drawn from `sample` or memory then, not from that list. The same goes for `[]` passed to `:data` together with `:loading`. ## Refreshing `refresh()` doesn't flash the skeleton: the old data stays on screen until the new data arrives. If you do want a skeleton, pass `:loading`. ## Setting the state by hand Set the state by hand with `data`, `loading`, `empty` and `error`. With `immediate: false`, pass `:empty` until you call `execute()`. The `reveal` event fires when content has replaced the skeleton. ## With Suspense A child component that awaits in `setup` has no data to pass to ``. `` is a Suspense boundary with a measured fallback: the component goes in the default slot, and markup rendered from sample data goes in `#skeleton`. # Troubleshooting > Common problems and what to do about them. ## The skeleton never shows The request is holding up the page, so by the time it renders the data is already there. Two common causes: - `useFetch` without `lazy: true, server: false`: the server waits for the response and sends the content in the HTML. If that's fine, no skeleton is needed. - An `async` wrapper around `useFetch`. Awaiting it in `setup` waits for the response too. Keep the wrapper synchronous and return the `useFetch` result as it is: ```ts [composables/useApi.ts] // Not async: the caller gets data, status and error at once and passes them to :of export const useApi = (path: MaybeRefOrGetter) => useFetch(path, { baseURL: '/api', lazy: true, server: false }) ``` ## Nothing changed after updating the package Restart the dev server. Vite keeps transformed modules from `node_modules` in memory and doesn't watch them, so a reinstalled package keeps serving the old code until a restart. A shape remembered before the update is still drawn the old way until the content loads once and saves it again. To see the new drawing right away, call `forgetSkeletons()` or clear the `boneprint` key in `localStorage`. ## The page jumps when content arrives Turn on the [debug overlay](https://kukson777.github.io/boneprint/docs/guide/debugging) to see where the shape came from and how far the content moved. Most often the sample is shorter or longer than the real data, so give it text of typical length. ## An image moves when it loads It had no size until it loaded, so the skeleton had no room for it. Give it a `width` and `height`, or an `aspect-ratio`. ## Something is drawn the wrong way Use `data-skeleton-block` to draw an element as one block and `data-skeleton-skip` to leave it out. For a chart or a logo, use the [`#skeleton` slot](https://kukson777.github.io/boneprint/docs/guide/markup#your-own-skeleton). ## Three gray lines There was nothing to measure. Pass a `sample`, or an `id` so the shape can be remembered. In development, the console prints a ready-made sample once the first response arrives. ## Lines shift as a web font loads Skeletons measure again when fonts finish loading, so the first frame uses the fallback font. Preload the font to measure it from the start. ## A Content Security Policy blocks the script With Nuxt, the skeleton is drawn before hydration by one inline script. Set a per-request nonce in a server middleware, and the script picks it up: ```ts [server/middleware/nonce.ts] export default defineEventHandler((event) => { event.context.nonce = createNonce() // the same value as in your CSP header }) ``` ## Testing jsdom and happy-dom have no layout, so there is nothing to measure. While loading, the sample's text is in the document inside an `aria-hidden` skeleton: queries by role skip it, queries by text don't. # How It Works > What happens between the HTML and the content appearing. 1. The server sends the slot's markup rendered with the sample, with its text transparent. 2. A script in `` finds skeletons as the page is parsed. There's one per page, and components render no ` ``` ## Resources for Agents - [API catalog: every service document this site publishes](https://kukson777.github.io/boneprint/.well-known/api-catalog) - [Sitemap (XML)](https://kukson777.github.io/boneprint/sitemap.xml) - [Sitemap (Markdown): every page on the site](https://kukson777.github.io/boneprint/sitemap.md) - [llms.txt: index of the documentation for LLMs](https://kukson777.github.io/boneprint/llms.txt) - [llms-full.txt: the full documentation as a single file](https://kukson777.github.io/boneprint/llms-full.txt) - [OpenAPI document: every route this site serves to agents](https://kukson777.github.io/boneprint/openapi.json)