Skip to content

Basic Components

[02] Basic Components

Skeleton

The skeleton prop shows any component as a loading placeholder in its own layout, and on a container reaches everything inside. Skeleton is a plain box for custom areas.

SourceEdit this page

A skeleton is a placeholder that holds the shape of content while it loads. In VaneUI it is a prop, not a separate set of components: add skeleton to a component and it is drawn as a placeholder in its own layout, at its own size. On a container, every component inside turns into a placeholder too. For an area that has no component of its own, such as a chart or a map, use the Skeleton box. Both need @vaneui/ui 1.8.0 or later.

const photo = "/puppy.webp";

Turn a card into a placeholder with one prop

skeleton on a Card reaches everything inside it. Text turns into bars, one per line and as long as the line. Buttons, badges, fields and avatars turn into solid shapes of their own size and corners. The Card keeps its surface and border, so the page reads before the data arrives.

Biscuit
Biscuit

Head of snacks

Reviews every pull request that mentions treats, usually within the hour.

Online
Biscuit
Biscuit

Head of snacks

Reviews every pull request that mentions treats, usually within the hour.

Online
<Row tabletStack itemsStart>
<Card skeleton className="w-80">
<Row>
<Avatar src={photo} name="Biscuit"/>
<Col noGap>
<Title sm>Biscuit</Title>
<Text sm secondary>Head of snacks</Text>
</Col>
</Row>
<Text>Reviews every pull request that mentions treats, usually within the hour.</Text>
<Row>
<Badge success dot>Online</Badge>
<Button filled>Follow</Button>
</Row>
</Card>
<Card className="w-80">
<Row>
<Avatar src={photo} name="Biscuit"/>
<Col noGap>
<Title sm>Biscuit</Title>
<Text sm secondary>Head of snacks</Text>
</Col>
</Row>
<Text>Reviews every pull request that mentions treats, usually within the hour.</Text>
<Row>
<Badge success dot>Online</Badge>
<Button filled>Follow</Button>
</Row>
</Card>
</Row>

Switch between loading and loaded

Render the real components while the data loads and pass the loading state to skeleton. A text with no data yet draws one bar 12 characters long, so the components need no filler text. The placeholders take the size and lines of the finished content, so nothing moves when it arrives.

const [loading, setLoading] = useState(true);
const user = loading ? undefined : { name: 'Biscuit', role: 'Head of snacks' };
return (
<Col>
<Label row>
<Checkbox checked={loading} onChange={() => setLoading(!loading)}/>
Loading
</Label>
<Card skeleton={loading} className="w-80">
<Row>
<Avatar src={user ? photo : undefined} name={user?.name}/>
<Col noGap>
<Title sm>{user?.name}</Title>
<Text sm secondary>{user?.role}</Text>
</Col>
</Row>
<Button filled>Follow</Button>
</Card>
</Col>
);

For a bar closer to the loaded length, pass placeholder text of about that length, such as {user?.role ?? 'Head of snacks'}. It is never shown or read while skeleton is on, and two sentences of filler give a two-line bar where a two-line bio goes.

Bars for text that has not loaded yet

A text with nothing in it yet draws one bar 12 characters long and one line tall, at the text's own size. An empty Button, Badge, Chip, Code, Kbd or Mark takes the room of a 6-character label, at its usual height. This covers a Text, Title, Link, ListItem, Blockquote, table cell, NavLink, MenuItem or BreadcrumbItem whose data is still undefined:

<Card skeleton className="w-80">
<Row>
<Avatar/>
<Col noGap>
<Title sm/>
<Text sm secondary/>
</Col>
</Row>
<Text/>
<Row>
<Badge success/>
<Button filled/>
</Row>
</Card>

Set --skeleton-text-width to change the length of those text bars, and --skeleton-label-width for the empty boxes. A Badge with dot and no text stays a dot.

.loading-list {
--skeleton-text-width: 100%;
}

What each component turns into

ComponentPlaceholder
Text, titles, links, labels, list items, table cells, NavLink and MenuItem textA bar per line, as long as the line, at the text's own size
Button, IconButton, Badge, Chip, Code, Kbd, MarkA solid shape of the same size and corners
Input, Textarea, Select, Checkbox, Radio, Switch, Progress, SpinnerA solid shape of the control, without its value, check mark, sections or chevron
Avatar, Img, Icon and bare <svg> iconsA solid shape of the same size
Card, Row, Col, Stack, Section, Table, Field, Alert and other containersTheir own surface and border stay; their content turns into placeholders

Put text in a component of its own, such as Text, rather than straight inside a Row, Col, Card, Stack, Section or Container. Safari draws a bar over text that sits straight in one of those layout containers as a thin line, while Chrome and Firefox draw the full bar.

