Compare side by side — Comparison block

Free

comparison-compare-side-by-side · for home, product, landing pages

Compare side by side

The two pictures whole, next to each other with "or" on the seam: two options or states to choose between, where a slider would hide half of each

Documentation

Installation

One command copies the block into your project with the shadcn CLI (the registry is set once: Installation).

pnpm dlx shadcn-vue@latest add @trame/comparison-compare-side-by-side

Usage

Its demo data, shortened (Using blocks).

<script setup lang="ts">
import ComparisonCompareSideBySide from '@/components/trame/blocks/comparison/comparison-compare-side-by-side.vue'

const props = {
title: "Before and after plant dyeing",
text: "The same T-shirts, photographed in the same spot, before and after a bath of madder and weld. Drag the slider to see the difference.",
before: {
image: "https://images.unsplash.com/photo-1705250466297-90035b3a2b26?w=1600&q=80&sat=-100",
alt: "Rolled-up T-shirts in undyed cotton",
label: "Before"
},
after: {
image: "https://images.unsplash.com/photo-1705250466297-90035b3a2b26?w=1600&q=80",
alt: "The same T-shirts, dyed from green to blue",
label: "After"
},
options: {
eyebrow: "Our workshop"
}
}
</script>

<template>
<ComparisonCompareSideBySide v-bind="props" />
</template>

Props

Each prop says who changes it: Words, Picture, Action, Design, Data.* required.

PropTypeDescription
title*stringWordswhat the visitor is invited to compare
before*Beforethe first picture: before, or the first option
after*Afterthe second picture: after, or the second option
textstringWordswhat changed, and how the business knows
optionsOptionsthe block’s settings: layout choices and secondary words, read by every variant
Before before · 3 props
PropTypeDescription
image*stringPicturea real picture of the subject, in the same frame as the other side
alt*stringWordswhat this picture shows
labelstringWordsthe chip on its side, plainly ("New", "After 800 km")
After after · 3 props
PropTypeDescription
image*stringPicturea real picture of the subject, in the same frame as the other side
alt*stringWordswhat this picture shows
labelstringWordsthe chip on its side, plainly ("New", "After 800 km")
Options options · 3 props
PropTypeDescription
eyebrowstringWordsa few words above the title
initialnumberwhere the split starts, in % from the left (50 by default); side by side, how the width is shared and which side a phone shows first
mood'inverse' | 'brand' | 'warm' | 'tint' | stringa band of the page that redefines the theme surfaces inside it
What it asks your app for

The block never knows your app: it asks it, through one context provided once, where its links lead, what its actions do, how a price reads and which words to say (The host context).

MemberWhat it is for
hrefthe address an action leads to, or null to hide what leads there
actruns a change (subscribe, add to cart, save) and answers { ok } or { ok: false, error }
canwhether the page has this action
asseta picture’s address as your app serves it
cartCountthe cart badge’s number
cartDrawerwhether your app has a cart drawer
cartOpenwhether the cart drawer is open
labelyour word for an interface key, or undefined to keep the block’s own

The words it says itself, in English and French; label(key) replaces any of them:

KeyEnglishFrench
newsletter.alreadyYou are already subscribed.Vous êtes déjà inscrit.
newsletter.doneDone: you are subscribed.C’est noté : vous êtes inscrit.
newsletter.invalidCheck the email address.Vérifiez l’adresse e-mail.
newsletter.tooManyToo many attempts, try again in a moment.Trop de tentatives, réessayez dans un moment.

Features

  • Every word in the server HTML
  • Same markup in Vue and React
  • Theme tokens only: every theme, light and dark
  • Shows what you give it, invents nothing
  • Subtle motion: one short reveal; still under reduced motion
  • Real buttons and links, a visible focus

A comparison section, for home, product, landing pages; it uses clsx, motion, tailwind-merge.

Built with

The components this block is made of; each one installs on its own too.

More comparison blocks

  • Before after count contrast: two huge figures (9 steps, then 3) with their lists under: when one number tells the story.
  • Before after pros cons: two panels, "for whom" tinted and "not for whom" quiet: an honest statement of fit.
  • Before after two lists: the old way struck through on the left, the new way framed on the right, totals underneath: step-by-step savings.
  • Cost bars: the merchant’s cost against another cost the merchant sourced, as two bars and a sentence: when a saving is real.
  • Fit matrix: options as columns and situations as rows with a mark per cell: compatibility, "this bag goes with…".
  • Head to head choice cards: 2 to 4 cards, each with its price, what it adds over the previous and its points: tiers, sizes and variants.
  • Head to head dimension rows: each criterion a row with the answers side by side in sentences: 3 to 6 dimensions that need words, not marks.
  • Head to head versus split: two panels, ours and the other, each a list of points grouped by theme: 4 to 8 points without a table feel.

All 15 comparison blocks