Alt text
- Sanity
- No built-in field
- You
- Add the field, require it where it matters, render it
Add an alt text field to Sanity images, keep hotspot and crop working, and serve sized, modern-format images with the image URL parameters.
Sanity's image type does not include an alt text field, so add one in the schema and render it in your <img>. Request images through the CDN with w, fit=max and auto=format instead of the original file, and build URLs with @sanity/image-url so the editor's crop and hotspot are respected. Name files descriptively with a vanity filename.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
fields property adds optional fields to the image record, such as caption and attribution. The same mechanism carries alt text. The docs' own example reads image.alt and notes that "Depending on your schema, you may need to adjust the alt text location", so the field is yours to define.<img
src={urlFor(image).width(800).url()}
srcSet={[
`${urlFor(image).width(400).url()} 400w`,
`${urlFor(image).width(800).url()} 800w`,
`${urlFor(image).width(1200).url()} 1200w`,
].join(', ')}
sizes="(max-width: 600px) 400px, (max-width: 1200px) 800px, 1200px"
alt={image.alt || ''}
/>Pass the whole image field, not just the asset, to urlFor: Sanity's presenting-images guide says it needs the crop and hotspot data. Google recommends always specifying a fallback src for responsive images because some browsers and crawlers do not understand srcset, which the snippet does.
defineField({
name: 'image',
type: 'image',
options: { hotspot: true },
fields: [
defineField({
name: 'alt',
type: 'string',
title: 'Alternative text',
description: 'Describe what the image shows for someone who cannot see it.',
}),
],
})auto=format returns the most optimized format the browser's Accept header allowshotspot is enabled@sanity/image-url so they applyimages arrayw, hfit=maxauto=formatAccept headerfm=webpjpg, pjpg, png or webp; avif is not valid for fmqdprw and h may cause performance issues or timeouts. &h=200 is correct and &h=200.0 may be problematic, including for calculated values.https://cdn.sanity.io/images/<project>/<dataset>/<asset-id>-1600x900.jpg/dalmatian-puppy-playing-fetch.jpg?w=800&fit=max&auto=formatalt="puppy" is better, and alt="Dalmatian puppy playing fetch" is best. A keyword-stuffed alt is the bad example. Google also says to avoid generic filenames like image1.jpg, and that short descriptive ones such as my-new-black-kitten.jpg give light clues. That is the case for the vanity file name above.alt when the field is blank, so decide per image whether that is acceptable and do not let it hide a missing description.alt for content images, so an editor cannot publish without it.Run Sanity's own test, with your real URL: curl -sS -I -H 'accept: image/avif,image/webp,image/*' 'https://cdn.sanity.io/images/:projectId/:dataset/:filename?auto=format' | grep 'content-type:'. The docs say expect image/webp first and image/avif after waiting around 30 seconds.
In DevTools Elements, confirm the <img> has a non-empty alt where it should, a src fallback and srcset URLs with w values.
Filter by Img and confirm the bytes transferred match the displayed size, not the original upload.
Move the hotspot in Studio, rebuild and check the image still frames the subject at each ratio you render.
2 questions people ask next, answered from the sources on this page.
No. The image type lets you add custom fields, so you define an alt string on the image and render it in your markup.
Use auto=format for browsers so the response follows the Accept header. Use fm only where you need a fixed format, and note it does not accept avif.
Run the free audit, then approve the fixes. Every change can be undone.