Skeleton

Placeholder blocks that sketch the layout of content while it loads, so the page does not jump when the data arrives. Use it for content areas; use a spinner or a button's loading state for actions.

  • vig-skeleton
  • vigSkeleton
Import
import { Skeleton, VigSkeleton } from '@vigdx/ui/skeleton';

Shapes

shape is text (default), rect or circle . Text skeletons render lines bars, the last one shorter; width and height take any CSS length.

text
rect
circle

Sizing with the font

Text bars are 1em tall, so wrap them in the text style they stand in for. Set animated to false for a static placeholder; the pulse also stops for users who prefer reduced motion.

Loading a card

Mirror the final layout with skeletons and swap them for the content when it arrives. One ariaLabel announces the whole placeholder; the other skeletons stay silent.

Loading profile

Skeleton directive

Put vigSkeleton on the real markup and it becomes its own placeholder while the data loads, with no second skeleton tree to keep in sync:

HTML
<h2 [vigSkeleton]="loading()">{{ user()?.name }}</h2>
<p [vigSkeleton]="loading()" vigSkeletonLines="3">{{ user()?.bio }}</p>
<img [vigSkeleton]="loading()" vigSkeletonShape="circle"
     [attr.src]="user()?.avatar" alt="" width="48" height="48" />

While vigSkeleton is true the element keeps its box, hides its content and shows the skeleton look: one bar per line for text, a filled block for vigSkeletonShape="rect" and "circle". An empty element is vigSkeletonLines lines tall (1lh each); vigSkeletonWidth and vigSkeletonHeight size it while loading, and [vigSkeletonAnimated]="false" stops the pulse. When it is false the directive adds nothing to the element.

Loading in place

The card renders the same avatar, name, role and bio while loading and after. Stale content from before a reload keeps the layout and turns into bars; the status line under the card announces each loading state once.

Customizing the directive

  • It follows the same tokens as vig-skeleton: --color-muted for the fill and --radius-skeleton for the corners.
  • While loading, the element carries [data-scope="skeleton"][data-part="root"][data-state="loading"] and aria-busy="true"; style that selector to adjust the placeholder. Text bars are background images in the element's content box, so its padding, border and background colour stay; rect and circle fill the element.
  • Use it on plain HTML elements. Kit components have their own scope and state on their host, so wrap them, or use their loading input. An inline element such as <span> has no box while empty: make it inline-block (a flex or grid item already is a block).

Styling hooks

Internal elements carry a stable data-part and the component's data-scope; both are public API, so removing one is a breaking change. Select a part by both, e.g. [data-scope="skeleton"][data-part="bar"] { … }: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through aria-* and, where listed, a data-state; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other data-* attributes listed below (such as data-opening while an overlay animates) are API too. See Customizing.

Skeleton [data-scope="skeleton"]

Skeleton styling hooks
Part Element data-state
bar One placeholder block or text line. —

VigSkeleton [data-scope="skeleton"]

VigSkeleton styling hooks
Part Element data-state
root The [vigSkeleton] element while loading ( inert , aria-busy="true" ); nothing while not. loading

Accessibility

  • Skeletons are hidden from assistive technology by default, so a group of them does not produce a series of empty announcements.
  • Give one skeleton per loading region an ariaLabel, e.g. “Loading profile”: it becomes a role="status" region with that text.
  • Mark the container that is loading with aria-busy="true" and set it back to false once the content is in place.
  • A vigSkeleton element is inert while loading: stale or empty content is neither read nor focusable, and focusable children leave the tab order instead of being hidden while focusable. It also gets aria-busy="true". It announces nothing by itself, so a page of placeholders is not a series of announcements: give the loading region one status message, as the demo above does.
  • inert also takes focus away: when loading starts while focus is inside the element, the browser moves it to the page. Move focus to something that stays, such as the loading region itself (tabindex="-1"), before reloading content the user is working in; dev mode warns once when this happens.
  • An element's own inert, aria-busy and data-scope/data-part/data-state values come back when loading ends.
  • In forced-colors mode (Windows High Contrast) the placeholders are drawn in GrayText, since forced colors drop author backgrounds.
  • The pulse animation stops when the user prefers reduced motion (prefers-reduced-motion).

API

Skeleton

vig-skeleton component

Placeholder block shown while content loads. Hidden from assistive tech by default; pass ariaLabel to announce it as a role="status" region.

Skeleton props
Name Type Default Description
animatedbooleantrue

Pulses while loading; static with reduced motion.

ariaLabelstring | undefinedundefined

Announces the placeholder (e.g. "Loading profile") as a status region.

heightstring | undefinedundefined

Any CSS length. Text lines are 1em tall; rect defaults to 1em.

linesnumber1

Number of text bars (shape="text" only); the last of several is shorter.

shapeSkeletonShape'text'
—
widthstring | undefinedundefined

Any CSS length, e.g. '12rem' or '60%'. Text and rect fill their container by default.

VigSkeleton

[vigSkeleton] directive

Turns the element it sits on into its own loading placeholder, so a loading state needs no parallel skeleton markup:

Example :
<h2 [vigSkeleton]="loading()">{{ user()?.name }}</h2>
<p [vigSkeleton]="loading()" vigSkeletonLines="3">{{ user()?.bio }}</p>
<img [vigSkeleton]="loading()" vigSkeletonShape="circle" [attr.src]="user()?.avatar" alt="" />

While vigSkeleton is true the host keeps its layout box, its content is hidden (text transparent, child elements visibility: hidden, an image's picture moved out of its box) and it shows the vig-skeleton look instead: one bar per line for text, a filled block for rect and circle. A text host with no content yet (whitespace aside) is vigSkeletonLines lines tall. The host is inert (out of the tab order and the accessibility tree, so stale or empty content is not read; a focused element inside loses focus) and carries aria-busy="true", data-scope="skeleton", data-part="root" and data-state="loading". The host's own values of these attributes come back when loading ends; while false the directive adds nothing.

It announces nothing: give the loading region one announcement, e.g. a vig-skeleton with an ariaLabel. Use it on plain HTML elements, not on kit components, whose hosts carry their own scope and state. An inline element (<span>) has no box while empty: make it inline-block. root skeleton loading

VigSkeleton props
Name Type Default Description
vigSkeletonbooleanfalse

Shows the placeholder while true (a bare vigSkeleton attribute counts as true).

vigSkeletonAnimatedbooleantrue

Pulses while loading; static with reduced motion.

vigSkeletonHeightstring | undefinedundefined

Height while loading, any CSS length; a circle with only a width stays square.

vigSkeletonLinesnumber1

Lines an empty text host shows (1lh each); the last of several is shorter.

vigSkeletonShapeSkeletonShape'text'

text (default) draws one bar per line; rect and circle fill the host.

vigSkeletonWidthstring | undefinedundefined

Width while loading, any CSS length (e.g. '70%'); the host's own width otherwise.

Are you sure?