StealThis .dev

Metric Comparison

A before/after metric comparison widget that highlights the difference between two values with an animated transition bar, percentage change label, and color-coded improvement/regression indicators.

Open in Lab
css react tailwind vue svelte
Targets: TS JS HTML React Vue Svelte

Code

Features

  • Before / After bars — two progress bars with animated width fill
  • Delta badge — absolute and percentage change highlighted in green/red
  • Animated transition — bars animate from before to after on load
  • Multiple metrics — support for comparing several metrics in a grid
  • Labels — configurable period labels (e.g., “This month” vs “Last month”)

How it works

  1. Both bars are CSS width transitions triggered on mount via requestAnimationFrame
  2. Delta is computed as (after - before) / before * 100 and rounded
  3. Positive delta gets green; negative gets red with a ▼ indicator
  4. Bars share a common max value so relative proportions are preserved