Skip to content

Layout Components

[05] Layout Components

Img

Displays images with VaneUI styling support including sizes, shapes, borders, shadows, and object-fit options.

SourceEdit this page

Img is for photos, screenshots, avatars and other content images. It renders a native <img> element and takes no children, so an image that needs a title or caption next to it goes in a Card or a Col together with its text. For an icon, use Icon, which wraps an inline SVG in a <span> rather than loading an image file.

const placeholderSrc = "https://placehold.co/300x200/e2e8f0/64748b?text=Image";
const portraitSrc = "https://placehold.co/200x300/cbd5e1/475569?text=Portrait";
const avatarSrc = "https://placehold.co/120x120/c7d2fe/4338ca?text=Avatar";

Basic usage

Render an image with the Img component.

Sample landscape photo
<Img src={placeholderSrc} alt="Sample landscape photo" />

Alt text

Always pass a descriptive alt attribute. Use an empty alt="" for decorative images so assistive technology can skip them.

Team standing in front of the office building
<Row flexWrap>
<Img src={placeholderSrc} alt="Team standing in front of the office building" />
<Img src={placeholderSrc} alt="" />
</Row>

Shapes

Control border radius with rounded (default), pill (great for avatars), and sharp.

Rounded image

rounded (default)

Avatar

pill

Sharp image

sharp

<Row flexWrap>
<Col itemsCenter>
<Img src={placeholderSrc} alt="Rounded image" />
<Text sm secondary>rounded (default)</Text>
</Col>
<Col itemsCenter>
<Img pill src={avatarSrc} alt="Avatar" />
<Text sm secondary>pill</Text>
</Col>
<Col itemsCenter>
<Img sharp src={placeholderSrc} alt="Sharp image" />
<Text sm secondary>sharp</Text>
</Col>
</Row>

Border and shadow

Add border and shadow props for visual emphasis.

Bordered image

border

Image with shadow

shadow

Bordered image with shadow

border + shadow

<Row flexWrap>
<Col itemsCenter>
<Img border src={placeholderSrc} alt="Bordered image" />
<Text sm secondary>border</Text>
</Col>
<Col itemsCenter>
<Img shadow src={placeholderSrc} alt="Image with shadow" />
<Text sm secondary>shadow</Text>
</Col>
<Col itemsCenter>
<Img border shadow src={placeholderSrc} alt="Bordered image with shadow" />
<Text sm secondary>border + shadow</Text>
</Col>
</Row>

Appearances and variants

Img paints no surface of its own, so an appearance only shows through the border it draws. filled gives it a background, which is visible behind a transparent PNG or while the image is still loading.

Success borderDanger border
<Row flexWrap itemsCenter>
<Img border success src="https://placehold.co/80x60/png" alt="Success border" />
<Img border danger src="https://placehold.co/80x60/png" alt="Danger border" />
<Img filled secondary className="w-20 h-15" alt="" />
</Row>

Sizes

Images support five sizes: xs, sm, md (default), lg, xl. Size controls border-radius scaling.

xs image

xs

sm image

sm

md image

md (default)

lg image

lg

xl image

xl

<Row flexWrap itemsEnd>
<Col itemsCenter>
<Img xs src={placeholderSrc} alt="xs image" />
<Text sm secondary>xs</Text>
</Col>
<Col itemsCenter>
<Img sm src={placeholderSrc} alt="sm image" />
<Text sm secondary>sm</Text>
</Col>
<Col itemsCenter>
<Img src={placeholderSrc} alt="md image" />
<Text sm secondary>md (default)</Text>
</Col>
<Col itemsCenter>
<Img lg src={placeholderSrc} alt="lg image" />
<Text sm secondary>lg</Text>
</Col>
<Col itemsCenter>
<Img xl src={placeholderSrc} alt="xl image" />
<Text sm secondary>xl</Text>
</Col>
</Row>

Object fit

Control how an image fills a sized container with objectCover (default), objectContain, and objectFill. The examples below constrain the image to a fixed box so the difference is visible.

