Responsive Grid Example
Learn how to use sanity-image in responsive layouts with proper sizing attributes.3-Column Grid Layout
This example shows a 3-column grid that fills the viewport until it reaches a maximum of 1,200px wide. Each column is 390px at most on desktop:Fixed Height Grid with Cover Mode
If you need images to match in height, usecover mode. This produces images with a 3:2 aspect ratio that fill the column width:
Without a
hotspot value, the image will be cropped based on what Sanity thinks is the most interesting part using crop=entropy. Pass a hotspot value to override this behavior.Understanding the sizes Attribute
The sizes attribute tells the browser how big the image will be at different viewport sizes:
(min-width: 1240px) 390px- At viewports 1240px and wider, the image is 390pxcalc((100vw - 40px - 30px) / 3)- Below 1240px, calculate one-third of the viewport width minus padding (40px) and gaps (30px)