← All Components
<mth-image>
Accessible progressive image with safe-URL validation, aspect ratio, lazy loading, placeholder, and fallback handling.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Methane UI · 16:9 Responsive Image Frame
Ready · interact with <mth-image>, or toggle Theme, Direction (LTR/RTL), or props above.
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/image"></script>
<mth-image fit="cover" loading="lazy"></mth-image>import '@methane-ui/ui/image';
import '@methane-ui/react';
export function Example() {
return <mth-image fit="cover" loading="lazy"></mth-image>;
}<script setup lang="ts">
import '@methane-ui/ui/image';
</script>
<template>
<mth-image fit="cover" loading="lazy"></mth-image>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/image';
import { MthImageDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthImageDirective],
template: `<mth-image fit="cover" loading="lazy"></mth-image>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/image';
import MthImage from '@methane-ui/svelte/MthImage.svelte';
</script>
<MthImage fit="cover" loading="lazy"></MthImage>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
src | src | string | "" | Primary image URL (validated against safe HTTP(S)/relative protocols). |
alt | alt | string | "" | Alternative text describing the image. |
fallbackSrc | fallback-src | string | "" | Optional backup URL loaded if the primary src fails. |
aspectRatio | aspect-ratio | string | "" | CSS aspect-ratio applied to the image container (e.g. 16/9). |
fit | fit | 'cover' | 'contain' | 'fill' | 'none' | 'scale-down' | "cover" | Object-fit mode for the rendered image. |
loading | loading | 'lazy' | 'eager' | "lazy" | Native browser loading strategy (lazy or eager). |
decoding | decoding | 'async' | 'sync' | 'auto' | "async" | Image decoding hint (async, sync, or auto). |
rounded | rounded | boolean | false | Applies rounded corner radius tokens to the container. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-load | { src: string } | Fired when the active image finishes loading. |
mth-error | { src: string } | Fired when the image fails to load or src is rejected as unsafe. |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | Focus ownership matches focusModel="none". | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| states | Exposes ElementInternals CustomStateSet flags: :state(loading), :state(loaded), :state(error). | Conformance suite |
| i18n | Routes 2 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |