logo dile-components dile-components

dile-skeleton

Web Component that draws a placeholder block with the approximate shape and size of content that is still loading. Combine several blocks with your own layout to sketch list rows, cards or panels, and reserve their space so the page does not jump when the real content arrives.

It only draws: it does not fetch data nor decide when loading ends. To swap the skeleton for the real content and announce the loading state, wrap it in a dile-skeleton-loader. For blocking operations or measurable progress, use a spinner or a progress bar instead.

Installation

npm i @dile/ui

Usage

Import the component.

import '@dile/ui/components/skeleton/skeleton.js';

Use the component.

<dile-skeleton lines="3"></dile-skeleton>
<dile-skeleton shape="circle" width="48px"></dile-skeleton>
<dile-skeleton shape="rect" height="160px"></dile-skeleton>

Properties

Property Type Default Description
shape String "text" Shape of the block: text (one or more lines), circle (avatars, icons), rect (images, media) or rounded (cards, panels, buttons). Unknown values fall back to text.
lines Number 1 Number of lines of the text shape. When it is greater than 1, the last line is shorter.
width String "" CSS width of the block (200px, 50%...). For circle, it also sets the height when height is empty. By default the block takes the full width (circle: 40px).
height String "" CSS height of the block. For text, the height of each line.
static Boolean false Disables the shine animation.

CSS Custom Properties

Custom property Description Default
--dile-skeleton-color Base color of the blocks --dile-on-background-color at 12%, or gray at 12%
--dile-skeleton-highlight-color Color of the moving shine rgba(255, 255, 255, 0.35)
--dile-skeleton-animation-duration Duration of one shine cycle 1.5s
--dile-skeleton-animation Shine animation. none makes every skeleton below an element static dile-skeleton-shine 1.5s ease-in-out infinite
--dile-skeleton-border-radius Border radius of the text and rect shapes 4px
--dile-skeleton-rounded-border-radius Border radius of the rounded shape 12px
--dile-skeleton-text-height Height of each line of the text shape 0.9em
--dile-skeleton-line-gap Space between lines 0.6em
--dile-skeleton-last-line-width Width of the last line when there are several 60%
--dile-skeleton-circle-size Default diameter of the circle shape 40px
--dile-skeleton-rect-height Default height of the rect and rounded shapes 120px

CSS Parts

Accessibility

dile-skeleton demos

Shapes

<script type="module">
  import '@dile/ui/components/skeleton/skeleton.js';
</script>
<dile-skeleton lines="3"></dile-skeleton>
<div style="display: flex; gap: 1rem; align-items: center; margin-top: 1rem;">
  <dile-skeleton shape="circle"></dile-skeleton>
  <dile-skeleton shape="rect" width="160px" height="90px"></dile-skeleton>
  <dile-skeleton shape="rounded" width="160px" height="90px"></dile-skeleton>
</div>

List rows

Compose blocks with your own layout. Here the text block grows with flex: 1.

<div style="display: flex; flex-direction: column; gap: 1rem;">
  <div style="display: flex; gap: 1rem; align-items: center;">
    <dile-skeleton shape="circle"></dile-skeleton>
    <dile-skeleton lines="2" style="flex: 1;"></dile-skeleton>
  </div>
  <div style="display: flex; gap: 1rem; align-items: center;">
    <dile-skeleton shape="circle"></dile-skeleton>
    <dile-skeleton lines="2" style="flex: 1;"></dile-skeleton>
  </div>
</div>

Card

<div style="width: 280px; padding: 1rem; border: 1px solid #ccc; border-radius: 12px; display: flex; flex-direction: column; gap: 0.8rem;">
  <dile-skeleton shape="rect" height="140px"></dile-skeleton>
  <dile-skeleton width="70%" height="1.3em"></dile-skeleton>
  <dile-skeleton lines="3"></dile-skeleton>
</div>

Static

<dile-skeleton lines="2" static></dile-skeleton>

Styled

<style>
  .styled-skeleton {
    --dile-skeleton-color: #d7ecf3;
    --dile-skeleton-highlight-color: rgba(255, 255, 255, 0.8);
    --dile-skeleton-animation-duration: 0.9s;
    --dile-skeleton-border-radius: 20px;
    --dile-skeleton-text-height: 1.1em;
  }
</style>
<dile-skeleton class="styled-skeleton" lines="3"></dile-skeleton>