Skeleton component is used to provide a low fidelity representation of content before it appears. This improves the perceived loading time for users.
import { Skeleton } from "@kesko/components";
export default () => <Skeleton lines={3} effect="sheen" />;<k-skeleton aria-hidden="true" lines="3">
<span></span>
<span></span>
<span></span>
</k-skeleton>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>
);<k-stack direction="row" gap="sm" alignment="center" nowrap aria-busy="true" style="max-inline-size: 20rem">
<k-skeleton aria-hidden="true" shape="circle" effect="pulse"></k-skeleton>
<k-skeleton aria-hidden="true" lines="2" effect="pulse">
<span></span>
<span></span>
</k-skeleton>
</k-stack>import { Skeleton } from "@kesko/components";
export default () => (
<Skeleton
lines={2}
effect="sheen"
style={{ "--k-skeleton-color": "var(--k-color-bg-primary)" }}
/>
);<k-skeleton aria-hidden="true" lines="2" effect="sheen" style="--k-skeleton-color: var(--k-color-bg-primary)">
<span></span>
<span></span>
</k-skeleton>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>
);<k-stack gap="lg" alignment="stretch">
<k-stack gap="2xs" alignment="stretch">
<span class="k-text-sm">None</span>
<k-skeleton aria-hidden="true" lines="3">
<span></span>
<span></span>
<span></span>
</k-skeleton>
</k-stack>
<k-stack gap="2xs" alignment="stretch">
<span class="k-text-sm">Pulse</span>
<k-skeleton aria-hidden="true" effect="pulse" lines="3">
<span></span>
<span></span>
<span></span>
</k-skeleton>
</k-stack>
<k-stack gap="2xs" alignment="stretch">
<span class="k-text-sm">Sheen</span>
<k-skeleton aria-hidden="true" effect="sheen" lines="3">
<span></span>
<span></span>
<span></span>
</k-skeleton>
</k-stack>
</k-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>
);<k-stack direction="row" gap="md" alignment="center">
<k-skeleton aria-hidden="true" shape="circle"></k-skeleton>
<k-skeleton aria-hidden="true" shape="square"></k-skeleton>
<k-skeleton aria-hidden="true" shape="rectangle" style="inline-size: 8rem; block-size: 3rem"></k-skeleton>
</k-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>
);<k-stack direction="row" gap="md" alignment="center">
<k-skeleton aria-hidden="true" shape="circle" style="--k-skeleton-size: var(--k-space-xl)"></k-skeleton>
<k-skeleton aria-hidden="true" shape="circle"></k-skeleton>
<k-skeleton aria-hidden="true" shape="square" style="--k-skeleton-size: 6rem"></k-skeleton>
</k-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>
);<k-stack gap="sm">
<k-skeleton aria-hidden="true" class="k-text-3xl" style="inline-size: 60%"></k-skeleton>
<k-skeleton aria-hidden="true" class="k-text-md" lines="3">
<span></span>
<span></span>
<span></span>
</k-skeleton>
<k-skeleton aria-hidden="true" class="k-text-xs" style="inline-size: 30%"></k-skeleton>
</k-stack>Properties #
| Name | Description | Type | Default |
|---|---|---|---|
shape | The shape of the skeleton. | "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 | 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.
| Name | Description | Default |
|---|---|---|
--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/csspnpm add @kesko/components @kesko/cssyarn add @kesko/components @kesko/cssbun add @kesko/components @kesko/cssOnce 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 #
Usage guidelines
Learn how to use the component library with React, Next.js, or basic HTML.
Localization
How to translate the components for multiple languages.
CSS Framework
Utilities and tokens for everything the components don’t cover.
Themes
How to customize the component library theme.
Accessibility checklist
Interactive, browser-based Kesko accessibility checklist.