DXC Logo
Halstack Design System
v16.1.0

Image

The image component is used to embed images in Halstack-based user interfaces.

Props

NameTypeDescriptionDefault
Required
alt
stringAlternative text description displayed when the specified image is not loaded. See MDN and the alt decision tree of W3C for further information.-
captionstringImage legend with a descriptive purpose. It is placed below the image and is complementary to the alt attribute, which is required regardless of the presence of the caption or not.-
heightstringSets the rendered height of the image.-
lazyLoadingbooleanIf true, the image will be loaded only when it is visible on the screen (lazy loading). Otherwise and by default, the image will be loaded as soon as the component is mounted (eager loading).false
objectFit'contain' | 'cover' | 'fill' | 'none' | 'scale-down'Sets the object-fit CSS property. See MDN for further information.'fill'
objectPositionstringSets the object-position CSS property. See MDN for further information.'50% 50%'
onErrorReact.ReactEventHandler <HTMLImageElement>This function will be called when the image fails to load.-
onLoadReact.ReactEventHandler <HTMLImageElement>This function will be called when the image is loaded.-
sizesstringOne or more strings separated by commas, indicating a set of source sizes. If the srcSet attribute is absent or contains no values with a width descriptor, then this attribute has no effect. See MDN for further information.-
Required
src
stringURL of the image.-
srcSetstringList of one or more strings separated by commas indicating a set of possible images for the user agent to use. See MDN for further information.-
widthstringSets the rendered width of the image.-

Examples

Basic usage

() => {
  return (
    <DxcInset space="var(--spacing-padding-xl)">
      <DxcImage 
        alt="Wooden dock on a lake" 
        caption="Wooden dock on a beautifully landscaped lake."
        width="100%"
        src="https://images.unsplash.com/photo-1454372182658-c712e4c5a1db?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2670&q=80" 
      />
    </DxcInset>
  );
}