All placeholders share one fill, so a bar that runs over a shape adds nothing to it. A component that carries skeleton itself turns into a placeholder in the same way, whatever it sits in:

Paid

Last synced a minute ago

<Row flexWrap>
<Button skeleton>Save changes</Button>
<Badge skeleton>Paid</Badge>
<Input skeleton aria-label="Email" placeholder="you@example.com" wFit/>
<Switch skeleton aria-label="Notifications" defaultChecked/>
<Text skeleton>Last synced a minute ago</Text>
</Row>

Lists, tables and navigation

The prop works the same on any container, so a table or a sidebar keeps its rows, lines and active item while the bars stand in for the text.

NameRole
BiscuitHead of snacks
PepperNight watch
<Row tabletStack itemsStart>
<Col skeleton noGap className="w-56">
<NavLink href="#home" active>Dashboard</NavLink>
<NavLink href="#projects">Projects</NavLink>
<NavLink href="#settings">Settings</NavLink>
</Col>
<Table skeleton>
<Thead><Tr><Th>Name</Th><Th>Role</Th></Tr></Thead>
<Tbody>
<Tr><Td>Biscuit</Td><Td>Head of snacks</Td></Tr>
<Tr><Td>Pepper</Td><Td>Night watch</Td></Tr>
</Tbody>
</Table>
</Row>

The Skeleton box for areas with no component

Skeleton is a plain box. It is full width and one line of text tall at its size, from 18px at xs to 30px at xl, with corners that follow the size. Aspect props, a height or a class set its shape. Use it for a chart, a map, an embed or any block you draw yourself.

<Row itemsStart flexWrap>
<Skeleton aspectVideo className="w-64"/>
<Col className="w-64">
<Skeleton xs/>
<Skeleton/>
<Skeleton xl/>
<Skeleton className="h-16"/>
</Col>
<Skeleton pill aspectSquare className="w-12"/>
</Row>

For a component that VaneUI has, prefer the component with skeleton over a box of the same size: an Avatar keeps its exact size and shape, and the swap to the loaded content does not move the layout.

Focus, clicks and screen readers

The element with skeleton gets aria-busy="true" and the inert attribute. Nothing inside it takes focus, clicks or text selection, so a placeholder button cannot be pressed. inert also hides the placeholder from screen readers, which is right for placeholder text, so tell them about the wait in a status message outside it:

<Col>
<Text srOnly role="status">{loading ? 'Loading profile' : ''}</Text>
<Card skeleton={loading}>...</Card>
</Col>

The Skeleton box is decorative and renders aria-hidden="true".

Pulse and reduced motion

The placeholders pulse between two shades of the fill. The pulse runs on the outermost element with skeleton, so every placeholder inside it pulses in step, and the surface of the container stays still. With prefers-reduced-motion: reduce, the placeholders do not move.

Placeholder color and dark mode

The fill is a light shade of the secondary text color, mixed into the page surface, so it follows the theme: a dark subtree or a page with data-theme="dark" gets a dark fill. Set --skeleton-color to tint it:

.brand-skeletons {
--skeleton-color: var(--color-text-info);
}

Customizing

skeleton is a boolean prop like any other, so themeDefaults can turn it on for a component node, and the Skeleton box has its own skeleton node for its defaults.

<ThemeProvider themeDefaults={{ skeleton: { pill: true, sm: true } }}>
<Col className="w-64">
<Skeleton/>
<Skeleton className="w-1/2"/>
</Col>
</ThemeProvider>

Frequently asked questions

Do I need a separate skeleton layout for each page?

No. Render the page you already have with skeleton on the container that waits for data. Text that has not arrived draws a default bar, and placeholder text of the expected length draws a closer one. The placeholders keep the same sizes and positions as the loaded content, so there is one layout to maintain and the page does not jump when the data arrives.

Why is a placeholder missing?

A component that is not rendered draws nothing, as in {user && <Text>{user.bio}</Text>}. Render the component and leave its text empty while it loads, <Text>{user?.bio}</Text>, and it draws a default bar. For an area with no text at all, such as a chart, use the Skeleton box with a size or an aspect prop.

Can a part of a card stay live while the rest loads?

Put skeleton on the part that waits instead of on the card. The prop reaches only the components inside the element that carries it, so a Col skeleton inside a Card turns that column into placeholders and leaves the header and its buttons usable.

Does skeleton change the HTML that is rendered?

It adds three attributes to the element that carries it: data-skeleton, aria-busy="true" and inert. The components inside it render the same elements as before. The placeholder look comes from the stylesheet, so it also applies to server-rendered HTML before hydration.

Skeleton Props

PropCategoryDefaultDescription
aspectAuto

Aspect

The content's own ratio (aspect-ratio: auto)

aspectSquare

Aspect

Square box (aspect-ratio: 1 / 1)

