
# Skeleton



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

## Examples

### Default

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

export default () => <Skeleton lines={3} effect="sheen" />;

```

```html
<k-skeleton aria-hidden="true" lines="3">
  <span></span>
  <span></span>
  <span></span>
</k-skeleton>
```

### Card

```tsx
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>
);

```

```html
<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>
```

### Colors

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

export default () => (
  <Skeleton
    lines={2}
    effect="sheen"
    style={{ "--k-skeleton-color": "var(--k-color-bg-primary)" }}
  />
);

```

```html
<k-skeleton aria-hidden="true" lines="2" effect="sheen" style="--k-skeleton-color: var(--k-color-bg-primary)">
  <span></span>
  <span></span>
</k-skeleton>
```

### Effects

```tsx
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>
);

```

```html
<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>
```

### Shapes

```tsx
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>
);

```

```html
<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>
```

### Sizes

```tsx
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>
);

```

```html
<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>
```

### Text sizes

```tsx
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>
);

```

```html
<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>
```


## Props

- `shape` — `"text" | "circle" | "square" | "rectangle"` (default: `"text"`) 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.
- `effect` — `"pulse" | "sheen"` The animation the skeleton uses while content loads. Leave it out for a static skeleton.
- `lines` — `number` The number of text lines to render, with a shorter last line. Only applies to the `text` shape.

## CSS custom properties

- `--k-skeleton-color` (default: `var(--k-color-bg-container)`) Overrides the skeleton color.
- `--k-skeleton-sheen-color` (default: `rgb(255 255 255 / 50%)`) Overrides the highlight that sweeps across with the sheen effect.
- `--k-skeleton-radius` (default: `var(--k-radius-sm)`) Overrides the border radius.
- `--k-skeleton-size` (default: `var(--k-space-3xl)`) Overrides the width and height of the circle and square shapes.

## 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](/components/visually-hidden/) 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](/accessibility/) and the [A11Y checklist](/a11y-checklist/) for more details.

## Integration

Install `@kesko/components` together with `@kesko/css`, which provides the design tokens and base styles it depends on, and `@kesko/themes` for your brand:

```sh
npm install @kesko/components @kesko/css @kesko/themes
```

Then load the base stylesheet and one brand theme once, in your app's entry point or root layout. Leave out `@kesko/css/components`: it mirrors the component styles for plain HTML, and `@kesko/components` already ships them.

```tsx
import "@kesko/css";
import "@kesko/themes/dist/k-rauta.css";
```

Finally, import the component into your project:

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

Projects without React get the same markup and styling from `@kesko/css` by importing the base stylesheet, the `components` add-on and a brand theme, in that order:

```css
@import "@kesko/css";
@import "@kesko/css/components";
@import "@kesko/themes/dist/k-rauta.css";
```

The HTML examples above show the exact markup to copy.

## Resources

- [Usage guidelines](/components/usage/) — Learn how to use the component library with React, Next.js, or basic HTML.
- [Localization](/localization/) — How to translate the components for multiple languages.
- [CSS Framework](/css/) — Utilities and tokens for everything the components don’t cover.
- [Themes](/themes/) — How to customize the component library theme.
- [Accessibility checklist](/a11y-checklist/) — Interactive, browser-based Kesko accessibility checklist.

