Using @sanity/image-url without a framework or build process
I can see why you're confused - the documentation examples assume you're using a module system with a configured Sanity client, which isn't straightforward without a build process. Let me clarify what's actually possible.
Based on the official documentation, @sanity/image-url is distributed as an NPM package designed to work in a module environment. The examples show importing it and passing a configured @sanity/client instance.
The honest answer: The @sanity/image-url library isn't officially documented for direct browser usage without a build process. The docs only cover NPM/module imports.
Your best option: Build URLs manually
The good news is you don't actually need the library! You can construct Sanity's image CDN URLs directly, which works perfectly without any build process or dependencies.
Here's how the URL structure works, based on the Image Pipeline documentation:
<!DOCTYPE html>
<html>
<head>
<title>Sanity Images Example</title>
</head>
<body>
<img id="myImage" alt="Example">
<script>
// Your project details
const projectId = 'your-project-id' // Get this from sanity.io/manage
const dataset = 'production' // Usually 'production'
// Your image reference (from your Sanity query)
// Format: image-{assetId}-{width}x{height}-{format}
const imageRef = 'image-G3i4emG6B8JnTmGoN0UjgAp8-300x450-jpg'
// Build the base URL
const baseUrl = `https://cdn.sanity.io/images/${projectId}/${dataset}/${imageRef}`
// Add transformations as query parameters
const transformedUrl = `${baseUrl}?w=600&h=400&fit=crop&auto=format`
// Use it!
document.getElementById('myImage').src = transformedUrl
</script>
</body>
</html>Available URL parameters
You can add these as query parameters to transform your images (from the image transformations docs):
w=400- Set width to 400pxh=300- Set height to 300pxfit=crop- Crop to exact dimensions (also:max,fill,clip)auto=format- Automatically serve WebP/AVIF to supported browsersq=75- Set quality (0-100)blur=50- Blur the imagerect=x,y,width,height- Crop to a specific rectangle
Example with multiple transformations:
const url = `https://cdn.sanity.io/images/${projectId}/${dataset}/${imageRef}?w=800&h=600&fit=max&auto=format&q=85`Getting the image reference from Sanity
When you query Sanity, you'll get an image reference that looks like this:
// Example image object from a GROQ query
{
"_type": "image",
"asset": {
"_ref": "image-G3i4emG6B8JnTmGoN0UjgAp8-300x450-jpg",
"_type": "reference"
}
}Use that _ref value as your imageRef in the URL construction above.
About "passing a configured sanityClient"
The documentation mentions this because the library can accept a full client object, but when building URLs manually (as shown above), you only need your projectId and dataset - no client library required!
This manual approach is actually documented in the official Image Pipeline guide and works perfectly without any build tooling or JavaScript libraries.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.