Placeholder
Use loading placeholders (skeleton loaders) for your components or pages to indicate something may still be loading.
Use Placeholder for skeleton shapes and animation, and PlaceholderButton for a disabled
button-shaped placeholder. Their props generate the component styles discussed below.
About
Placeholders are built with HTML and CSS and need no JavaScript. Render them conditionally to control
visibility, and use the Placeholder props to set their color, size, width, or animation. When
animating several placeholders together, render them as children of an animated Placeholder.
Example
In the example below, we take a typical card component and recreate it with placeholders applied to create a “loading card”. Size and proportions are the same between the two.
Card title
Some quick example text to build on the card title and make up the bulk of the card’s content.
Go somewhere<div className="d-flex justify-content-around flex-wrap gap-3">
<Card
style={{
width: '18rem'
}}
>
<CardImage
alt=""
height="180"
placement="top"
src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22640%22%20height%3D%22180%22%20viewBox%3D%220%200%20640%20180%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22%2320c997%22%2F%3E%3Ctext%20x%3D%2250%25%22%20y%3D%2250%25%22%20fill%3D%22%23fff%22%20dominant-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20font-family%3D%22sans-serif%22%20font-size%3D%2224%22%3E%3C%2Ftext%3E%3C%2Fsvg%3E"
width="100%"
/>
<CardBody>
<CardTitle as="h5">
Card title
</CardTitle>
<CardText>
Some quick example text to build on the card title and make up the bulk of the
card’s content.
</CardText>
<Button
href="#"
theme="primary"
variant="solid"
>
Go somewhere
</Button>
</CardBody>
</Card>
<Card
aria-hidden="true"
style={{
width: '18rem'
}}
>
<CardImage
alt=""
height="180"
placement="top"
src="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22640%22%20height%3D%22180%22%20viewBox%3D%220%200%20640%20180%22%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22%23868e96%22%2F%3E%3Ctext%20x%3D%2250%25%22%20y%3D%2250%25%22%20fill%3D%22%23fff%22%20dominant-baseline%3D%22middle%22%20text-anchor%3D%22middle%22%20font-family%3D%22sans-serif%22%20font-size%3D%2224%22%3E%3C%2Ftext%3E%3C%2Fsvg%3E"
width="100%"
/>
<CardBody>
<Placeholder
animation="wave"
as="h5"
className="card-title"
>
<Col
as={function ve(){}}
xs={6}
/>
</Placeholder>
<Placeholder
animation="wave"
as="p"
className="card-text"
>
<Col
as={function ve(){}}
xs={7}
/>
<Col
as={function ve(){}}
xs={4}
/>
<Col
as={function ve(){}}
xs={4}
/>
<Col
as={function ve(){}}
xs={6}
/>
<Col
as={function ve(){}}
xs={8}
/>
</Placeholder>
<Col
aria-disabled="true"
as={function ve(){}}
href="#"
theme="primary"
variant="solid"
xs={6}
/>
</CardBody>
</Card>
</div>How it works
Render Placeholder for a skeleton shape, and use Col to set its grid width. Use the as prop
when the placeholder should render as a different element.
PlaceholderButton applies the button sizing and disabled state for button-shaped placeholders.
<Stack gap={3}>
<p aria-hidden="true">
<Col
as={function ve(){}}
xs={6}
/>
</p>
<Col
aria-disabled="true"
as={function ve(){}}
href="#"
theme="primary"
variant="solid"
xs={4}
/>
</Stack>The use of
aria-hidden="true"only indicates that the element should be hidden to screen readers. The loading behavior of the placeholder depends on how authors will actually use the placeholder styles, how they plan to update things, etc. Some JavaScript code may be needed to swap the state of the placeholder and inform AT users of the update.
Width
Set the width prop for a fixed or percentage width, use Col for grid sizing, or pass Bootstrap
width utilities through className.
<Stack gap={3}>
<Col
as={function ve(){}}
xs={6}
/>
<Placeholder className="w-75" />
<Placeholder width="25%" />
</Stack>Color
By default, Placeholder uses currentColor. Set its theme prop to choose a theme color, or use
className for a custom color.
<Stack gap={3}>
<Col
as={function ve(){}}
xs={9}
/>
<Col
as={function ve(){}}
theme="primary"
xs={6}
/>
<Col
as={function ve(){}}
theme="accent"
xs={6}
/>
<Col
as={function ve(){}}
theme="secondary"
xs={6}
/>
<Col
as={function ve(){}}
theme="success"
xs={6}
/>
<Col
as={function ve(){}}
theme="danger"
xs={6}
/>
<Col
as={function ve(){}}
theme="warning"
xs={6}
/>
<Col
as={function ve(){}}
theme="info"
xs={6}
/>
<Col
as={function ve(){}}
theme="inverse"
xs={6}
/>
</Stack>Sizing
The size of Placeholder follows the typographic style of its parent. Set size to "lg", "sm",
or "xs" to use a sizing modifier.
<Stack gap={2}>
<Col
as={function ve(){}}
size="lg"
xs={12}
/>
<Col
as={function ve(){}}
xs={12}
/>
<Col
as={function ve(){}}
size="sm"
xs={12}
/>
<Col
as={function ve(){}}
size="xs"
xs={12}
/>
</Stack>Animation
Set Placeholder's animation prop to "wave" for the default loading animation, or "pulse" for
an opacity pulse. "glow" remains available as a compatibility alias for "pulse".
<Stack gap={3}>
<Placeholder
animation="wave"
as="p"
>
<Col
as={function ve(){}}
xs={12}
/>
</Placeholder>
<Placeholder
animation="pulse"
as="p"
>
<Col
as={function ve(){}}
xs={12}
/>
</Placeholder>
</Stack>Text
Set animation on Placeholder to apply the loading animation to text.
<Stack gap={3}>
<Placeholder
animation="wave"
as="span"
className="fg-3"
>
<p>
Working on it…
</p>
</Placeholder>
</Stack>CSS
Variables
| CSS variable | Default |
|---|---|
--bs-placeholder-opacity-max | 0.18 |
--bs-placeholder-opacity-min | 0.1 |
--bs-placeholder-wave-opacity-max | 1 |
--bs-placeholder-wave-opacity-min | 0.4 |