Cover crops to fill the box

objectCover (default)

Contain fits inside the box

objectContain

Fill stretches to the box

objectFill

<Row flexWrap>
<Col itemsCenter>
<Img src={portraitSrc} alt="Cover crops to fill the box" className="w-[200px] h-[150px]" />
<Text sm secondary>objectCover (default)</Text>
</Col>
<Col itemsCenter>
<Img objectContain src={portraitSrc} alt="Contain fits inside the box" className="w-[200px] h-[150px]" />
<Text sm secondary>objectContain</Text>
</Col>
<Col itemsCenter>
<Img objectFill src={portraitSrc} alt="Fill stretches to the box" className="w-[200px] h-[150px]" />
<Text sm secondary>objectFill</Text>
</Col>
</Row>

Aspect ratio

aspectSquare and aspectVideo fix the shape of the image at 1:1 and 16:9: set the width, and the height follows. With objectCover, the default, the photo is cropped to fill that shape, so a gallery of photos of different sizes lines up. aspectAuto goes back to the photo's own shape. These props need @vaneui/ui 1.8.0 or later.

Square crop16:9 crop of a portrait photo
<Row flexWrap itemsStart>
<Img aspectSquare src={placeholderSrc} alt="Square crop" className="w-32" />
<Img aspectVideo src={portraitSrc} alt="16:9 crop of a portrait photo" className="w-56" />
</Row>

Inside a Card

For a media tile, put the Img first in a Card built from parts and the text in a CardBody. A Card of parts has no inset of its own, so the image sits on the Card's top edge: it takes the Card's corners there, less the border, and is square where it meets the body. Use wFull so the image spans the card width. An Img that closes the Card takes the bottom corners the same way.

Sunset over the harbor
Harbor Sunset

Captured last weekend on a walk along the pier.

Forest trail at dawn
Forest Trail

Early morning hike through the pine forest.

<Row flexWrap itemsStart>
<Card className="w-[240px]">
<Img wFull src={placeholderSrc} alt="Sunset over the harbor" className="h-[140px]" />
<CardBody>
<Title sm>Harbor Sunset</Title>
<Text sm secondary>Captured last weekend on a walk along the pier.</Text>
</CardBody>
</Card>
<Card className="w-[240px]">
<Img wFull src={placeholderSrc} alt="Forest trail at dawn" className="h-[140px]" />
<CardBody>
<Title sm>Forest Trail</Title>
<Text sm secondary>Early morning hike through the pine forest.</Text>
</CardBody>
</Card>
</Row>

An Img inside a padded Card keeps its own corners on all four sides, as do a sharp or pill Img and one with a radius class of your own. The edge corners need @vaneui/ui 1.8.0 or later; on earlier releases, give the Card noPadding and overflowHidden and the Img sharp.

Keeping its size in a row with noShrink

In a flex Row, an image is a flex item that can give up width when the row runs out of room. noShrink sets flex-shrink: 0, so a logo or an avatar keeps its size and the text beside it gives way instead. Here the row also takes whitespaceNowrap and overflowHidden, so the label stays on one line and clips at the row's edge. noShrink on Img needs @vaneui/ui 1.4.5 or later.

A long label that stays on one line and clips at the edge of its row

<Row whitespaceNowrap overflowHidden className="max-w-80">
<Img noShrink pill src={avatarSrc} alt="" width={32} height={32}/>
<Text sm>A long label that stays on one line and clips at the edge of its row</Text>
</Row>

Native HTML attributes

Img forwards all standard <img> attributes including loading, decoding, srcSet, sizes, referrerPolicy, and crossOrigin. Use loading="lazy" for below-the-fold images.

Lazy-loaded image
<Img
src={placeholderSrc}
alt="Lazy-loaded image"
loading="lazy"
decoding="async"
/>

Frequently asked questions

How do I make a round avatar?

Use Avatar. It sizes the circle with the size prop, crops the photo to fill it, and falls back to the initials of name when the image is missing or fails to load. For a round Img of your own, add pill and aspectSquare and set a width, for example <Img pill aspectSquare className="w-10" />. objectCover, a default, crops a photo that is not square to fill the circle.

How do I add a caption to an image?

Wrap the Img and its caption in <Col tag="figure">, and render the caption with <Text tag="figcaption" sm secondary>. The caption then names the figure for assistive technology. Keep the alt text as well: it describes what the image shows, while the caption adds context such as a credit, a date or a place.

Can I use Img with the Next.js Image component?

Yes: pass it as the tag, as in <Img tag={Image} src="/team.jpg" alt="The team" width={600} height={400}/> with Image imported from next/image. Img then renders that component with its own classes, so the shape, border and object-fit props still apply, while Next.js resizes and lazy-loads the file. Next.js still requires width and height, or fill.

Img Props

PropCategoryDefaultDescription
accent

Appearance

Accent color appearance (rose)

danger

Appearance

Danger color appearance (red)

info

Appearance

Info color appearance (cyan)

inheritAppearance

Appearance

Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables

primary

Appearance

Primary color appearance (gray)

secondary

Appearance

Secondary color appearance (gray)

success

Appearance

Success color appearance (green)

tertiary

Appearance

Tertiary color appearance

warning

Appearance

Warning color appearance (amber)

aspectAuto

Aspect

The content's own ratio (aspect-ratio: auto)

aspectSquare

Aspect

Square box (aspect-ratio: 1 / 1)

aspectVideo

Aspect

Video box (aspect-ratio: 16 / 9)

pill

Shape

Fully rounded corners (circular)

rounded

Shape

✓

Medium rounded corners (default)

sharp

Shape

No rounded corners (square)

noShrink

Shrink

Prevent the flex item from shrinking below its content size (= shrink-0)

lg

Size

Large size

md

Size

✓

Medium size (default)

sm

Size

Small size

xl

Size

Extra large size

xs

Size

Extra small size

skeleton

Skeleton

Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too

filled

Variant

Filled variant - solid background with contrasting text color

ghost

Variant

Ghost variant - transparent background, no border, appearance-colored text, tinted hover background

outline

Variant

✓

Outline variant - transparent background with border and colored text (default)

Layout & utility props (gap, padding, hide, items, justify, ...)

Documented on Common Props.

PropCategoryDefaultDescription
border

Border

Enable border on all sides

borderB

Border

Enable border on bottom

borderEnd

Border

Enable border on the inline-end side (right in LTR, left in RTL)

borderL

Border

Enable border on left

borderR

Border

Enable border on right

borderStart

Border

Enable border on the inline-start side (left in LTR, right in RTL)

borderT

Border

Enable border on top

borderX

Border

Enable border on left and right

borderY

Border

Enable border on top and bottom

noBorder

Border

Disable all borders

block

Display

Block display - takes full width, new line

contents

Display

Contents display - element's box is removed, children display as if parent didn't exist

flex

Display

Flex display - flexbox container

grid

Display

Grid display - CSS grid container

hidden

Display

Hidden display - element is not visible

inline

Display

Inline display - flows with text

inlineBlock

Display

Inline-block display - inline but with block properties

inlineFlex

Display

Inline-flex display - inline flexbox container

inlineGrid

Display

Inline-grid display - inline grid container

table

Display

Table display - behaves like table element

tableCell

Display

Table-cell display - behaves like td element

focusVisible

Focus Visible

Enable focus-visible outline

noFocusVisible

Focus Visible

Disable focus-visible outline

hAuto

Height

Set height to auto

hFit

Height

Set height to fit-content

hFull

Height

Set height to 100%

hScreen

Height

Set height to 100vh (viewport height), removes max-height constraint

desktopHide

Hide

Hide element on desktop devices and below (max-desktop: 80rem)

mobileHide

Hide

Hide element on mobile devices and below (max-mobile: 48rem)

tabletHide

