Skip to content

Skeleton

Last updated 11 Nov 2026

NbSkeleton stands in for content that is about to arrive, in the shape and at the size the real content will occupy. That last part is the whole component: a placeholder that is not the right height is worse than no placeholder, because the page settles twice, once when the skeleton appears and again when it is replaced.

Why the sizing rules matter ​

A text skeleton does not guess a height. The line box is font-size x line-height read straight off a type set through the --nb-type-* custom properties, so a body-md skeleton line is exactly as tall as the body-md paragraph that replaces it. The grey bar inside is shorter than the line box, the way ink is shorter than a line of text, which is why it reads as text rather than as a wall.

That is also why type is a closed list. An unknown name would resolve to an empty custom property, the line would collapse to zero height, and the page would shift on load: exactly the bug this component prevents, made invisible by a typo. An unrecognised value falls back to body-md.

The list is every type set that content arrives in: label, label-sm/md/lg, helper-text, overline, body-sm, body-compact, body-md/lg, code-sm/md/lg, heading-compact and heading-01 through heading-06. The code sets are there because monospaced blocks are the worst offenders: a JSON viewer placeholder measured with body-md is a different height from the mono text that lands in it. display-01 and display-02 are deliberately absent, since hero type does not arrive asynchronously.

vue
<template>
  <!-- Matches a heading-03 title, to the pixel -->
  <NbSkeleton variant="heading" type="heading-03" />
</template>
VariantSized byUse for
texttype (default body-md), linesParagraphs, cell values, list items
headingtype (default heading-02)Titles and section headers
blockwidth and height you passCards, images, charts, map panes
circleOne of width or heightAvatars, round icon buttons
buttonsize, and iconOnlyAn NbButton that has not arrived

Text and paragraphs ​

lines renders that many line boxes. From two lines up, the last one is shortened to lastLineWidth (60% by default) so a paragraph does not read as a solid rectangle. A single line keeps its full width, because one short line reads as a truncated value rather than as flowing text.

vue
<template>
  <NbSkeleton :lines="4" last-line-width="35%" />
</template>

Match the line count to what usually arrives. Three lines standing in for one line of text is its own layout shift, just in the other direction.

Blocks and circles ​

width and height accept a number (pixels) or any CSS length, including a token reference. Pass the measurement the real element already has rather than a round number that looks about right.

vue
<template>
  <!-- The chart canvas is 240px tall, so the placeholder is too -->
  <NbSkeleton variant="block" :height="240" radius="md" />

  <!-- The avatar is one field height, so the placeholder tracks the scale -->
  <NbSkeleton variant="circle" height="var(--nb-field-height-md)" />
</template>

A circle takes one measurement and applies it to both axes, so an avatar placeholder cannot come out oval. radius is ignored for circles and otherwise takes a step from the radius scale: none, xs, sm (default), md, lg, pill.

Buttons ​

variant="button" stands in for an NbButton. size takes the button's own scale, so the placeholder is exactly as tall as the button that replaces it: 16, 24, 32, 40, 48, 64 and 80px from xxs to xxl. The corners are the control radius every button has, whatever radius says.

A labelled placeholder is 150px wide: the 16px a button keeps at its start and the 64px it reserves at its end for the icon, around a 70px label, which is about a two-word action. Pass width when the real label is known to be longer, or width="100%" when the button fills a set. iconOnly makes it a square at the height of size, the shape every icon-only button has, and ignores width.

vue
<template>
  <NbGrid gap="sm">
    <NbSkeleton variant="button" size="lg" label="Loading actions" />
    <NbSkeleton variant="button" size="lg" />
  </NbGrid>
</template>

xl and xxl are minimum heights on a real button, where a long label wraps to a second line. The placeholder takes the one-line height, which is what every short label has. Before reaching for a button skeleton, ask whether a disabled button would do: a button whose label is already known can render disabled while its data loads, and keeps its name and its place in the tab order.

Composing a loading region ​

Skeletons are laid out by you, in the same container as the real content, using the same gaps. Reuse the real component's wrapper so the two states cannot disagree.

