Skip to Content
CodeUI

Skeleton

@codeui/styles v0.3.0

A placeholder shape in plain HTML, shown while content loads.

Load @codeui/styles/skeleton.css, or all.css. The Solid component is documented in Skeleton.

Demo

skeleton/basic.html
<section class="cui-stack" data-gap="2" aria-label="Snippet preview" aria-busy="true">  <div class="cui-skeleton" data-cui="skeleton" data-visible data-animate aria-hidden="true" style="width: 60%; height: 1rem"></div>  <div class="cui-skeleton" data-cui="skeleton" data-visible data-animate aria-hidden="true" style="width: 100%; height: 4rem"></div></section>

Markup

PartElementClassdata-cui
Rootdivcui-skeletonskeleton

The root is a block with a small radius. Set its size with your own width and height. Without a height, it takes the height of its children.

AttributeValuesDefault
data-visiblePresenceOff
data-animatePresenceOff
data-circlePresenceOff

Variants

Shapes

skeleton/shapes.html
<section class="cui-stack" data-gap="3" aria-label="Snippet details" aria-busy="true">  <div class="cui-stack" data-direction="row" data-gap="3" data-align="center">    <div class="cui-skeleton" data-cui="skeleton" data-visible data-animate data-circle aria-hidden="true" style="width: var(--cui-space-10); height: var(--cui-space-10); flex-shrink: 0"></div>    <div class="cui-stack" data-gap="2" style="flex: 1">      <div class="cui-skeleton" data-cui="skeleton" data-visible data-animate aria-hidden="true" style="width: 40%; height: 0.875rem"></div>      <div class="cui-skeleton" data-cui="skeleton" data-visible data-animate aria-hidden="true" style="width: 25%; height: 0.75rem"></div>    </div>  </div>  <div class="cui-skeleton" data-cui="skeleton" data-visible data-animate aria-hidden="true" style="width: 100%; height: 4rem; border-radius: var(--cui-radius-md)"></div></section>

data-circle uses a full radius. Give a circle equal width and height. For another radius, set border-radius yourself. Match the dimensions of the content that will load, so the layout does not move.

Animation

skeleton/animation.html
<section class="cui-stack" data-gap="3" aria-label="Snippet previews" aria-busy="true">  <div class="cui-skeleton" data-cui="skeleton" data-visible data-animate aria-hidden="true" style="height: 2rem"></div>  <div class="cui-skeleton" data-cui="skeleton" data-visible aria-hidden="true" style="height: 2rem"></div></section>

data-animate pulses the opacity of a visible placeholder. The first bar pulses and the second is static. The pulse is a CSS animation, so it runs without a script.

States

Visible

skeleton/revealed.html
<div class="cui-stack" data-direction="row" data-gap="6" data-wrap="true">  <section class="cui-stack" data-gap="1" aria-label="Loading snippet title" aria-busy="true" style="min-width: 200px">    <span class="cui-text" data-cui="text" data-size="xs" data-tone="hint">data-visible</span>    <div class="cui-skeleton" data-cui="skeleton" data-visible data-animate aria-hidden="true">      <span class="cui-text" data-cui="text">Gradient editor.tsx</span>    </div>  </section>  <section class="cui-stack" data-gap="1" aria-label="Snippet title" style="min-width: 200px">    <span class="cui-text" data-cui="text" data-size="xs" data-tone="hint">No data-visible</span>    <div class="cui-skeleton" data-cui="skeleton">      <span class="cui-text" data-cui="text">Gradient editor.tsx</span>    </div>  </section></div>

data-visible draws the placeholder. It fills the root, makes the text transparent, hides the children, and blocks pointer events and selection. Without it, the root is a plain block and its children show. Keep the children in the DOM and remove data-visible when the content is ready.

Reduced motion

Under prefers-reduced-motion: reduce, the pulse stops and the placeholder stays visible.

What you supply

  • Setting and removing data-visible when content loads.
  • aria-hidden="true" on a visible placeholder, and aria-busy="true" on the region that is loading.
  • Width and height for each placeholder.

Helper

import "@codeui/styles/skeleton.css";
import { applyStyleProps } from "@codeui/styles";
import { skeletonStyleProps } from "@codeui/styles/skeleton";

const title = document.querySelector(".snippet-title")!;
applyStyleProps(title, skeletonStyleProps({ animate: true, class: "snippet-title" }));
// class="cui-skeleton snippet-title" data-cui="skeleton" data-animate=""
title.toggleAttribute("data-visible", true);

The helper does not emit data-visible, because it is state, not appearance.

On this page