Hide

Hide element on tablet devices and below (max-tablet: 64rem)

itemsBaseline

Items

Align items to baseline

itemsCenter

Items

Align items to center

itemsEnd

Items

Align items to end (bottom/right)

itemsStart

Items

Align items to start (top/left)

itemsStretch

Items

Stretch items to fill container

justifyAround

Justify

Distribute items with space around them

justifyBaseline

Justify

Align items along their baseline on main axis

justifyBetween

Justify

Distribute items with space between them

justifyCenter

Justify

Center items along the main axis

justifyEnd

Justify

Pack items toward the end of the main axis

justifyEvenly

Justify

Distribute items with equal space around them

justifyStart

Justify

Pack items toward the start of the main axis

justifyStretch

Justify

Stretch items to fill the main axis

objectContain

Object Fit

Contain - image fits inside container, may have letterboxing

objectCover

Object Fit

✓

Cover - image covers container, may be cropped

objectFill

Object Fit

Fill - image stretches to fill container

objectNone

Object Fit

None - image displays at natural size

objectScaleDown

Object Fit

Scale down - like contain, but never scales up

overflowAuto

Overflow

Auto overflow - show scrollbars if needed

overflowClip

Overflow

Clip overflow - hard clip without scrollbars

overflowHidden

Overflow

Hidden overflow - clip content without scrollbars

overflowScroll

Overflow

Scroll overflow - always show scrollbars

overflowVisible

Overflow

Visible overflow - content extends beyond bounds

overflowXAuto

Overflow

Auto overflow on X-axis only

overflowXClip

Overflow

Clip overflow on X-axis only

overflowXHidden

Overflow

Hidden overflow on X-axis only

overflowXScroll

Overflow

Scroll overflow on X-axis only

overflowXVisible

Overflow

Visible overflow on X-axis only

overflowYAuto

Overflow

Auto overflow on Y-axis only

overflowYClip

Overflow

Clip overflow on Y-axis only

overflowYHidden

Overflow

Hidden overflow on Y-axis only

overflowYScroll

Overflow

Scroll overflow on Y-axis only

overflowYVisible

Overflow

Visible overflow on Y-axis only

absolute

Position

Absolute positioning

fixed

Position

Fixed positioning

relative

Position

Relative positioning

static

Position

Static positioning

sticky

Position

Sticky positioning at the top edge; set --sticky-top to stick below a fixed header

responsiveSizing

Responsive Sizing

Enable responsive sizing - uses breakpoint-specific classes for font size, padding, and gap

desktopWFull

Responsive Width

Set width to 100% on desktop and below, below 1280px (max-desktop: 80rem)

mobileWFull

Responsive Width

Set width to 100% on mobile, below 768px (max-mobile: 48rem)

tabletWFull

Responsive Width

Set width to 100% on tablet and below, below 1024px (max-tablet: 64rem)

insetRing

Ring

Enable the inset ring — emits ring-inset

noInsetRing

Ring

Disable the inset ring

noShadow

Shadow

Disable drop shadow

shadow

Shadow

Enable drop shadow at the component's size

shadowLg

Shadow

Large drop shadow, whatever the component's size

shadowMd

Shadow

Medium drop shadow, whatever the component's size

shadowSm

Shadow

Small drop shadow, whatever the component's size

shadowXl

Shadow

Extra-large drop shadow, whatever the component's size

shadowXs

Shadow

Extra-small drop shadow, whatever the component's size

desktopShow

Show

Show element only on desktop and below, below 1280px (hidden from 80rem up)

mobileShow

Show

Show element only on mobile, below 768px (hidden from 48rem up)

tabletShow

Show

Show element only on tablet and below, below 1024px (hidden from 64rem up)

transparent

Transparent

Disable background color - makes component background transparent

wAuto

Width

Set width to auto

wFit

Width

Set width to fit-content

wFull

Width

Set width to 100%

wScreen

Width

Set width to 100vw (viewport width), removes max-width constraint