Media

Image compare

Two images in one frame with a handle between them. Drag it, press anywhere to jump there, or use the arrow keys. For before and after, edits, restorations and maps.

Installation

npx sinaui add image-compare

Examples

Grayscale and color

Each side is a snippet, so it can be any image, picture or canvas.

A library in Basra, from al-Wasiti's Maqamat of al-Hariri, 1237.

<script lang="ts">
	import ImageCompare from '#lib/ui/ImageCompare.svelte';

	const src =
		'https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/A_Library_in_Golden_Islamic_Age.jpg/960px-A_Library_in_Golden_Islamic_Age.jpg';
</script>

<div class="demo">
	<ImageCompare beforeLabel="Grayscale" afterLabel="Color" ratio="3 / 4">
		{#snippet before()}<img {src} alt="" style:filter="grayscale(1)" />{/snippet}
		{#snippet after()}<img {src} alt="" />{/snippet}
	</ImageCompare>
	<p>A library in Basra, from al-Wasiti's Maqamat of al-Hariri, 1237.</p>
</div>

<style>
	.demo {
		inline-size: min(22rem, 100%);
	}
	p {
		margin: 0.5rem 0 0;
		color: var(--ui-muted);
		font-size: 0.875rem;
	}
</style>

Props

PropTypeDefault
before, afterSnippet (required)
beforeLabel, afterLabelstring'Before', 'After'
valuenumber, 0–100 (bindable)50
ratiostring'4 / 3'

Keyboard

KeyDoes
← →Move the handle by 1%
Page Up Page DownMove it by 10%
Home EndAll before, all after

Accessibility

  • The handle is a slider named after both labels, announcing how much of "after" shows.
  • Describe what the images show in text nearby, such as a caption.
  • With reduced motion, the handle moves without gliding.
Introduction
Theming
Changelog
Button
Action button
Confirm button
Copy button
Hold to confirm
Split button
Calendar
Checkbox
Color picker
Combobox
Date picker
Date range picker
File drop
Form
Input
Mention input
Multi select
Number field
OTP input
Password input
Phone input
Radio cards
Radio group
Rich text editor
Search field
Segmented control
Select
Signature pad
Slider
Switch
Tag input
Upload
Wheel picker
Textarea
Time field
Toggle group
Toolbar
Alert dialog
Command palette
Context menu
Dialog
Drawer
Dropdown
Hover card
Popover
Tooltip
Announcement bar
Alert
Empty state
Meter
Progress
Rolling number
Skeleton
Spinner
Toast
Avatar
Avatar group
Badge
Card
Carousel
Chart
Chat
Code block
Data table
Folder
Kbd
Mind map
Resizable panels
Scroll area
Separator
Sortable
Table
Tag group
Virtual list
Audio player
Image
Image compare
Video
Visualizer
Breadcrumb
File tree
Menubar
Navigation menu
Pagination
Sidebar layout
Stepper
Tabs
Alarm clock
Clock
Dynamic island
Fluid orb
Hourglass
Stopwatch
Timer
AI chat
AI media
Auth
Board
Booking
Dashboard
File explorer
Messaging
Notifications
Settings
Team
Overview
Pricing
Agent chat
Calendar
Voice agent
Mail inbox
CMS
Blog
Marketing site
E-commerce
AI agents
SaaS landing page
SaaS app
Accordion
Dark theme
Light theme