Skip to content

Image

A picture in a box of known shape, so nothing moves when it arrives: the skeleton holds its place until it loads, and if it cannot load the box says so.

import { Image, ImageSkeleton } from '@sypnia/ui/react'

On this page
  1. Shapes, a failure and a skeleton
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

Shapes, a failure and a skeleton

Drawing of hills under a sunDrawing of hills, squareDrawing of hills, shown wholeThe storefront
Code
import { Image, ImageSkeleton } from '@sypnia/ui/react';

// A box of known shape: nothing moves when the picture arrives. The last one cannot load and says so.
const art = (hue: number) => 'data:image/svg+xml;utf8,' + encodeURIComponent(
  `<svg xmlns="http://www.w3.org/2000/svg" width="1200" height="800" viewBox="0 0 1200 800"><rect width="1200" height="800" fill="hsl(${hue} 35% 88%)"/><circle cx="880" cy="250" r="130" fill="hsl(${hue} 45% 70%)"/><path d="M0 620 L320 380 L560 560 L780 420 L1200 700 L1200 800 L0 800Z" fill="hsl(${hue} 30% 62%)"/></svg>`);
export default function Shapes() {
  return (
    <div className="sy-grid">
      <Image src={art(30)} alt="Drawing of hills under a sun" />
      <Image src={art(200)} alt="Drawing of hills, square" ratio="1" />
      <Image src={art(140)} alt="Drawing of hills, shown whole" ratio="4 / 3" fit="contain" />
      <Image src="data:image/png;base64,AAAA" alt="The storefront" ratio="4 / 3" />
      <ImageSkeleton ratio="4 / 3" />
    </div>
  );
}

Skeleton

A plain warm colour
Code
import { Image, ImageSkeleton } from '@sypnia/ui/react';

// A picture and its skeleton: the same box, so nothing moves when it arrives.
export default function Skeleton() {
  return (
    <div className="sy-cols sy-cols--stack">
      <Image ratio="4 / 3" alt="A plain warm colour" src={'data:image/svg+xml;utf8,' + encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" width="400" height="300"><rect width="400" height="300" fill="hsl(30 40% 80%)"/></svg>')} />
      <ImageSkeleton ratio="4 / 3" />
    </div>
  );
}

When to use it

Use it when

  • Screenshots, product photos, covers.
  • fit="contain" when the whole picture must show.

Do not use it when

  • Icons: use Icon. Avatars: use Avatar.

For everyone

  • alt says what the picture shows; empty only for decoration.
  • A picture that fails keeps its name for screen readers.

Props

ImageTypeDefault
altrequired string
srcrequired string
fit

cover fills the box and crops; contain shows the whole picture.

"cover" | "contain" cover
lazy

Loads it only when it comes near the screen.

boolean true
ratio

Width / height: «16 / 9», «1», «4 / 3».

string 16 / 9
rounded boolean true
ImageSkeletonTypeDefault
ratio string 16 / 9
rounded boolean true
  1. Shapes, a failure and a skeleton
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms