mode prop controls how SanityImage handles aspect ratio changes when you specify both width and height. Understanding the difference between cover and contain is essential for getting the exact image behavior you need.
The Two Modes
Contain Mode (Default)
Contain mode treats the dimensions you provide as boundaries, resizing the image to fit inside of them. The output image will match the aspect ratio of the original image—no cropping will occur.Cover Mode
Cover mode treats the dimensions you provide as a container, resizing the image to completely fill the dimensions. The output image will match the aspect ratio of the dimensions you provide.Choosing the Right Mode
Use contain when:- You want to preserve the full image without any cropping
- The image might have a different aspect ratio than the display area
- You are displaying photos where every part of the image matters
- You need the image to fill a specific area completely
- Some cropping is acceptable
- You are creating thumbnails or hero images with fixed dimensions