# Price cut

Subtle web animation sketch from [https://mighil.com/animations](https://mighil.com/animations).

- **Live demo:** https://mighil.com/animations/price-cut
- **Standalone HTML:** https://mighil.com/animations/price-cut?download=1
- **This file:** https://mighil.com/animations/price-cut/price-cut.md
- **Technique:** `commerce`

## What it does

Old price crosses out while the new one counts to $29.

## Instructions for AI / coding agents

Implement this micro-interaction in the user's stack (vanilla HTML, React, Vue, Svelte, etc.).

1. Use the **HTML** as the DOM structure (adapt JSX/templates as needed; keep class names and ids).
2. Include the **Theme** CSS (or map the same variables into the host design system). It switches light/dark with `prefers-color-scheme`.
3. Apply the **CSS** as-is when possible. It uses `var(--text-color)`, `var(--heading-color)`, `var(--background-color)`, etc. from the theme so both modes work.
4. Run the **JavaScript** after the markup mounts. Prefer `DOMContentLoaded` or a framework `useEffect` / `onMount`.
5. Keep motion respectful of `prefers-reduced-motion` if the snippet already checks it.
6. Do not depend on mighil.com runtime or fonts. Theme variables are enough for color.
7. If porting to a component, expose the interactive root via a ref and preserve accessibility attributes (`aria-*`, `role`, `button` types).

## Theme (auto light / dark)

```css
/* Auto light / dark — follows prefers-color-scheme */
:root{
  color-scheme: light dark;
  --text-color: hsl(0, 0%, 18%);
  --heading-color: hsl(0, 0%, 18%);
  --background-color: hsl(0, 0%, 99%);
  --bg-color: hsl(0, 0%, 99%);
  --link-color: hsl(0, 0%, 18%);
  --visited-color: hsl(0, 0%, 18%);
  --blockquote-color: hsl(0, 0%, 18%);
  --code-bg-color: hsl(0, 0%, 95%);
  --code-color: hsl(0, 0%, 18%);
  --sub-color: hsl(0, 0%, 29%);
}
@media (prefers-color-scheme: dark){
:root{
  --text-color: hsl(35, 25%, 85%);
  --heading-color: hsl(35.2, 32.6%, 82.5%);
  --background-color: hsl(60, 2.2%, 8.8%);
  --bg-color: hsl(60, 2.2%, 8.8%);
  --link-color: hsl(34.7, 55.3%, 79.8%);
  --visited-color: hsla(34.7, 55.3%, 79.8%, 0.85);
  --blockquote-color: hsl(35, 30%, 75%);
  --code-bg-color: hsl(30, 5%, 7.8%);
  --code-color: limegreen;
  --sub-color: hsla(34.7, 24.7%, 84.9%, 0.78);
}
}
```

## HTML

```html
<div class="price-cut" id="price-cut">
        <span class="was"><i class="strike" aria-hidden="true"></i>$48</span>
        <span class="now">$<b class="num">48</b></span>
      </div>
```

## CSS

```css
.price-cut{display:inline-flex;align-items:baseline;gap:10px;font-variant-numeric:tabular-nums}

.price-cut .was{
  position:relative;font-size:.95rem;color:color-mix(in srgb,var(--text-color) 45%,transparent);
}

.price-cut .strike{
  position:absolute;left:0;top:50%;height:1.5px;width:0;
  background:currentColor;transform:translateY(-50%);
  pointer-events:none;
}

.price-cut .now{
  font-size:1.25rem;font-weight:600;
  opacity:0;transform:translateY(6px);
  min-width:2.4ch;
}
```

## JavaScript

```js
document.querySelectorAll('[data-act]').forEach((btn) => {
    btn.addEventListener('click', (e) => {
      e.stopPropagation();
      const act = btn.getAttribute('data-act');
      if (act === 'price') runPrice();
    });
  });
```

---

_Source: https://mighil.com/animations/price-cut_
