--- title: Image description: >- The `Image` component renders an image for the Storefront API's [Image object](https://shopify.dev/api/storefront/reference/common-objects/image) by using the `data` prop. You can [customize this component](https://shopify.dev/api/hydrogen/components#customizing-hydrogen-components) using passthrough props. Images default to being responsive automativally (`width: 100%, height: auto`), and expect an `aspectRatio` prop, which ensures your image doesn't create any layout shift. For fixed-size images, you can set `width` to an exact value, and a `srcSet` with 1x, 2x, and 3x DPI variants will automatically be generated for you. api_version: 2023-04 api_name: hydrogen-react source_url: html: 'https://shopify.dev/docs/api/hydrogen-react/2023-04/components/image' md: 'https://shopify.dev/docs/api/hydrogen-react/2023-04/components/image.md' --- # Image The `Image` component renders an image for the Storefront API's [Image object](https://shopify.dev/api/storefront/reference/common-objects/image) by using the `data` prop. You can [customize this component](https://shopify.dev/api/hydrogen/components#customizing-hydrogen-components) using passthrough props. Images default to being responsive automativally (`width: 100%, height: auto`), and expect an `aspectRatio` prop, which ensures your image doesn't create any layout shift. For fixed-size images, you can set `width` to an exact value, and a `srcSet` with 1x, 2x, and 3x DPI variants will automatically be generated for you. ## Props * aspectRatio string The aspect ratio of the image, in the format of `width/height`. * crop Crop Default: \`center\` The crop position of the image. * data PartialObjectDeep\ Data mapping to the [Storefront API `Image`](https://shopify.dev/docs/api/storefront/2023-04/objects/Image) object. Must be an Image object. * loader Loader A function that returns a URL string for an image. * srcSetOptions SrcSetOptions An optional prop you can use to change the default srcSet generation behaviour * loaderOptions ShopifyLoaderOptions deprecated Deprecated Use `crop`, `width`, `height`, and `src` props, and/or `data` prop * widths (string | number)\[] deprecated Deprecated Autocalculated, use only `width` prop, or srcSetOptions ### Crop ```ts 'center' | 'top' | 'bottom' | 'left' | 'right' ``` ### Loader ```ts (params: LoaderParams) => string ``` ### LoaderParams * src The base URL of the image ```ts string ``` * width The URL param that controls width ```ts number ``` * height The URL param that controls height ```ts number ``` * crop The URL param that controls the cropping region ```ts Crop ``` ```ts { /** The base URL of the image */ src?: ImageType['url']; /** The URL param that controls width */ width?: number; /** The URL param that controls height */ height?: number; /** The URL param that controls the cropping region */ crop?: Crop; } ``` ### SrcSetOptions * intervals ```ts number ``` * startingWidth ```ts number ``` * incrementSize ```ts number ``` * placeholderWidth ```ts number ``` ```ts { intervals: number; startingWidth: number; incrementSize: number; placeholderWidth: number; } ``` ### ShopifyLoaderOptions Legacy type for backwards compatibility \* * src The base URL of the image ```ts string ``` * width The URL param that controls width ```ts string | number ``` * height The URL param that controls height ```ts string | number ``` * crop The URL param that controls the cropping region ```ts Crop ``` ```ts { /** The base URL of the image */ src?: ImageType['url']; /** The URL param that controls width */ width?: HtmlImageProps['width'] | ImageType['width']; /** The URL param that controls height */ height?: HtmlImageProps['height'] | ImageType['height']; /** The URL param that controls the cropping region */ crop?: Crop; } ``` Examples ### Examples * #### Example code ##### Description I am the default example ##### JavaScript ```jsx import {Image} from '@shopify/hydrogen-react'; // An example query const IMAGE_QUERY = `#graphql query { product { featuredImage { altText url height width } } } `; export default function ProductImage({product}) { if (!product.featuredImage) { return null; } return ( ); } ``` ##### TypeScript ```tsx import React from 'react'; import {Image} from '@shopify/hydrogen-react'; import type {Product} from '@shopify/hydrogen-react/storefront-api-types'; // An example query const IMAGE_QUERY = `#graphql query { product { featuredImage { altText url height width } } } `; export default function ProductImage({product}: {product: Product}) { if (!product.featuredImage) { return null; } return ( ); } ``` ## Related [- MediaFile](https://shopify.dev/api/hydrogen-react/components/mediafile)