Skip to main content

Skeleton Image

Image placeholder skeleton with aspect ratio support

Skeleton Image

Specialized skeleton component for image placeholders with customizable aspect ratios and optional caption support.

Demo

Default (16:9)
Loading...
Loading image...
Square (1:1)
Loading...
Loading image...

Usage

<script>
import SkeletonImage from '$lib/shared/components/loading/SkeletonImage.svelte';
</script>

<!-- Default 16:9 image -->
<SkeletonImage />

<!-- Square image -->
<SkeletonImage aspectRatio="1 / 1" />

<!-- With caption -->
<SkeletonImage showCaption={true} />

<!-- Custom animation -->
<SkeletonImage animation="pulse" />

<!-- Custom size -->
<SkeletonImage width="400px" />

Props

PropTypeDefaultDescription
aspectRatiostring'16 / 9'CSS aspect-ratio value
showCaptionbooleanfalseWhether to show caption skeleton
animation'shimmer' \| 'pulse' \| 'none''shimmer'Animation style
widthstring'100%'Image width
roundedbooleanfalseUse rounded corners
classstring''Additional CSS classes

Common Aspect Ratios

RatioUse Case
16 / 9Video thumbnails, hero images
4 / 3Standard photos
1 / 1Square images, avatars
3 / 4Portrait photos
21 / 9Ultra-wide banners

Examples

<div class="gallery">
	{#each Array(6) as _}
		<SkeletonImage aspectRatio="1 / 1" />
	{/each}
</div>

Article Image

<article>
	<SkeletonImage aspectRatio="16 / 9" showCaption={true} />
	<SkeletonText lines={3} />
</article>

Profile Cover

<div class="profile-header">
	<SkeletonImage aspectRatio="21 / 9" />
	<Skeleton variant="avatar" size="lg" />
</div>

Best Practices

  1. Match Aspect Ratios: Use the same aspect ratio as your actual images
  2. Prevent Layout Shift: Skeleton dimensions should match loaded content exactly
  3. Caption Consistency: Only show caption skeleton if real image has captions
  4. Responsive Sizing: Use percentage widths for responsive layouts