vue
<template>
  <NbGrid gap="md" align="center">
    <NbSkeleton variant="circle" :width="40" label="Loading profile" />
    <NbGrid dir="col" gap="xs" grow>
      <NbSkeleton variant="heading" type="heading-01" width="45%" />
      <NbSkeleton :lines="2" />
    </NbGrid>
  </NbGrid>
</template>

Only one skeleton in the region carries a label. The rest are silent, so a table of forty placeholders announces itself once rather than forty times.

When the fetch fails ​

A skeleton is not an empty state and not an error state. Swap it for NbEmptyState when the response is legitimately empty, and for a message or banner when the request failed. A single "no contacts yet" element for loading, empty and failed alike makes a broken API read as a user with no data.

If you set completeLabel, the failure path has one more line to write. The skeleton announces that message when it is unmounted, and a failed fetch unmounts it just as surely as a successful one does, so without this a screen reader user is told "Description loaded" at the exact moment the screen filled with an error they cannot see. Say so where the failure is known:

ts
import { suppressLoadingAnnouncement } from '@nubisco/ui'

try {
  description.value = await api.load()
} catch (reason) {
  // The skeleton is about to be replaced by a banner. Nothing completed.
  suppressLoadingAnnouncement()
  error.value = reason
} finally {
  loading.value = false
}

The call covers anything queued for the rest of the current task, so it holds across the render that removes the skeleton, and then lifts by itself: the next load is a new load and announces its own ending normally.

It has to be a call rather than a :failed prop, and the reason is a Vue detail worth knowing. Props are not updated on the render that unmounts a component, so a flag flipped in the same tick as v-if="loading" is never seen by the teardown handler that does the announcing. The half of the code that knows the load failed is the catch, so that is the half that speaks.

If the request is driven through useInlineLoading, this is already done for you: its run() suppresses the announcement when the action rejects.

Props ​

PropTypeDefaultDescription
variant'text' | 'heading' | 'block' | 'circle' | 'button''text'Shape family
type'label', 'label-sm|md|lg', 'helper-text', 'overline', 'body-sm|compact|md|lg', 'code-sm|md|lg', 'heading-compact', 'heading-01'..'heading-06''body-md' for text, 'heading-02' for headingType set the line height is taken from
linesnumber1Number of text lines. Text variant only
lastLineWidthstring'60%'Width of the last line when there is more than one
widthstring | numberundefinedWidth. A number is pixels. Unset means the CSS default, which is width: 100%
heightstring | numberundefinedHeight for block and circle. A number is pixels. Unset means --nb-skeleton-height, which is calc(var(--nb-base-unit) * 8). Text sizes itself from type and ignores it
size'xxs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl''md'Button variant only. The NbButton size it stands in for, which sets the height
iconOnlybooleanfalseButton variant only. A square at the height of size, for an icon-only button
radius'none' | 'xs' | 'sm' | 'md' | 'lg' | 'pill''sm'Corner radius step. Ignored by circle
animatedbooleantrueTurns the shimmer off when false
labelstringundefinedAnnouncement. Set it on one skeleton per region
completeLabelstringundefinedAnnounced once when the skeleton unmounts and content lands
idstringautoExplicit DOM id, otherwise generated by useStableId

Events ​

None.

Tokens ​

TokenUsed for
--nb-type-*-sizeFont size of a text or heading line. With --nb-type-*-line-height it gives the line box its height
--nb-type-*-line-heightLine box height multiplier, so the swap does not shift
--nb-c-discretePlaceholder fill, in both themes
--nb-c-surfaceThe shimmer highlight, mixed into the fill
--nb-radius-*Corner radius steps
--nb-radius-controlThe button variant's corners, the same radius a real button has
--nb-base-unitGap between lines, and the button variant's height and width

Width does not come from a token: it is the width prop (and lastLineWidth for the final line of a paragraph), defaulting to 100% of whatever the skeleton is placed in. The type tokens control the vertical axis only, which is the axis that causes layout shift.

Under forced-colors: active the fill leaves the token system entirely and paints from Canvas / CanvasText, because a discarded background is indistinguishable from no content at all.