
Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag storeYou can use a custom image as an icon in Sanity Studio by returning a React component (including an <img> tag) from the prepare function in your schema's preview configuration. The media property accepts React components, not just image field references.
Here's how to use a custom image as an icon:
If you want to use an image file from your project (like from a public or static folder):
export default {
name: 'myDocument',
type: 'document',
fields: [...],
preview: {
select: {
title: 'title',
},
prepare({ title }) {
return {
title: title,
media: <img src="/path/to/your/image.png" alt="Custom icon" style={{width: '100%', height: '100%', objectFit: 'cover'}} />
}
}
}
}preview: {
select: {
title: 'title',
},
prepare({ title }) {
return {
title: title,
media: <img src="https://example.com/icon.png" alt="Custom icon" />
}
}
}If you want to use an image that's stored in the document itself, you can reference it directly in the select object without needing a custom component:
preview: {
select: {
title: 'title',
media: 'customIcon' // Reference to an image field in your schema
}
}media property in the prepare function accepts any React component, so you can render custom JSX including <img> tags, SVGs, or even styled componentspublic folder (or equivalent static folder depending on your setup) so they're accessible at runtimeYou can find more details in the Sanity documentation on rendering React components in previews.
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.
Content operations
Content backend


The only platform powering content operations
By Industry


Tecovas strengthens their customer connections
Build and Share

Grab your gear: The official Sanity swag store
Read Grab your gear: The official Sanity swag store