Skeleton component is used to provide a low fidelity representation of content before it appears. This improves the perceived loading time for users.

Open in new tab
import { Skeleton } from "@kesko/components";

export default () => <Skeleton lines={3} effect="sheen" />;
import { Skeleton, Stack } from "@kesko/components";

export default () => (
  <Stack direction="row" gap="sm" alignment="center" nowrap aria-busy="true" style={{ maxInlineSize: "20rem" }}>
    <Skeleton shape="circle" effect="pulse" />
    <Skeleton lines={2} effect="pulse" />
  </Stack>
);
import { Skeleton } from "@kesko/components";

export default () => (
  <Skeleton
    lines={2}
    effect="sheen"
    style={{ "--k-skeleton-color": "var(--k-color-bg-primary)" }}
  />
);
import { Skeleton, Stack } from "@kesko/components";

export default () => (
  <Stack gap="lg" alignment="stretch">
    <Stack gap="2xs" alignment="stretch">
      <span className="k-text-sm">None:</span>
      <Skeleton lines={3} />
    </Stack>
    <Stack gap="2xs" alignment="stretch">
      <span className="k-text-sm">Pulse:</span>
      <Skeleton effect="pulse" lines={3} />
    </Stack>
    <Stack gap="2xs" alignment="stretch">
      <span className="k-text-sm">Sheen:</span>
      <Skeleton effect="sheen" lines={3} />
    </Stack>
  </Stack>
);
import { Skeleton, Stack } from "@kesko/components";

export default () => (
  <Stack direction="row" gap="md" alignment="center">
    <Skeleton shape="circle" />
    <Skeleton shape="square" />
    <Skeleton shape="rectangle" style={{ inlineSize: "8rem", blockSize: "3rem" }} />
  </Stack>
);
import { Skeleton, Stack } from "@kesko/components";

export default () => (
  <Stack direction="row" gap="md" alignment="center">
    <Skeleton shape="circle" style={{ "--k-skeleton-size": "var(--k-space-xl)" }} />
    <Skeleton shape="circle" />
    <Skeleton shape="square" style={{ "--k-skeleton-size": "6rem" }} />
  </Stack>
);
import { Skeleton, Stack } from "@kesko/components";

export default () => (
  <Stack gap="sm">
    <Skeleton className="k-text-3xl" style={{ inlineSize: "60%" }} />
    <Skeleton className="k-text-md" lines={3} />
    <Skeleton className="k-text-xs" style={{ inlineSize: "30%" }} />
  </Stack>
);

Properties #

NameDescriptionTypeDefault
shape

The shape of the skeleton. text is one line that follows the surrounding font size and line height, circle and square stand in for avatars and thumbnails, and rectangle fills its container.

"text" | "circle" | "square" | "rectangle""text"
effect

The animation the skeleton uses while content loads. Leave it out for a static skeleton.

"pulse" | "sheen"—
lines

The number of text lines to render, with a shorter last line. Only applies to the text shape.

number—

Styles #

CSS custom properties provide finer-grained control than properties. See Styling API for more details. Prefer the Properties API when it suits your need.

NameDescriptionDefault
--k-skeleton-color

Overrides the skeleton color.

var(--k-color-bg-container)
--k-skeleton-sheen-color

Overrides the highlight that sweeps across with the sheen effect.

rgb(255 255 255 / 50%)
--k-skeleton-radius

Overrides the border radius.

var(--k-radius-sm)
--k-skeleton-size

Overrides the width and height of the circle and square shapes.

var(--k-space-3xl)

Accessibility #

Skeleton is a decorative <k-skeleton> element. It is hidden from assistive technology, so screen reader users need to hear about the wait another way.

  • Mark the region that is loading. Set aria-busy="true" on the container the skeletons sit in, and remove it when the content arrives.
  • Announce the wait once. A page of skeletons says nothing to a screen reader. Add one status message for the whole view, for example a VisuallyHidden element with role="status" that reads “Ladataan tilaushistoriaa.”
  • Use effects sparingly. Many animated skeletons at once pull attention away from the rest of the page. Pick one effect per view, or leave the skeletons static in dense layouts.
  • Remove it when the wait ends. Render the content in place of the skeleton instead of hiding the skeleton behind it.

See the accessibility guidelines and the A11Y checklist for more details.


Usage #

There are two necessary parts to using the Skeleton component. The @kesko/components package and the CSS Framework are required. Everything else is optional:

npm install @kesko/components @kesko/css

Once installed, load the CSS Framework in your app’s entry point or root layout:

import "@kesko/css";

Then, you can import the Skeleton:

import { Skeleton } from "@kesko/components";

Projects without React can get the same styles from @kesko/css by importing the components stylesheet as well:

@import "@kesko/css";
@import "@kesko/css/components";

Resources #