Image

An image that fills its box the way you choose, such as cropped to fit or shown whole.

Oskar Brandt

Usage

Code
import { Image } from '@leverui/components';
Code
<Image src="..." />

Examples

Height

Use the height style to change the height of the image component.

Circular

Here's an example of how to render a circular image.

Theo Park

Aspect Ratio

Use the aspect-ratio style to change the aspect ratio of the image component.

Mountain landscape

Fit

By default, the image applies object-fit: cover. Use the fit prop to change the fit of the image component.

HTML Width and Height

Use the htmlWidth and htmlHeight props to set the native width and height of the image component.

Guides

Accessibility

Describe a meaningful image in alt. Use alt="" for decoration, so screen readers skip it.

Image does not load a fallback image.

Dimensions

Set the size with style or your own class. Set both width and height to crop to a fixed shape. fit="contain" keeps the whole image visible.

Image renders a plain img, so width, height, loading, and decoding work.

Code
<Image
  src="/portrait.jpg"
  alt="Portrait of the speaker"
  style={{ width: '8rem', height: '8rem' }}
  fit="cover"
  class="portrait-image"
/>
Code
.portrait-image {
  border-radius: 50%;
}

Put portrait.jpg in your app's public folder.

Props

PropDefaultTypeDescription
fitcover'cover' | 'contain' | 'fill' | 'none' | 'scale-down' or responsive mapHow the image fills its box. CSS object-fit.
align—string or responsive mapWhere the image sits in its box. CSS object-position.
htmlWidth—string | numberwidth attribute on the img.
htmlHeight—string | numberheight attribute on the img.
asimgNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the image's props.
unstyledfalsebooleanTurn off the default fit and position styles.

Also accepts every standard img attribute.

Customize with CSS

Import @leverui/components/styles.css once, before your own CSS. Set --leverui-image-fit and --leverui-image-position, or style .leverui-image.

No CSS objects or general style props.