Gathering detailed insights and metrics for gatsby-plugin-sanity-image-alt
Gathering detailed insights and metrics for gatsby-plugin-sanity-image-alt
Gathering detailed insights and metrics for gatsby-plugin-sanity-image-alt
Gathering detailed insights and metrics for gatsby-plugin-sanity-image-alt
Gatsby plugin providing easy responsive behavior for Sanity-hosted images
npm install gatsby-plugin-sanity-image-alt
Typescript
Module System
Node Version
NPM Version
54.1
Supply Chain
88.4
Quality
71.8
Maintenance
100
Vulnerability
80.6
License
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
38 Stars
89 Commits
12 Forks
7 Watchers
2 Branches
3 Contributors
Updated on Jun 30, 2025
Latest Version
0.1.12
Package Id
gatsby-plugin-sanity-image-alt@0.1.12
Unpacked Size
70.16 kB
Size
20.06 kB
File Count
6
NPM Version
6.14.8
Node Version
12.19.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
The well-considered marriage between Sanity’s image assets and Gatsby you’ve been looking for.
<img>
tag, no nested DOM structure to mess withsrcSet
automatically based on the width
you specify in your
component code (meaning you can change it on the fly!)object-position
in case you need itsrcSet
entries that are larger than
the source dimensions when appropriate (follows Sanity’s image-url parameters)1yarn add gatsby-plugin-sanity-image
If this is your first time adding a Gatsby plugin, be sure to read this guide first—the below is a shorthand notation.
Know what y’er doin’? Here’s the copy pasta:
1{ 2 resolve: "gatsby-plugin-sanity-image", 3 options: { 4 // Sanity project info (required) 5 projectId: "abcd1234", 6 dataset: "production", 7 8 // Additional params to include with every image. 9 // This is optional and the default is shown 10 // below—if you like what you see, don’t set it. 11 defaultImageConfig: { 12 quality: 75, 13 fit: "max", 14 auto: "format", 15 }, 16 }, 17}
Don’t forget to restart gatsby develop
after you update your
gatsby-config.js
!
SanityImage
componentimg
tag! 🤯😇This plugin includes two GraphQL fragments that will fetch the fields needed for display from any Sanity image asset. You do not have to use them, but they are convenient and help keep you away from confusing bugs.
In most cases, you'll want to use the ImageWithPreview
fragment:
1export const query = graphql` 2 { 3 sanitySomeDocument { 4 yourImageField { 5 ...ImageWithPreview 6 } 7 } 8 } 9`
This will retrieve the asset
, hotspot
, and crop
fields and includes a
low-quality image preview that will be shown while the full image is loading.
If you have an image that you do NOT want to use the preview image for, you can
opt to use the simpler Image
fragment instead. This has all of the same fields
with the exception of the preview. This will keep your HTML files a bit lighter,
but you may wind up with more cumulative layout shift as the browser fetches the
image dimensions and evaluates your styles.
Note: If you are using an SVG image, you probably do not want to fetch the
preview since it’ll get thrown away—the SanityImage
component aborts early on
SVG images to avoid generating meaningless srcSet
data that reduces cache
efficiency.
SanityImage
componentThe data you fetched from GraphQL should be an object that you can expand
straight into the SanityImage
component and just work. If you used the
ImageWithPreview
fragment, SanityImage
will do the right thing
automatically.
1import SanityImage from "gatsby-plugin-sanity-image" 2 3const YourComponent = ({ yourImageFieldData }) => 4 <SanityImage {...yourImageFieldData} width={300} alt="Sweet Christmas!">
This renders an image tag like the following:
1<!-- 2 Using {baseUrl} below to refer to a string with this format: 3 https://cdn.sanity.io/images/{projectId}/{dataset}/{imageId}?w=300&h=600&q=75&fit=max&auto=format 4 --> 5<img 6 src="{baseUrl}" 7 srcset=" 8 {baseUrl}&dpr=0.5 150w, 9 {baseUrl}&dpr=0.75 225w, 10 {baseUrl}&dpr=1 300w, 11 {baseUrl}&dpr=1.5 450w, 12 {baseUrl}&dpr=2 600w 13 " 14 loading="lazy" 15 alt="Sweet Christmas!" 16 class="css-1jku2jm-SanityImage" 17/>
Note that SanityImage
is not doing anything to style your image based on the
width or height you provide (aside from setting a class with object-position
set, should you choose to use it). In practice, it's rare that these values
align consistently with a particular layout, and library control of this makes
it difficult to predict the output given a particular input.
Instead you can style the resulting img
tag just like any other element.
SanityImage
will pass through className
and style
props, and it makes no
assumptions about your image presentation.
SanityImage
is relying on browser-native deferred image loading. This
generally works fine in browsers that support it, but there are situations where
the unloaded image is hidden or covered, resulting in the full image never
loading.
If this happens, you can override the styles set on the full-size image using
the img[data-loading]
selector. This image sits immediately adjacent to the
spaceball image and has the following default styles while loading:
1position: absolute; 2width: 10px !important; /* must be > 4px to be lazy loaded */ 3height: 10px !important; /* must be > 4px to be lazy loaded */ 4opacity: 0; 5zindex: -10; 6pointerevents: none; 7userselect: none;
width
the uploaded image width is used.sizes
attribute to steer browsers to select
the most appropriate image from the srcSet
based on the viewport widthimg[data-lqip]
should you want to style it differentlyThis project is licensed under the Mozilla Public License 2.0, which is a copyleft license with a share-alike provision. Please contribute meaningful improvements back to the open-source community, either via direct contribution or by releasing a separate library!
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
4 existing vulnerabilities detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/22 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More