---
title: Skeleton
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, TokensTable, PropsTable } from '../../src/components'
import { Skeleton as BaseDocs } from 'docs/@telus-uds/components-base'
import AvailableOnBoth from '../../partials/_platform-considerations-both.mdx'
import NoStylisticVariants from '../../partials/_variants-none.mdx'

# Skeleton

<LibraryInfo />

```jsx live
<Skeleton />
```

## Introduction

Content placeholders to mock content while it is loading.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

Use Skeleton to show visual placeholders for loading content. Limit use to content and pages you expect to have a longer wait time, such as search pages loading content from a server.

During waits of a few seconds, a skeleton that loosely resembles the shape of incoming content may help the user understand where to look on the page, and may make the load time feel faster. For near-instant content loads, however, showing a skeleton first may cause a jarring flash.

Don't use Skeleton to replace every line of text. Skeleton is meant to give a general visualization of content to come.

### Alternatives

- [Spinner](spinner) with an appropriate label may be more appropriate when a user's primary goal is the completion of an action, rather than seeing new content. For example, when saving changes to a form, a spinner labelled "Saving changes" is more relevant to the user's goals.

- [Progress](progress) may be more appropriate for very slow content loads that involve long processes, where a user watching a skeleton may begin to worry that something has failed.

## Shapes

### Line

By default, a Skeleton component renders one or more lines that resemble lines of text.

- The `lines` prop may be used to render multiple lines of text spaced with `8px` (equivalent to `space={2}`) between them.
- The `characters` prop sets the line's width in multiples of 40px (regardless of skeleton size).

```jsx live
<StackView space={2}>
  <Skeleton characters={8} sizeIndex={5} />
  <Skeleton characters={10} lines={3} />
  <Skeleton characters={6} />
</StackView>
```

### Circle

Circular skeletons are often used to represent circular content such as profile images.

```jsx live
<Skeleton shape="circle" sizePixels={128} />
```

### Box

Square skeletons may represent square content with rounded corners.

```jsx live
<Skeleton shape="box" sizePixels={128} />
```

:::info
Rectangular skeletons with different height and width are not currently supported. If this is needed, please [file a feature request](/about/contributing) describing the use case.
:::

### Sizing

- For simple sizing, pass the `sizeIndex` prop a number from 1-11. These pick sizes on the theme's [spacing scale](sizing#spacing-and-layout) which will complement other spacing on the page.
- For exact sizing, pass the `sizePixels` prop a number to exactly match content of a known pixel size.
  `

```jsx live
function SkeletonExample() {
  const characters = useResponsiveProp({ xs: 2, md: 4, xl: 6 })

  return (
    <StackView space={3} direction="row">
      <Skeleton sizePixels={112} shape="circle" />
      <StackView space={3}>
        <Skeleton sizeIndex={5} characters={characters} />
        <Skeleton sizeIndex={3} lines={3} characters={characters} />
      </StackView>
    </StackView>
  )
}
```

#### Responsive sizing

Both `sizeIndex` and `sizePixels` may be passed either simple numbers, or responsive objects for different viewports, e.g. `{ xs: 4, lg: 8 }` to be `4` on xs, sm and md viewports and `8` on lg and xl viewports.

In this example, size and spacing are smaller on smaller viewports:

```jsx live
function SkeletonExample() {
  const characters = useResponsiveProp({ xs: 2, md: 4, xl: 6 })

  return (
    <StackView space={3} direction="row">
      <Skeleton sizePixels={{ xs: 96, md: 112, xl: 128 }} shape="circle" />
      <StackView space={{ xs: 3, md: 4, xl: 5 }}>
        <Skeleton sizeIndex={{ xs: 3, md: 4, xl: 5 }} characters={characters} />
        <Skeleton sizeIndex={3} lines={3} characters={characters} />
      </StackView>
    </StackView>
  )
}
```

### SkeletonProvider

```jsx
import { SkeletonProvider } from '@telus-uds/components-web'
```

`SkeletonProvider` can be used as a loading container for `Image` and `Typography` components. If the SkeletonProvider has a `show` boolean property set to true, they will be replaced by a skeleton.

Skeletons for square and circular images will be sized and shaped automatically based on the Image's props.

:::info
`Image` and `Typography` components within a SkeletonProvider may take a object prop `skeleton` of Skeleton props which will be passed to the skeleton when it is shown.
:::

```jsx live
<SkeletonProvider show>
  <StackView space={2} direction="row">
    <Image src={testImage} alt="test" width={100} rounded="circle" />
    <Box flex={1}>
      <StackView space={2}>
        <Typography variant={{ size: 'h2' }} skeleton={{ sizeIndex: 5, characters: 6 }}>
          Lorem ipsum
        </Typography>
        <Typography skeleton={{ lines: 3 }}>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit Lorem ipsum dolor sit amet,
          consectetur adipiscing elit Lorem ipsum dolor sit amet, consectetur adipiscing elit
        </Typography>
      </StackView>
    </Box>
  </StackView>
</SkeletonProvider>
```

### Accessibility

Skeletons are intended as a purely visual placeholder and will normally be ignored by assistive technology such as screen readers.

It is possible to pass in React Native accessibility props ([web docs](https://necolas.github.io/react-native-web/docs/accessibility/),
[native docs](https://reactnative.dev/docs/accessibility)), but in cases where this seems appropriate, it is likely that a more descriptive [alternative component](#alternatives) is more suitable.

### Platform considerations

<AvailableOnBoth />

## Props

<PropsTable base={BaseDocs} />

## Tokens

<TokensTable base={BaseDocs} component="Skeleton" />

## Variants

<NoStylisticVariants />

## Feedback

<Feedback component="Skeleton" />
