Skip to main content

Use cases

  • Product images: Display images in catalogs and order details to help identify items.
  • Marketing content: Show promotional banners or seasonal content for business information.
  • Visual guidance: Provide instructions or onboarding content for complex processes.
  • Branding: Display logos or store imagery to maintain brand consistency.

Display visual content using an Image component with automatic loading optimization and error handling. This example shows a basic image with source URL and alt text for accessibility.

Display an image

Display an image

<s-image src="example.png" inlineSize="auto" />

Configure the following properties on the Image component.

string
Default: `''`

An alternative text description that describe the image for the reader to understand what it is about. It is extremely useful for both users using assistive technology and sighted users. A well written description provides people with visual impairments the ability to participate in consuming non-text content. When a screen readers encounters an s-image, the description is read and announced aloud. If an image fails to load, potentially due to a poor connection, the alt is displayed on screen instead. This has the benefit of letting a sighted buyer know an image was meant to load here, but as an alternative, they’re still able to consume the text content. Read considerations when writing alternative text to learn more.

string

A unique identifier for the element.

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

The displayed inline width of the image.

  • fill: the image will takes up 100% of the available inline size.
  • auto: the image will be displayed at its natural size.

Mobile surfaces: Always wrap your image in a box with a set width and height. ScrollViews on mobile have a dynamic height, which can cause images to appear inconsistently without defined dimensions.

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

Determines how the content of the image is resized to fit its container. The image is positioned in the center of the container.

string

The image source, which should be a remote URL.

When the image is loading or no src is provided, a placeholder will be rendered.

  • Choose appropriate sizing: Use inlineSize="fill" for responsive layouts. Use inlineSize="auto" to maintain natural dimensions.
  • Select object fit behavior: Use objectFit="contain" to show the complete image. Use objectFit="cover" to fill the container, accepting cropping.
  • Implement error handling and loading states: Image loading and caching behavior depends on the browser and network conditions—implement proper error handling and loading states for better user experience.

Large images can impact performance—ensure proper optimization and compression for better loading times.

Was this page helpful?