---
title: ResponsiveImage
---

import LibraryInfo from '@theme/LibraryInfo'
import { Feedback, PropsTable } from '../../src/components'
import { ResponsiveImage } from '@telus-uds/components-web'
import { ResponsiveImage as WebDocs } from 'docs/@telus-uds/components-web'
import AvailableOnWebOnly from '../../partials/_platform-considerations-web-only.mdx'
import NoStylisticVariants from '../../partials/_variants-none.mdx'

# ResponsiveImage

<LibraryInfo packageType="Web Component" />

```jsx live
<ResponsiveImage
  lgSrc={mountainsDesktopImage}
  mdSrc={mountainsTabletImage}
  smSrc={mountainsMobileImage}
  xsSrc={mountainsMobileImage}
  fallbackSrc={mountainsDesktopImage}
  alt="mountain background"
/>
```

## Introduction

```jsx
import { ResponsiveImage } from '@telus-uds/components-web'
```

Provide different image sources for different screen sizes.

[Follow the appropriate instructions](importing-components) to add this component in to your app.

## Guidance

The `ResponsiveImage` component allows variation in "art direction" when wanting to change the image displayed to suit different screen sizes. This can also be used to provide compressed files or alternate formats based on device to help reduce download size.

Similarly to the Image component:

- We recommend not to resize or crop images in the browser
- Image optimization should be done BEFORE rendering
- You can use the `contentful API` to request an image of a certain size
- Pass `'lazy'` via the `loading` prop to make the image
  [lazy-loading](https://developer.mozilla.org/en-US/docs/Web/Performance/Lazy_loading#images_and_iframes)

Specific to ResponsiveImage:

- The image will fit to 100% of its parent container
- The image source will change based on `window width`, not parent container size
- Uses the following breakpoints:
  - xl: min-width 1200px
  - lg: min-width 992px
  - md: min-width 768px
  - sm: min-width 576px
  - xs: max-width 575px
- Provide a source for the sm and xs breakpoints as a minimum
- Internet Explorer is not supported and will use the fallback src provided

Change the window width to see the images above change.

### Accessibility

Always provide an `alt` attribute for images with a short description of the image. You can use an empty string (`""`) if the image is purely decorative and conveys no information.

### Platform considerations

<AvailableOnWebOnly />

## Props

<PropsTable web={WebDocs} />

### Use of `dataSet`

Use dataSet prop to pass custom data attributes. Here's an example:

```jsx live
<ResponsiveImage
  lgSrc={mountainsDesktopImage}
  mdSrc={mountainsTabletImage}
  smSrc={mountainsMobileImage}
  xsSrc={mountainsMobileImage}
  fallbackSrc={mountainsDesktopImage}
  alt="mountain background"
  dataSet={{ 'data-field-id': 'test field id', 'data-entry-id': 'test entry id' }}
/>
```

## Variants

<NoStylisticVariants />

## Feedback

<Feedback component="ResponsiveImage" />
