VercelImage

Turn a hi-res origin image into a responsive image using Vercel's Image Optimization API.

Properties

PropertyTypeRequiredDescription
srcstringyesURL to origin image.
altstringyesAlt text (not caption) .
sizesstringnoSize hints. If not specified, it defaults to "100vw".
intrinsicWidthnumbernoOptimize generated srcset when provided.
aspectRatiostring | numbernoOverride intrinsic aspect ratio. "1 / 1" or 1.0, not 1.
loading'lazy' | 'eager'noDefaults to "lazy".
classstringnoTailwind v4 classes.

Examples

Origin image in the cloud

The default use case for VercelImage is that the origin image is hosted in the cloud:

Local origin images

If your origin image is part of your SvelteKit website’s repository, we can import it and obtain its root-relative path. VercelImage can handle root-relative paths because Vercel’s Image Optimization API supports them.

The following example renders a local origin image:

Note that VercelImage suppresses the generation of srcset while in dev mode. The browser then sees an img tag with only a src prop containing a root-relative path. This ensures that images are rendered during dev.