You are looking at the documentation of the work in progress Hope UI 1.0, examples and information may be broken or outdated.

Data display

Image

Display images with fallback placeholder support.

Import

tsx
import { Image } from "@hope-ui/core";
tsx
import { Image } from "@hope-ui/core";

Usage

Monkey D. Luffy
tsx
<Image src="https://bit.ly/3TJwRZR" alt="Monkey D. Luffy" objectFit="cover" maxW="200px" />
tsx
<Image src="https://bit.ly/3TJwRZR" alt="Monkey D. Luffy" objectFit="cover" maxW="200px" />

Fallback placeholder

Image allows you provide a fallback placeholder, which is displayed when:

  • The fallback or fallbackSrc prop is provided.
  • The image provided in src is currently loading.
  • An error occurred while loading the image src.
  • No src prop was passed.

You can also opt out of this behavior by passing the ignoreFallback prop.

tsx
<Image src="gibberish.png" fallbackSrc="https://via.placeholder.com/150" />
tsx
<Image src="gibberish.png" fallbackSrc="https://via.placeholder.com/150" />

Usage with SSR

For server side rendered applications, Hope UI provides an alternative Img component which uses the image directly without client side checks.

tsx
import { Img } from "@hope-ui/core";
function Demo() {
return <Img src="https://bit.ly/3TJwRZR" alt="Monkey D. Luffy" />;
}
tsx
import { Img } from "@hope-ui/core";
function Demo() {
return <Img src="https://bit.ly/3TJwRZR" alt="Monkey D. Luffy" />;
}

Props

NameTypeDescriptionDefault value
srcstringThe image src attribute.
srcSetstringThe image srcset attribute.
sizesstringThe image sizes attribute.
crossOrigin"" | "anonymous" | "use-credentials"The key used to set the crossOrigin on the HTMLImageElement into which the image will be loaded. This tells the browser to request cross-origin access when trying to download the image data.
loading"eager" | "lazy"The image loading strategy.
htmlWidthstring | numberThe native HTML width attribute to the passed to the img.
htmlHeightstring | numberThe native HTML height attribute to the passed to the img.
fallbackSrcstringFallback image src to show if image is loading or image fails. Using a local image is recommended.
fallbackJSX.ElementFallback element to show if image is loading or image fails.
ignoreFallbackbooleanIf true, opt out of the fallbackSrc logic.false
alignProperty.ObjectPositionHow to align the image within its bounds. It maps to css object-position property.
fitProperty.ObjectFitHow the image to fit within its bounds. It maps to css object-fit property.
onLoadJSX.EventHandlerUnion<HTMLImageElement, Event>A callback for when the image src has been loaded.
onErrorJSX.EventHandlerUnion<HTMLImageElement, Event>A callback for when there was an error loading the image src.
Previous
Icon
Next
Kbd