Image

The Image component renders extends and renders an img tag underneath.

Usage

Import the Image component from @avocado-ui/react and render with the required src prop.

Landscape with yellow sky

Please add the alt attribute to your images. These can help describe the image for screen readers.

Size

The Image comes in medium size by default. You can change that by specifying a size value with the size prop. You can set it to any of the following - xs, sm, md, lg, xl.

Landscape with yellow skyLandscape with yellow skyLandscape with yellow sky

You can also pass a number (integer) that'll set the image height & width in pixels.

Landscape with yellow skyLandscape with yellow skyLandscape with yellow sky

The size prop overrides the height & width property of the original img element.

Shape

You can apply a quick change to the border-radius of the Image component by using the shape prop. It's value can be any of curve, round and square

Landscape with yellow skyLandscape with yellow skyLandscape with yellow sky

Object Fit

In cases where the image you're rendering is out of proportion, you can use the objectFit prop to crop into appropriate ratio. The values for objectFit are fill, contain, cover, none and scale-down

Landscape with yellow skyLandscape with yellow skyLandscape with yellow sky

You can change the value of objectFit in this demo to get a feel of the differences. Also see object-fit documentation.

Image Captions

It's great practice to describe images with captions. Avocado provides a beautiful API for doing just that. Get started with the caption prop

Landscape with yellow sky
Image I took yesterday

You can furthermore, customize the position of the caption by setting captionPosition to any of topLeft, topCenter, topRight, bottomLeft, bottomCenter or bottomRight. It's set to bottomCenter by default.

Image I took yesterday
Landscape with yellow sky
Landscape with yellow sky
Image I took yesterday
Landscape with yellow sky
Image I took yesterday

The spacing between the image and the caption might not look good to you. You can customize it by passing a number to the captionSpacing prop.

Landscape with yellow sky
Image I took yesterday
Image I took yesterday
Landscape with yellow sky

Avocado is intelligent enough to know where to add the space depending on the captionPosition prop

Props Table

propertydescriptiontypedefault
sizesize of imagexs, sm, md,lg, numbermd
shapeshape of imageround, square,curvesqaure
altText to announce out to screen readers. Please make this availablestring
srcsource for avatar imagestring
widthwidth of imagenumber
heightheight of imagenumber
captionCaption to more information about imagestring
captionPositionposition to show the image caption.topLeft, topCenter, topRight, bottomLeft, bottomCenter, bottomRight bottomCenterbottomCenter
captionSpacingspace between the image and the image caption in pxnumber