aspectVideo

Aspect

Video box (aspect-ratio: 16 / 9)

margin

Margin

Enable margin on all sides

marginB

Margin

Enable only bottom margin

marginT

Margin

Enable only top margin

marginX

Margin

Enable only horizontal (inline) margin

marginY

Margin

Enable only vertical (block) margin

noMargin

Margin

Disable margin (reset to 0)

pill

Shape

Fully rounded corners (circular)

rounded

Shape

✓

Medium rounded corners (default)

sharp

Shape

No rounded corners (square)

noShrink

Shrink

Prevent the flex item from shrinking below its content size (= shrink-0)

lg

Size

Large size

md

Size

✓

Medium size (default)

sm

Size

Small size

xl

Size

Extra large size

xs

Size

Extra small size

skeleton

Skeleton

✓

Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too

Layout & utility props (gap, padding, hide, items, justify, ...)

Documented on Common Props.

PropCategoryDefaultDescription
block

Display

✓

Block display - takes full width, new line

contents

Display

Contents display - element's box is removed, children display as if parent didn't exist

flex

Display

Flex display - flexbox container

grid

Display

Grid display - CSS grid container

hidden

Display

Hidden display - element is not visible

inline

Display

Inline display - flows with text

inlineBlock

Display

Inline-block display - inline but with block properties

inlineFlex

Display

Inline-flex display - inline flexbox container

inlineGrid

Display

Inline-grid display - inline grid container

table

Display

Table display - behaves like table element

tableCell

Display

Table-cell display - behaves like td element

hAuto

Height

Set height to auto

hFit

Height

Set height to fit-content

hFull

Height

Set height to 100%

hScreen

Height

Set height to 100vh (viewport height), removes max-height constraint

desktopHide

Hide

Hide element on desktop devices and below (max-desktop: 80rem)

mobileHide

Hide

Hide element on mobile devices and below (max-mobile: 48rem)

tabletHide

Hide

Hide element on tablet devices and below (max-tablet: 64rem)

itemsBaseline

Items

Align items to baseline

itemsCenter

Items

Align items to center

itemsEnd

Items

Align items to end (bottom/right)

itemsStart

Items

Align items to start (top/left)

itemsStretch

Items

Stretch items to fill container

justifyAround

Justify

Distribute items with space around them

justifyBaseline

Justify

Align items along their baseline on main axis

justifyBetween

Justify

Distribute items with space between them

justifyCenter

Justify

Center items along the main axis

justifyEnd

Justify

Pack items toward the end of the main axis

justifyEvenly

Justify

Distribute items with equal space around them

justifyStart

Justify

Pack items toward the start of the main axis

justifyStretch

Justify

Stretch items to fill the main axis

overflowAuto

Overflow

Auto overflow - show scrollbars if needed

overflowClip

Overflow

Clip overflow - hard clip without scrollbars

overflowHidden

Overflow

Hidden overflow - clip content without scrollbars

overflowScroll

Overflow

Scroll overflow - always show scrollbars

overflowVisible

Overflow

Visible overflow - content extends beyond bounds

overflowXAuto

Overflow

Auto overflow on X-axis only

overflowXClip

Overflow

Clip overflow on X-axis only

overflowXHidden

Overflow

Hidden overflow on X-axis only

overflowXScroll

Overflow

Scroll overflow on X-axis only

overflowXVisible

Overflow

Visible overflow on X-axis only

overflowYAuto

Overflow

Auto overflow on Y-axis only

overflowYClip

Overflow

Clip overflow on Y-axis only

overflowYHidden

Overflow

Hidden overflow on Y-axis only

overflowYScroll

Overflow

Scroll overflow on Y-axis only

overflowYVisible

Overflow

Visible overflow on Y-axis only

absolute

Position

Absolute positioning

fixed

Position

Fixed positioning

relative

Position

Relative positioning

static

Position

Static positioning

sticky

Position

Sticky positioning at the top edge; set --sticky-top to stick below a fixed header

desktopWFull

Responsive Width

Set width to 100% on desktop and below, below 1280px (max-desktop: 80rem)

mobileWFull

Responsive Width

Set width to 100% on mobile, below 768px (max-mobile: 48rem)

tabletWFull

Responsive Width

Set width to 100% on tablet and below, below 1024px (max-tablet: 64rem)

desktopShow

Show

Show element only on desktop and below, below 1280px (hidden from 80rem up)

mobileShow

Show

Show element only on mobile, below 768px (hidden from 48rem up)

tabletShow

Show

Show element only on tablet and below, below 1024px (hidden from 64rem up)

wAuto

Width

Set width to auto

wFit

Width

Set width to fit-content

wFull

Width

✓

Set width to 100%

wScreen

Width

Set width to 100vw (viewport width), removes max-width constraint