Skip to main content

Image

The image component embeds images within the interface with control over presentation and loading behavior. Use image to visually illustrate concepts, showcase products, display user content, or support tasks and interactions with visual context.

Image components support responsive sizing, alt text for accessibility, aspect ratio control, and loading states for progressive enhancement. For small preview images in lists or tables, use product thumbnail.

Images must load from an external URL (inline data URIs aren't supported), and cross-origin images need proper CORS headers from the host. A basic placeholder shows while loading — there's no built-in loading skeleton or progressive loading.

Support
Targets (29)

Configure the following properties on the image component.

Anchor to accessibilityRole
accessibilityRole
'img' | 'none' | 'presentation'
Default: 'img'

Sets the semantic meaning of the image content. When set, the role will be used by assistive technologies to help users navigate the page.

  • 'img': Identifies the element as an image that conveys meaningful information to users.
  • 'none': Completely hides the element and its content from assistive technologies.
  • 'presentation': Removes semantic meaning, making the image purely decorative and ignored by screen readers.
string
Default: ''

Alternative text that describes the image for accessibility.

Provides a text description of the image for users with assistive technology and serves as a fallback when the image fails to load. A well-written description enables people with visual impairments to understand non-text content.

When a screen reader encounters an image, it reads this description aloud. When an image fails to load, this text displays on screen, helping all users understand what content was intended.

Learn more about writing effective alt text and the alt attribute.

Anchor to aspectRatio
aspectRatio
`${number}${optionalSpace}/${optionalSpace}${number}` | `${number}`
Default: '1/1'

The aspect ratio of the image.

The rendering of the image will depend on the inlineSize value:

  • inlineSize="fill": the aspect ratio will be respected and the image will take the necessary space.
  • inlineSize="auto": the image will not render until it has loaded and the aspect ratio will be ignored.

Learn more about the aspect-ratio property.

Anchor to border
border

A shorthand for setting the border around the image. Accepts a size keyword alone (for example, 'base'), a size and color (for example, 'base base'), or a size, color, and style (for example, 'base base solid'). Use 'none' to remove the border.

Anchor to borderRadius
borderRadius
<Extract<$1['borderRadius'], 'none' | 'small-100' | 'small' | 'base' | 'large' | 'large-100' | 'max'>>
Default: 'none'

The radius of the border corners around the image. You can use a single value to apply the same radius to all corners, or use the 1-to-4-value syntax to control individual corners.

Anchor to borderStyle
borderStyle
<> | ""
Default: '' - meaning no override

Controls the visual style of the border on all sides, such as solid, dashed, or dotted.

When set, this overrides the style value specified in the border property.

Supports 1-to-4-value syntax for specifying different styles per side:

  • One value: applies to all sides
  • Two values: applies to block sides (top/bottom) and inline sides (left/right) respectively
  • Three values: applies to block-start (top), inline sides (left/right), and block-end (bottom) respectively
  • Four values: applies to block-start (top), inline-end (right), block-end (bottom), and inline-start (left) respectively
Anchor to borderWidth
borderWidth
<> | ''

The width of the border around the image. You can use a single value to apply the same width to all sides, or use the 1-to-4-value syntax to control individual sides. When set, this overrides the width value specified in the border shorthand.

string

A unique identifier for the element. Use this to reference the element in JavaScript, link labels to form controls, or target specific elements for styling or scripting.

Anchor to inlineSize
inlineSize
'fill' | 'auto'
Default: 'fill'

The inline width (horizontal size) of the image.

  • 'fill': The image takes up 100% of the available inline space.
  • 'auto': The image is displayed at its natural size.

Learn more about the width attribute.

Anchor to loading
loading
'eager' | 'lazy'
Default: 'eager'

Determines the loading behavior of the image:

  • 'eager': Immediately loads the image, irrespective of its position within the visible viewport.
  • 'lazy': Delays loading the image until it approaches a specified distance from the viewport.

Learn more about the loading attribute.

Anchor to objectFit
objectFit
'contain' | 'cover'
Default: 'contain'

How the image should be resized to fit its container. The image is positioned in the center of the container. Learn more about the object-fit property.

  • 'contain': Fits the entire image within the container, preserving aspect ratio. May leave empty space.
  • 'cover': Fills the container while preserving aspect ratio, cropping the image if needed.
Anchor to sizes
sizes
string

A set of media conditions and their corresponding sizes. Learn more about the sizes attribute.

string

The image source (either a remote URL or a local file resource).

When the image is loading or no src is provided, a placeholder is rendered. Learn more about the src attribute.

Anchor to srcSet
srcSet
string

A set of image sources and their width or pixel density descriptors. Learn more about the srcset attribute. This overrides the src property.


Anchor to Display a product imageDisplay a product image

Display a product image with controlled sizing and rounded corners. This example uses aspectRatio, objectFit="cover", and borderRadius to fit and style an image within a fixed container.

Display a product image

A rendered example of the image component

html

<s-box inlineSize="200px">
<s-image
src="https://cdn.shopify.com/static/sample-product/House-Plant1.png"
alt="Indoor plant product photo"
aspectRatio="1/1"
objectFit="cover"
borderRadius="base"
inlineSize="fill"
></s-image>
</s-box>

Control image proportions with a fixed aspect ratio. This example displays a 16:9 image that scales to fill its container using objectFit="cover", with lazy loading for performance.

html

<s-image
src="https://cdn.shopify.com/static/sample-product/House-Plant1.png"
alt="Featured product banner"
aspectRatio="16/9"
inlineSize="fill"
objectFit="cover"
loading="lazy"
></s-image>

Add visual emphasis with border styling. This example displays an image with a thick border, strong border color, and rounded corners inside a fixed-width container.

html

<s-box inlineSize="300px">
<s-image
src="https://cdn.shopify.com/static/sample-product/House-Plant1.png"
alt="Product thumbnail"
borderWidth="large"
borderStyle="solid"
borderRadius="large"
objectFit="cover"
aspectRatio="1/1"
inlineSize="fill"
></s-image>
</s-box>

Anchor to Render a fixed-size imageRender a fixed-size image

Display an image at exact dimensions without cropping. This example uses inlineSize and blockSize for fixed dimensions and objectFit="contain" to show the full image within the bounds.

html

<s-box inlineSize="200px">
<s-image
src="https://cdn.shopify.com/static/sample-product/House-Plant1.png"
alt="Gift card design preview"
inlineSize="fill"
objectFit="contain"
borderRadius="base"
></s-image>
</s-box>

Anchor to Use in a grid layoutUse in a grid layout

Build a product image gallery with consistent sizing. This example arranges three product photos in a row using grid, each constrained to a square with rounded corners.

html

<s-grid gridTemplateColumns="repeat(3, 150px)" gap="base" alignItems="center">
<s-image
src="https://cdn.shopify.com/static/sample-product/House-Plant1.png"
alt="Main view"
aspectRatio="1/1"
objectFit="cover"
borderRadius="base"
inlineSize="fill"
></s-image>
<s-image
src="https://cdn.shopify.com/static/sample-product/House-Plant1.png"
alt="Side view"
aspectRatio="1/1"
objectFit="cover"
borderRadius="base"
inlineSize="fill"
></s-image>
<s-image
src="https://cdn.shopify.com/static/sample-product/House-Plant1.png"
alt="Detail view"
aspectRatio="1/1"
objectFit="cover"
borderRadius="base"
inlineSize="fill"
></s-image>
</s-grid>

  • Always provide meaningful alt text: Write descriptive alt text that conveys the image's content or purpose for screen readers. For guidance on writing effective descriptions, see Shopify's alt text guide.
  • Use images for meaningful content, not decoration: Display product photos, diagrams, charts, or instructional screenshots. For icons or decorative elements, use the icon component instead.
  • Use lazy loading for off-screen images: Set loading="lazy" for images below the fold to improve initial page performance.
  • Choose the right fit mode: Use objectFit="cover" for banners and hero images, and objectFit="contain" for logos and previews where cropping would lose meaning.
  • Ensure images are accessible and performant: Use compressed images with an appropriate size and format (WebP for photos, PNG for graphics with transparency, SVG for logos) to minimize loading times. Ensure images load from reliable sources with proper CORS configuration if cross-origin.

Was this page helpful?