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.
Usage
Usage

BeforeAfterimport { 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;trueeverywhere,falsenowhere). 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
import { NgTemplateOutlet } from '@angular/common';import { Component, ViewEncapsulation } from '@angular/core';import { ScCompare, ScCompareAfter, ScCompareBefore, ScCompareHandle, ScCompareLabel, ScFrame,} from '@semantic-components/ui';Vertical

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


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

BeforeAfter30% 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.
| Part | Selector | Description |
|---|---|---|
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. |
| Input | Type | Default | Description |
|---|---|---|---|
position | number | 50 | Two-way: how much of the before shows, 0–100. |
orientation | 'horizontal' | 'vertical' | 'horizontal' | Across, or up and down. |
handleOnly | boolean | 'touch' | 'touch' | Only the handle drags: on touch screens, always, or never. |
hover | boolean | false | The divider follows the pointer. |
bounds | number | 0 | How close to the edges it goes (%). |
step | number | 1 | An arrow key’s step (%); Shift: ten. |