Skip to content

Image

Image component with aspect ratio support, multiple sources, lazy loading, fallback and complete accessibility. Optimized for performance and responsive compatibility.

Usage examples

Basic Image

Simple image

vue
<template>
  <SuImage 
    src="https://images.pexels.com/photos/417074/pexels-photo-417074.jpeg"
    alt="Natural landscape"
    width="400"
    height="300"
  />
</template>

Aspect Ratios

Different ratios

16:9 (cinema)

4:3 (classic)

1:1 (square)

vue
<template>
  <!-- Cinema ratio -->
  <SuImage 
    src="image.jpg"
    alt="Cinema image"
    ratio="16/9"
  />
  
  <!-- Classic ratio -->
  <SuImage 
    src="image.jpg"
    alt="Classic image"
    ratio="4/3"
  />
  
  <!-- Square ratio -->
  <SuImage 
    src="image.jpg"
    alt="Square image"
    ratio="1/1"
  />
  
  <!-- Custom ratio -->
  <SuImage 
    src="image.jpg"
    alt="Custom image"
    :ratio="2.5"
  />
</template>

API

Props

PropTypeDefaultDescription
srcstringrequiredMain image URL
altstringrequiredAlternative text for accessibility
fallbackstringundefinedFallback image on error
sourcesImageSource[][]Multiple sources for picture tag
ratio'auto' | '16/9' | '4/3' | '1/1' | number'auto'Image aspect ratio
fit'cover' | 'contain' | 'fill' | 'none' | 'scale-down''cover'Image fit mode
position'center' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right''center'Image position
lazybooleanfalseEnable lazy loading
loading'eager' | 'lazy''lazy'Loading strategy
widthstring | numberundefinedImage width
heightstring | numberundefinedImage height
placeholderbooleantrueShow placeholder during loading
placeholderColorstring'#f3f4f6'Placeholder color

Types

ImageSource

typescript
interface ImageSource {
  srcset: string
  type?: string
  media?: string
}

Events

EventTypeDescription
@load(event: Event) => voidEmitted when image is loaded
@error(event: Event) => voidEmitted if image fails to load

Exposed methods

MethodTypeDescription
reload()() => voidReload the image
imageRefRef<HTMLImageElement>Reference to image element

Accessibility

The Image component follows WCAG 2.1 AA standards:

✅ Accessibility features

  • Required alt text: The alt prop is required for accessibility
  • ARIA attributes: Complete support for ARIA attributes
  • Loading states: Accessible feedback during loading
  • Error handling: Accessible error messages
  • Lazy loading: Compatible with screen readers
  • Placeholder: Appropriate descriptions during loading

🎯 Best practices

vue
<!-- Decorative image -->
<SuImage 
  src="decoration.jpg"
  alt=""
  aria-hidden="true"
/>

<!-- Informative image -->
<SuImage 
  src="chart.jpg"
  alt="Chart showing sales evolution from 2020 to 2024"
  aria-describedby="chart-description"
/>
<div id="chart-description">
  The chart shows consistent growth...
</div>

<!-- Image with specific role -->
<SuImage 
  src="logo.jpg"
  alt="Company logo"
  role="img"
/>

Publié sous licence MIT.