antlitz
Menu

Image

An image with a fallback and a load reveal.

import { Image } from "antlitz";

In a Next.js app, import from antlitz/next to render through next/image with its optimisation and layout handling.

import { Image } from "antlitz/next";

API

PropTypeDefault
altstring—
asElementType—
fallbackstring—
srcstring—

alt is required — an image with no alt text is either decorative, in which case pass an empty string deliberately, or it is missing information.

Usage

A placeholder
export function Basic() {
  return <Image src={PLACEHOLDER} alt="A placeholder" className="w-40" />;
}

Fallback

A broken sourceAn empty source
export function Fallback() {
  return (
    <div className="flex items-start gap-4">
      <Image
        src="/does-not-exist.jpg"
        fallback={PLACEHOLDER}
        alt="A broken source"
        className="w-40"
      />
      <Image
        src=""
        fallback={PLACEHOLDER}
        alt="An empty source"
        className="w-40"
      />
    </div>
  );
}

Both of these images point at sources that cannot resolve. An empty or whitespace-only src takes the fallback without waiting for a failed request.

Loading

Images carry a muted background while they load, so layout does not flash white, and fade in once decoded. Images already in the browser cache skip the animation — the reveal only runs when there was actually a wait.

The reveal is the one animation in the package gated behind motion-safe. It scales and blurs the image, which is movement, and it is decorative. Skeleton's pulse only fades, which is not movement; the Spinner moves, but it conveys state.

Next.js

Through antlitz/next, src also takes a static import. The width, height and blur placeholder come from the file, as they do with next/image; pass only a width and the height follows the image's proportions.

import { Image } from "antlitz/next";
import hero from "./hero.jpg";

<Image src={hero} alt="The studio at dusk" placeholder="blur" />;

A local path renders through next/image. An external URL renders a plain img by default, because next/image refuses any host missing from images.remotePatterns and antlitz cannot see your config. Once the host is listed, set optimize to send the URL through next/image as well.

<Image
  src="https://cdn.example.com/a.jpg"
  alt="…"
  width={800}
  height={600}
  optimize
/>

The plain img keeps the next/image props that still mean something: fill positions it absolutely over its container, and priority or preload loads it eagerly at high fetch priority. Props that only next/image understands — quality, placeholder, blurDataURL, loader — are dropped rather than written to the element.