Image
Image with a shimmer skeleton while it loads, a fade-in, an error fallback and aspect ratio presets.
<arc-image>Overview
Image wraps a native <img> with loading and error states. While the image loads, a shimmer skeleton fills the container, and the image fades in once it arrives. If it fails, the component shows the fallback image if you set one, or a placeholder icon if you didn't.
aspect takes one of six presets (1/1, 4/3, 16/9, 21/9, 3/4, 9/16) and sizes the container before the image loads, so the page doesn't jump. fit maps to CSS object-fit and defaults to cover. loading defaults to lazy.
Guidelines
Do
- Write `alt` text that describes the image
- Set `aspect` so the layout doesn't shift while the image loads
- Use `fit="contain"` for logos and icons that shouldn't be cropped
- Set `fallback` on images that must always show something
Don't
- Don't use it for decorative backgrounds. Use CSS `background-image`
- Don't set `loading="eager"` on images below the fold. Lazy loading waits until they're near the viewport
- Don't serve very large source images without resizing them on the server
Features
- `fit` values: `cover` (default), `contain`, `fill`, `none` and `scale-down`
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-image
src="/demo/mountain-600x400.jpg"
alt="Mountain landscape"
aspect="16/9"
></arc-image>
<!-- With fallback -->
<arc-image
src="https://example.com/missing.jpg"
alt="Product photo"
aspect="1/1"
fallback="/demo/fallback-200x200.jpg"
></arc-image>import { Image } from '@arclux/arc-ui-react';
export default function Example() {
return (
<>
<Image src="/demo/mountain-600x400.jpg" alt="Mountain landscape" aspect="16/9" />
<Image src="/missing.jpg" alt="Product" aspect="1/1" fallback="/placeholder.png" />
</>
);
}<script setup>
import { Image } from '@arclux/arc-ui-vue';
</script>
<template>
<Image src="/demo/mountain-600x400.jpg" alt="Mountain landscape" aspect="16/9" />
<Image src="/missing.jpg" alt="Product" aspect="1/1" fallback="/placeholder.png" />
</template><script>
import { Image } from '@arclux/arc-ui-svelte';
</script>
<Image src="/demo/mountain-600x400.jpg" alt="Mountain landscape" aspect="16/9" />
<Image src="/missing.jpg" alt="Product" aspect="1/1" fallback="/placeholder.png" />import { Component } from '@angular/core';
import { Image } from '@arclux/arc-ui-angular';
@Component({
imports: [Image],
template: `
<arc-image src="/demo/mountain-600x400.jpg" alt="Mountain landscape" aspect="16/9" />
<arc-image src="/missing.jpg" alt="Product" aspect="1/1" fallback="/placeholder.png" />
`,
})
export class GalleryComponent {}import { Image } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<>
<Image src="/demo/mountain-600x400.jpg" alt="Mountain landscape" aspect="16/9" />
<Image src="/missing.jpg" alt="Product" aspect="1/1" fallback="/placeholder.png" />
</>
);
}import { Image } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<>
<Image src="/demo/mountain-600x400.jpg" alt="Mountain landscape" aspect="16/9" />
<Image src="/missing.jpg" alt="Product" aspect="1/1" fallback="/placeholder.png" />
</>
);
}API
srcstring''- Image source URL.
altstring''- Alt text for the image. Used as the accessible description.
fallbackstring''- URL of a fallback image to display if the primary
srcfails to load. aspect'' | '1/1' | '4/3' | '16/9' | '21/9' | '3/4' | '9/16'''- Constrains the container to a fixed aspect ratio, preventing layout shift during loading. Empty (the default) leaves the container unconstrained; an unrecognised ratio falls back to it.
fit'cover' | 'contain' | 'fill' | 'none' | 'scale-down''cover'- CSS object-fit mode controlling how the image fills its container.
loading'lazy' | 'eager''lazy'- Native loading strategy. Lazy defers off-screen images until they approach the viewport.
Events
arc-load- Fired when the image successfully loads.
arc-error- Fired when the image fails to load.