Ir al contenido
Español

Cómo funciona

Each block is the text colour at 7% opacity (8% in dark), so it reads the same on a card and on a filled panel. The highlight is an ::after band moved with transform rather than background-position, and every block shares one global phase through a negative animation-delay, so blocks mounted at different moments still sweep together. Build the skeleton from the same rows and sizes as the real widget. SkeletonSwap keeps both layers in one grid cell while it cross-fades, so the container never collapses, and unmounts the skeleton after it has faded.

Úsalo para

  • First load of content with a predictable structure, such as lists, cards and detail pages, so people see the layout first.
  • Pull to refresh or refetching after a filter change, instead of a full-page spinner.
  • Areas that usually take more than 300ms; faster requests should show the result directly.

Busca otra opción cuando

  • Feedback for actions such as submit or save: use the loading state inside the button.
  • Content with an unpredictable structure (unknown result counts, rich text): the skeleton would differ a lot, so use a simple spinner.
  • Long tasks with exact progress, such as uploads and exports: use a progress bar or ring.

Uso

import { Skeleton, SkeletonSwap } from './Skeleton.jsx'

export function OrderCard({ order }) {
  return (
    <SkeletonSwap
      loading={!order}
      label="Loading order"
      skeleton={
        <div style={{ display: 'flex', gap: 12 }}>
          <Skeleton variant="circle" height={40} />
          <Skeleton lines={2} />
        </div>
      }
    >
      {order && <OrderDetail order={order} />}
    </SkeletonSwap>
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
Skeleton.variant'line' | 'circle' | 'rect''line'Shape: text line, round avatar, or rectangle for an image or button.
Skeleton.widthnumber | string—Width; numbers are px. line and rect default to 100%, circle to its height.
Skeleton.heightnumber | string—Height; numbers are px. line defaults to 0.75em (follows font size), circle and rect to 40px.
Skeleton.linesnumber1Number of lines (line only). With more than one, the last line shortens to 60%.
Skeleton.radiusnumber | string—Corner radius; defaults to a full pill for line, 10px for rect and a full circle for circle.
Skeleton.durationnumber1600Sweep period in ms. When omitted, follows the surrounding SkeletonSwap's shimmerDuration.
Skeleton.animatebooleantrueSweeps the highlight. When false, only the static base colour stays.
SkeletonSwap.loadingboolean—Whether it is loading. When it turns false, the skeleton fades out and the content fades in while rising.
SkeletonSwap.skeletonReactNode—The skeleton shown while loading; match the real content's size as closely as you can.
SkeletonSwap.childrenReactNode—The real content; not rendered while loading.
SkeletonSwap.shimmerDurationnumber1600Sweep period in ms for every Skeleton inside.
SkeletonSwap.labelstring'Loading'Text announced to screen readers while loading.
...restHTMLAttributes—Other attributes, such as className and style, go to the root element.

Accesibilidad

  • The container has aria-busy, so screen readers do not read half-loaded content during loading.
  • A permanent role="status" region announces “Loading” when loading starts; set label for something more specific.
  • All skeleton blocks are aria-hidden and never read as empty elements.
  • With reduced motion there is no sweep, only the static base colour, and the swap replaces the content without movement.

Movimiento

The sweep cycle is 1600ms by default (70% sweeping, 30% pause), ease-in-out, in phase across blocks. The skeleton leaves in 200ms ease-in; content enters in 360ms ease-out after 60ms, rising 8px. In the demo the bars then rise for 900ms on cubic-bezier(0.22, 1, 0.36, 1), 30ms apart, while the total counts up. Reduced motion shows static blocks and swaps without movement.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

Skeleton.jsxskeleton-shimmer.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Carga
Revelado de imagen viene con Pro. La vista previa aparece al desbloquearlo.
Cargador orbital viene con Pro. La vista previa aparece al desbloquearlo.