Compare

Two things compared, one over the other, split by a divider you drag — photos before and after an edit, two themes of a design, any content.

MediaExperimental

Usage

Usage

Mountains at dawn, as shot: grey and flatThe same photo, edited: warm light and deep coloursBeforeAfter
import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScCompare,  ScCompareAfter,  ScCompareBefore,  ScCompareHandle,  ScCompareLabel,  ScFrame,} from '@semantic-components/ui';

Anatomy

The before sizes the box; the after lies over it, shown past the divider. Labels and the handle's icon are yours.

import { ScCompare, ScCompareAfter, ScCompareBefore, ScCompareHandle, ScCompareLabel } from '@semantic-components/ui';
<div scCompare scFrame class="aspect-3/2">  <img scCompareBefore ngSrc="before.jpg" fill alt="…" />  <img scCompareAfter ngSrc="after.jpg" fill alt="…" />  <span scCompareLabel="before">Before</span>  <span scCompareLabel="after">After</span>  <div scCompareHandle aria-label="Before and after"><svg siChevronsLeftRightIcon></svg></div></div>

Dragging

  • With a mouse or a pen, a press anywhere moves the divider there and drags it; on a touch screen only the handle drags, so the page still scrolls over the photo (handleOnly: 'touch' by default; true everywhere, false nowhere).
  • hover: the divider follows the pointer, without a press. bounds: how close to the edges it goes.
  • The after is clipped at --sc-compare-position — no layout in script. Images and videos cover the box, so two of different sizes line up.

Keyboard

  • The arrows move the divider their way — as the text reads, and up or down when vertical — by step (1%); with Shift, ten steps.
  • Page Up / Page Down: ten percent up the slider and down; Home / End: to the ends.
  • Moved by the keys, the divider glides there — not under reduced motion; dragged, it follows at once.

Accessibility

  • The handle is a slider: name it. It reads its position as a percentage in the app's language; write your words in aria-valuetext ("30% before").
  • Give each photo its alt: they are two images.
  • Labels are your text; each fades while the divider covers its side.

Examples

Any content

Team plan

Everything in Pro, for up to ten people.

$49 / month

Start a trial

Team plan

Everything in Pro, for up to ten people.

$49 / month

Start a trial
LightDark
import { NgTemplateOutlet } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScCompare,  ScCompareAfter,  ScCompareBefore,  ScCompareHandle,  ScCompareLabel,  ScFrame,} from '@semantic-components/ui';

Vertical

Mountains at dawn, as shot: grey and flatThe same photo, edited: warm light and deep coloursBeforeAfter
import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScCompare,  ScCompareAfter,  ScCompareBefore,  ScCompareHandle,  ScCompareLabel,  ScFrame,} from '@semantic-components/ui';

Hover

Mountains at dawn, as shot: grey and flatThe same photo, edited: warm light and deep colours
import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import {  ScCompare,  ScCompareAfter,  ScCompareBefore,  ScCompareHandle,  ScFrame,} from '@semantic-components/ui';import { SiChevronsLeftRightIcon } from '@semantic-icons/lucide-icons';

Handle only, bounds and step

Mountains at dawn, as shot: grey and flatThe same photo, edited: warm light and deep coloursBeforeAfter

30% before

import { NgOptimizedImage } from '@angular/common';import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScCompare,  ScCompareAfter,  ScCompareBefore,  ScCompareHandle,  ScCompareLabel,  ScFrame,} from '@semantic-components/ui';

RTL

جبال عند الفجر، كما صُوّرتالصورة نفسها بعد التعديلقبلبعد
import { Dir } from '@angular/cdk/bidi';import { NgOptimizedImage } from '@angular/common';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import {  ScCompare,  ScCompareAfter,  ScCompareBefore,  ScCompareHandle,  ScCompareLabel,  ScFrame,

API reference

Each part takes class, merged over its own. The knob's and the labels' corners are the style's (compare); restyle the handle from its class — before: the line, after: the knob.

PartSelectorDescription
ScCompare[scCompare] The box: the position, dragging. exportAs: setPosition().
ScCompareBefore / After[scCompareBefore], [scCompareAfter] Your two things; the after clipped past the divider.
ScCompareLabel[scCompareLabel] "before" or "after": your text in its corner.
ScCompareHandle[scCompareHandle] The divider’s slider: line and knob, your icon inside.
InputTypeDefaultDescription
positionnumber50 Two-way: how much of the before shows, 0–100.
orientation'horizontal' | 'vertical''horizontal' Across, or up and down.
handleOnlyboolean | 'touch''touch' Only the handle drags: on touch screens, always, or never.
hoverbooleanfalse The divider follows the pointer.
boundsnumber0 How close to the edges it goes (%).
stepnumber1 An arrow key’s step (%); Shift: ten.