# Tilt Card

Card that tilts in 3D toward the pointer with a moving glare and optional parallax layers, then eases back. Lifts on keyboard focus.

- Category: MarkasUI
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/tilt-card.json
- CLI: `npx markasui@latest add tilt-card`

## When to use

A few showcase cards that should feel tactile: membership or credit cards, featured products, profile or team cards, pricing highlights.

- Use one to three tilt cards per section; plain Card is better for dense grids
- Put background, border, radius, and padding classes on the component itself
- Add data-depth to one or two inner elements, such as an image or a chip, not to text blocks
- Never put the only copy of important information in the glare or depth layers

## Code

### Blade

Save at `resources/views/components/markas/tilt-card.blade.php`. Dependencies: alpinejs.

```blade
@props([
    'maxAngle' => 10,
    'glare' => true,
])

@php
    $base = 'group/tilt relative isolate rounded-xl transition-[transform,translate,scale,box-shadow] duration-500 ease-out [transform:perspective(800px)_rotateX(var(--tilt-x,0deg))_rotateY(var(--tilt-y,0deg))] has-[:focus-visible]:-translate-y-1 has-[:focus-visible]:shadow-overlay data-[state=active]:scale-[1.02] data-[state=active]:duration-150 motion-reduce:transition-none motion-reduce:[transform:none] [&_[data-depth]]:transition-[translate] [&_[data-depth]]:duration-500 [&_[data-depth]]:ease-out data-[state=active]:[&_[data-depth]]:duration-150 motion-reduce:[&_[data-depth]]:transition-none';
    $glareClass = 'pointer-events-none absolute inset-0 z-10 rounded-[inherit] bg-[radial-gradient(circle_at_var(--glare-x,50%)_var(--glare-y,50%),color-mix(in_oklab,var(--glare)_45%,transparent),transparent_65%)] opacity-0 transition-opacity duration-300 ease-out [--glare:var(--color-surface)] group-data-[state=active]/tilt:opacity-100 motion-reduce:hidden dark:[--glare:var(--color-ink)]';
@endphp

{{-- Rotates toward the pointer, moves the glare, and shifts [data-depth] layers by their value in px. --}}
<div
    wire:ignore.self
    x-data="{
        max: {{ (float) $maxAngle }},
        stop: null,
        layers() {
            return this.$root.querySelectorAll('[data-depth]');
        },
        tilt(card, rect, x, y) {
            const px = (x - rect.left) / rect.width - 0.5;
            const py = (y - rect.top) / rect.height - 0.5;
            card.dataset.state = 'active';
            card.style.setProperty('--tilt-x', `${-py * 2 * this.max}deg`);
            card.style.setProperty('--tilt-y', `${px * 2 * this.max}deg`);
            card.style.setProperty('--glare-x', `${(px + 0.5) * 100}%`);
            card.style.setProperty('--glare-y', `${(py + 0.5) * 100}%`);
            for (const layer of this.layers()) {
                const depth = Number(layer.dataset.depth) || 0;
                layer.style.translate = `${px * 2 * depth}px ${py * 2 * depth}px`;
            }
        },
        {{-- Follow the pointer against the flat box measured on enter; the tilted card's own edges move away and would flicker. --}}
        enter(event) {
            if (this.stop || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
            const card = this.$root;
            const rect = card.getBoundingClientRect();
            const move = ({ clientX: x, clientY: y }) => {
                if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom) return this.stop?.();
                this.tilt(card, rect, x, y);
            };
            this.stop = () => {
                this.stop = null;
                document.removeEventListener('pointermove', move);
                delete card.dataset.state;
                for (const prop of ['--tilt-x', '--tilt-y', '--glare-x', '--glare-y']) card.style.removeProperty(prop);
                for (const layer of this.layers()) layer.style.translate = '';
            };
            document.addEventListener('pointermove', move);
            move(event);
        },
        destroy() {
            this.stop?.();
        },
    }"
    x-on:pointerenter="enter($event)"
    {{ $attributes->class([$base]) }}
>
    {{ $slot }}
    @if ($glare)
        <span aria-hidden="true" class="{{ $glareClass }}"></span>
    @endif
</div>
```

```blade
<x-markas.tilt-card :max-angle="12" class="w-72 border border-line bg-surface p-5">
    <img data-depth="16" src="/img/headphones.png" alt="" class="rounded-lg" />
    <p class="mt-4 font-semibold">Studio headphones</p>
    <x-markas.button>Add to cart</x-markas.button>
</x-markas.tilt-card>
```

Needs Alpine.js.

### React

Save at `src/components/markas/TiltCard.tsx`. No extra dependencies.

```tsx
"use client";

import {
  useEffect,
  useRef,
  type ComponentProps,
  type PointerEvent,
} from "react";

const base =
  "group/tilt relative isolate rounded-xl transition-[transform,translate,scale,box-shadow] duration-500 ease-out [transform:perspective(800px)_rotateX(var(--tilt-x,0deg))_rotateY(var(--tilt-y,0deg))] has-[:focus-visible]:-translate-y-1 has-[:focus-visible]:shadow-overlay data-[state=active]:scale-[1.02] data-[state=active]:duration-150 motion-reduce:transition-none motion-reduce:[transform:none] [&_[data-depth]]:transition-[translate] [&_[data-depth]]:duration-500 [&_[data-depth]]:ease-out data-[state=active]:[&_[data-depth]]:duration-150 motion-reduce:[&_[data-depth]]:transition-none";
const glareClass =
  "pointer-events-none absolute inset-0 z-10 rounded-[inherit] bg-[radial-gradient(circle_at_var(--glare-x,50%)_var(--glare-y,50%),color-mix(in_oklab,var(--glare)_45%,transparent),transparent_65%)] opacity-0 transition-opacity duration-300 ease-out [--glare:var(--color-surface)] group-data-[state=active]/tilt:opacity-100 motion-reduce:hidden dark:[--glare:var(--color-ink)]";

const PROPS = ["--tilt-x", "--tilt-y", "--glare-x", "--glare-y"];

const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");
const still = () =>
  window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
const layers = (card: HTMLElement) =>
  card.querySelectorAll<HTMLElement>("[data-depth]");

/** Rotate toward the pointer, move the glare, and shift depth layers by their data-depth in px. */
function tilt(
  card: HTMLElement,
  rect: DOMRect,
  x: number,
  y: number,
  max: number,
) {
  const px = (x - rect.left) / rect.width - 0.5;
  const py = (y - rect.top) / rect.height - 0.5;
  card.dataset.state = "active";
  card.style.setProperty("--tilt-x", `${-py * 2 * max}deg`);
  card.style.setProperty("--tilt-y", `${px * 2 * max}deg`);
  card.style.setProperty("--glare-x", `${(px + 0.5) * 100}%`);
  card.style.setProperty("--glare-y", `${(py + 0.5) * 100}%`);
  for (const layer of layers(card)) {
    const depth = Number(layer.dataset.depth) || 0;
    layer.style.translate = `${px * 2 * depth}px ${py * 2 * depth}px`;
  }
}

/** Ease back to flat once the pointer leaves. */
function reset(card: HTMLElement) {
  delete card.dataset.state;
  for (const prop of PROPS) card.style.removeProperty(prop);
  for (const layer of layers(card)) layer.style.translate = "";
}

/**
 * Follow the pointer against the card's flat box, measured on enter. The tilted card's own edges
 * move away from the pointer, so its pointerleave would fire near the edges and make it flicker.
 */
function follow(card: HTMLElement, max: number, done: () => void) {
  const rect = card.getBoundingClientRect();
  const move = ({ clientX: x, clientY: y }: MouseEvent) => {
    if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom)
      return stop();
    tilt(card, rect, x, y, max);
  };
  const stop = () => {
    document.removeEventListener("pointermove", move);
    reset(card);
    done();
  };
  document.addEventListener("pointermove", move);
  return { move, stop };
}

export type TiltCardProps = ComponentProps<"div"> & {
  /** Largest rotation in degrees, reached at the card edges. */
  maxAngle?: number;
  /** Shows a soft light that follows the pointer. */
  glare?: boolean;
};

export function TiltCard({
  maxAngle = 10,
  glare = true,
  className,
  children,
  onPointerEnter,
  ...props
}: TiltCardProps) {
  const stop = useRef<(() => void) | null>(null);
  useEffect(() => () => stop.current?.(), []);
  return (
    <div
      {...props}
      className={cx(base, className)}
      onPointerEnter={(event: PointerEvent<HTMLDivElement>) => {
        if (!stop.current && !still()) {
          const tracker = follow(event.currentTarget, maxAngle, () => {
            stop.current = null;
          });
          stop.current = tracker.stop;
          tracker.move(event.nativeEvent);
        }
        onPointerEnter?.(event);
      }}
    >
      {children}
      {glare && <span aria-hidden="true" className={glareClass}></span>}
    </div>
  );
}
```

```tsx
import { TiltCard } from "@/components/markas/TiltCard";

<TiltCard maxAngle={12} className="w-72 border border-line bg-surface p-5">
  <img
    data-depth="16"
    src="/img/headphones.png"
    alt=""
    className="rounded-lg"
  />
  <p className="mt-4 font-semibold">Studio headphones</p>
</TiltCard>;
```

### Vue

Save at `src/components/markas/TiltCard.vue`. No extra dependencies.

```vue
<script setup lang="ts">
import { onBeforeUnmount } from "vue";

const props = withDefaults(
  defineProps<{
    /** Largest rotation in degrees, reached at the card edges. */
    maxAngle?: number;
    /** Shows a soft light that follows the pointer. */
    glare?: boolean;
  }>(),
  { maxAngle: 10, glare: true },
);

const base =
  "group/tilt relative isolate rounded-xl transition-[transform,translate,scale,box-shadow] duration-500 ease-out [transform:perspective(800px)_rotateX(var(--tilt-x,0deg))_rotateY(var(--tilt-y,0deg))] has-[:focus-visible]:-translate-y-1 has-[:focus-visible]:shadow-overlay data-[state=active]:scale-[1.02] data-[state=active]:duration-150 motion-reduce:transition-none motion-reduce:[transform:none] [&_[data-depth]]:transition-[translate] [&_[data-depth]]:duration-500 [&_[data-depth]]:ease-out data-[state=active]:[&_[data-depth]]:duration-150 motion-reduce:[&_[data-depth]]:transition-none";
const glareClass =
  "pointer-events-none absolute inset-0 z-10 rounded-[inherit] bg-[radial-gradient(circle_at_var(--glare-x,50%)_var(--glare-y,50%),color-mix(in_oklab,var(--glare)_45%,transparent),transparent_65%)] opacity-0 transition-opacity duration-300 ease-out [--glare:var(--color-surface)] group-data-[state=active]/tilt:opacity-100 motion-reduce:hidden dark:[--glare:var(--color-ink)]";

const PROPS = ["--tilt-x", "--tilt-y", "--glare-x", "--glare-y"];

const still = () =>
  window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
const layers = (card: HTMLElement) =>
  card.querySelectorAll<HTMLElement>("[data-depth]");

/** Rotate toward the pointer, move the glare, and shift depth layers by their data-depth in px. */
function tilt(card: HTMLElement, rect: DOMRect, x: number, y: number) {
  const max = props.maxAngle;
  const px = (x - rect.left) / rect.width - 0.5;
  const py = (y - rect.top) / rect.height - 0.5;
  card.dataset.state = "active";
  card.style.setProperty("--tilt-x", `${-py * 2 * max}deg`);
  card.style.setProperty("--tilt-y", `${px * 2 * max}deg`);
  card.style.setProperty("--glare-x", `${(px + 0.5) * 100}%`);
  card.style.setProperty("--glare-y", `${(py + 0.5) * 100}%`);
  for (const layer of layers(card)) {
    const depth = Number(layer.dataset.depth) || 0;
    layer.style.translate = `${px * 2 * depth}px ${py * 2 * depth}px`;
  }
}

let stop: (() => void) | null = null;
onBeforeUnmount(() => stop?.());

/**
 * Follow the pointer against the card's flat box, measured on enter. The tilted card's own edges
 * move away from the pointer, so its pointerleave would fire near the edges and make it flicker.
 */
function enter(event: PointerEvent) {
  if (stop || still()) return;
  const card = event.currentTarget as HTMLElement;
  const rect = card.getBoundingClientRect();
  const move = ({ clientX: x, clientY: y }: MouseEvent) => {
    if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom)
      return stop?.();
    tilt(card, rect, x, y);
  };
  stop = () => {
    stop = null;
    document.removeEventListener("pointermove", move);
    delete card.dataset.state;
    for (const prop of PROPS) card.style.removeProperty(prop);
    for (const layer of layers(card)) layer.style.translate = "";
  };
  document.addEventListener("pointermove", move);
  move(event);
}
</script>

<template>
  <div :class="base" @pointerenter="enter">
    <slot />
    <span v-if="props.glare" aria-hidden="true" :class="glareClass"></span>
  </div>
</template>
```

```vue
<template>
  <TiltCard :max-angle="12" class="w-72 border border-line bg-surface p-5">
    <img data-depth="16" src="/img/headphones.png" alt="" class="rounded-lg" />
    <p class="mt-4 font-semibold">Studio headphones</p>
  </TiltCard>
</template>
```

### Svelte

Save at `src/lib/components/markas/TiltCard.svelte`. No extra dependencies.

```svelte
<script lang="ts">
  import type { Snippet } from "svelte";
  import type { HTMLAttributes } from "svelte/elements";

  const base =
    "group/tilt relative isolate rounded-xl transition-[transform,translate,scale,box-shadow] duration-500 ease-out [transform:perspective(800px)_rotateX(var(--tilt-x,0deg))_rotateY(var(--tilt-y,0deg))] has-[:focus-visible]:-translate-y-1 has-[:focus-visible]:shadow-overlay data-[state=active]:scale-[1.02] data-[state=active]:duration-150 motion-reduce:transition-none motion-reduce:[transform:none] [&_[data-depth]]:transition-[translate] [&_[data-depth]]:duration-500 [&_[data-depth]]:ease-out data-[state=active]:[&_[data-depth]]:duration-150 motion-reduce:[&_[data-depth]]:transition-none";
  const glareClass =
    "pointer-events-none absolute inset-0 z-10 rounded-[inherit] bg-[radial-gradient(circle_at_var(--glare-x,50%)_var(--glare-y,50%),color-mix(in_oklab,var(--glare)_45%,transparent),transparent_65%)] opacity-0 transition-opacity duration-300 ease-out [--glare:var(--color-surface)] group-data-[state=active]/tilt:opacity-100 motion-reduce:hidden dark:[--glare:var(--color-ink)]";

  const PROPS = ["--tilt-x", "--tilt-y", "--glare-x", "--glare-y"];

  const still = () =>
    window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
  const layers = (card: HTMLElement) =>
    card.querySelectorAll<HTMLElement>("[data-depth]");

  /** Rotate toward the pointer, move the glare, and shift depth layers by their data-depth in px. */
  function tilt(
    card: HTMLElement,
    rect: DOMRect,
    x: number,
    y: number,
    max: number,
  ) {
    const px = (x - rect.left) / rect.width - 0.5;
    const py = (y - rect.top) / rect.height - 0.5;
    card.dataset.state = "active";
    card.style.setProperty("--tilt-x", `${-py * 2 * max}deg`);
    card.style.setProperty("--tilt-y", `${px * 2 * max}deg`);
    card.style.setProperty("--glare-x", `${(px + 0.5) * 100}%`);
    card.style.setProperty("--glare-y", `${(py + 0.5) * 100}%`);
    for (const layer of layers(card)) {
      const depth = Number(layer.dataset.depth) || 0;
      layer.style.translate = `${px * 2 * depth}px ${py * 2 * depth}px`;
    }
  }

  type Props = HTMLAttributes<HTMLDivElement> & {
    /** Largest rotation in degrees, reached at the card edges. */
    maxAngle?: number;
    /** Shows a soft light that follows the pointer. */
    glare?: boolean;
    children?: Snippet;
  };

  let {
    maxAngle = 10,
    glare = true,
    class: className,
    children,
    onpointerenter,
    ...rest
  }: Props = $props();

  let stop: (() => void) | null = null;

  $effect(() => () => stop?.());

  /**
   * Follow the pointer against the card's flat box, measured on enter. The tilted card's own edges
   * move away from the pointer, so its pointerleave would fire near the edges and make it flicker.
   */
  function enter(event: PointerEvent & { currentTarget: HTMLDivElement }) {
    if (!stop && !still()) {
      const card = event.currentTarget;
      const rect = card.getBoundingClientRect();
      const max = maxAngle;
      const move = ({ clientX: x, clientY: y }: MouseEvent) => {
        if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom)
          return stop?.();
        tilt(card, rect, x, y, max);
      };
      stop = () => {
        stop = null;
        document.removeEventListener("pointermove", move);
        delete card.dataset.state;
        for (const prop of PROPS) card.style.removeProperty(prop);
        for (const layer of layers(card)) layer.style.translate = "";
      };
      document.addEventListener("pointermove", move);
      move(event);
    }
    onpointerenter?.(event);
  }
</script>

<div {...rest} class={[base, className]} onpointerenter={enter}>
  {@render children?.()}
  {#if glare}
    <span aria-hidden="true" class={glareClass}></span>
  {/if}
</div>
```

```svelte
<script lang="ts">
  import TiltCard from "$lib/components/markas/TiltCard.svelte";
</script>

<TiltCard maxAngle={8} class="border border-line bg-surface p-6">
  <div data-depth="20">Pro plan</div>
</TiltCard>
```

### Astro

Save at `src/components/markas/TiltCard.astro`. No extra dependencies.

```astro
---
import type { HTMLAttributes } from "astro/types";

const base =
  "group/tilt relative isolate rounded-xl transition-[transform,translate,scale,box-shadow] duration-500 ease-out [transform:perspective(800px)_rotateX(var(--tilt-x,0deg))_rotateY(var(--tilt-y,0deg))] has-[:focus-visible]:-translate-y-1 has-[:focus-visible]:shadow-overlay data-[state=active]:scale-[1.02] data-[state=active]:duration-150 motion-reduce:transition-none motion-reduce:[transform:none] [&_[data-depth]]:transition-[translate] [&_[data-depth]]:duration-500 [&_[data-depth]]:ease-out data-[state=active]:[&_[data-depth]]:duration-150 motion-reduce:[&_[data-depth]]:transition-none";
const glareClass =
  "pointer-events-none absolute inset-0 z-10 rounded-[inherit] bg-[radial-gradient(circle_at_var(--glare-x,50%)_var(--glare-y,50%),color-mix(in_oklab,var(--glare)_45%,transparent),transparent_65%)] opacity-0 transition-opacity duration-300 ease-out [--glare:var(--color-surface)] group-data-[state=active]/tilt:opacity-100 motion-reduce:hidden dark:[--glare:var(--color-ink)]";

type Props = HTMLAttributes<"div"> & {
  /** Largest rotation in degrees, reached at the card edges. */
  maxAngle?: number;
  /** Shows a soft light that follows the pointer. */
  glare?: boolean;
};

const { maxAngle = 10, glare = true, class: className, ...rest } = Astro.props;
---

<div
  {...rest}
  class:list={[base, className]}
  data-markas-tilt-card={Number(maxAngle)}
>
  <slot />
  {glare && <span aria-hidden="true" class={glareClass}></span>}
</div>

<script>
  // One listener per page serves every card, including markup added later and pages reached
  // through view transitions. pointerenter does not bubble, so it is caught in the capture phase.
  const PROPS = ["--tilt-x", "--tilt-y", "--glare-x", "--glare-y"];
  const active = new Set<HTMLElement>();

  const layers = (card: HTMLElement) =>
    card.querySelectorAll<HTMLElement>("[data-depth]");

  /** Rotate toward the pointer, move the glare, and shift depth layers by their data-depth in px. */
  function tilt(card: HTMLElement, rect: DOMRect, x: number, y: number) {
    const max = Number(card.dataset.markasTiltCard);
    const px = (x - rect.left) / rect.width - 0.5;
    const py = (y - rect.top) / rect.height - 0.5;
    card.dataset.state = "active";
    card.style.setProperty("--tilt-x", `${-py * 2 * max}deg`);
    card.style.setProperty("--tilt-y", `${px * 2 * max}deg`);
    card.style.setProperty("--glare-x", `${(px + 0.5) * 100}%`);
    card.style.setProperty("--glare-y", `${(py + 0.5) * 100}%`);
    for (const layer of layers(card)) {
      const depth = Number(layer.dataset.depth) || 0;
      layer.style.translate = `${px * 2 * depth}px ${py * 2 * depth}px`;
    }
  }

  /**
   * Follow the pointer against the card's flat box, measured on enter. The tilted card's own edges
   * move away from the pointer, so its pointerleave would fire near the edges and make it flicker.
   */
  function enter(card: HTMLElement, event: PointerEvent) {
    if (active.has(card)) return;
    if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return;
    const rect = card.getBoundingClientRect();
    const stop = () => {
      active.delete(card);
      document.removeEventListener("pointermove", move);
      delete card.dataset.state;
      for (const prop of PROPS) card.style.removeProperty(prop);
      for (const layer of layers(card)) layer.style.translate = "";
    };
    const move = ({ clientX: x, clientY: y }: MouseEvent) => {
      if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom)
        return stop();
      tilt(card, rect, x, y);
    };
    active.add(card);
    document.addEventListener("pointermove", move);
    move(event);
  }

  document.addEventListener(
    "pointerenter",
    (event) => {
      const target = event.target;
      if (target instanceof HTMLElement && target.hasAttribute("data-markas-tilt-card"))
        enter(target, event as PointerEvent);
    },
    true,
  );
</script>
```

```astro
---
import TiltCard from "@/components/markas/TiltCard.astro";
---

<TiltCard maxAngle={8} class="border border-line bg-surface p-6">
  <div data-depth="20">Pro plan</div>
</TiltCard>
```

One small bundled script serves every card on the page.

### Angular

Save at `src/app/markas/tilt-card.component.ts`. No extra dependencies.

```ts
import {
  ChangeDetectionStrategy,
  Component,
  computed,
  DestroyRef,
  inject,
  input,
  booleanAttribute,
  numberAttribute,
} from "@angular/core";

const base =
  "group/tilt relative isolate rounded-xl transition-[transform,translate,scale,box-shadow] duration-500 ease-out [transform:perspective(800px)_rotateX(var(--tilt-x,0deg))_rotateY(var(--tilt-y,0deg))] has-[:focus-visible]:-translate-y-1 has-[:focus-visible]:shadow-overlay data-[state=active]:scale-[1.02] data-[state=active]:duration-150 motion-reduce:transition-none motion-reduce:[transform:none] [&_[data-depth]]:transition-[translate] [&_[data-depth]]:duration-500 [&_[data-depth]]:ease-out data-[state=active]:[&_[data-depth]]:duration-150 motion-reduce:[&_[data-depth]]:transition-none";
const glareClass =
  "pointer-events-none absolute inset-0 z-10 rounded-[inherit] bg-[radial-gradient(circle_at_var(--glare-x,50%)_var(--glare-y,50%),color-mix(in_oklab,var(--glare)_45%,transparent),transparent_65%)] opacity-0 transition-opacity duration-300 ease-out [--glare:var(--color-surface)] group-data-[state=active]/tilt:opacity-100 motion-reduce:hidden dark:[--glare:var(--color-ink)]";

const PROPS = ["--tilt-x", "--tilt-y", "--glare-x", "--glare-y"];

const still = () =>
  window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
const layers = (card: HTMLElement) =>
  card.querySelectorAll<HTMLElement>("[data-depth]");

/** Rotate toward the pointer, move the glare, and shift depth layers by their data-depth in px. */
function tilt(
  card: HTMLElement,
  rect: DOMRect,
  x: number,
  y: number,
  max: number,
) {
  const px = (x - rect.left) / rect.width - 0.5;
  const py = (y - rect.top) / rect.height - 0.5;
  card.dataset.state = "active";
  card.style.setProperty("--tilt-x", `${-py * 2 * max}deg`);
  card.style.setProperty("--tilt-y", `${px * 2 * max}deg`);
  card.style.setProperty("--glare-x", `${(px + 0.5) * 100}%`);
  card.style.setProperty("--glare-y", `${(py + 0.5) * 100}%`);
  for (const layer of layers(card)) {
    const depth = Number(layer.dataset.depth) || 0;
    layer.style.translate = `${px * 2 * depth}px ${py * 2 * depth}px`;
  }
}

/** The host stays out of layout; the user's class lands on the card. */
@Component({
  selector: "markas-tilt-card",
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: "contents" },
  template: `
    <div [class]="classes()" (pointerenter)="enter($event)">
      <ng-content />
      @if (glare()) {
        <span aria-hidden="true" [class]="glareClass"></span>
      }
    </div>
  `,
})
export class TiltCard {
  /** Largest rotation in degrees, reached at the card edges. */
  readonly maxAngle = input(10, { transform: numberAttribute });
  /** Shows a soft light that follows the pointer. */
  readonly glare = input(true, { transform: booleanAttribute });
  readonly userClass = input("", { alias: "class" });

  protected readonly glareClass = glareClass;
  protected readonly classes = computed(() =>
    [base, this.userClass()].filter(Boolean).join(" "),
  );
  private stop: (() => void) | null = null;

  constructor() {
    inject(DestroyRef).onDestroy(() => this.stop?.());
  }

  /**
   * Follow the pointer against the card's flat box, measured on enter. The tilted card's own edges
   * move away from the pointer, so its pointerleave would fire near the edges and make it flicker.
   */
  protected enter(event: PointerEvent) {
    if (this.stop || still()) return;
    const card = event.currentTarget as HTMLElement;
    const rect = card.getBoundingClientRect();
    const max = this.maxAngle();
    const move = ({ clientX: x, clientY: y }: MouseEvent) => {
      if (x < rect.left || x > rect.right || y < rect.top || y > rect.bottom)
        return this.stop?.();
      tilt(card, rect, x, y, max);
    };
    this.stop = () => {
      this.stop = null;
      document.removeEventListener("pointermove", move);
      delete card.dataset.state;
      for (const prop of PROPS) card.style.removeProperty(prop);
      for (const layer of layers(card)) layer.style.translate = "";
    };
    document.addEventListener("pointermove", move);
    move(event);
  }
}
```

```ts
import { Component } from "@angular/core";
import { TiltCard } from "./markas/tilt-card.component";

@Component({
  selector: "app-plan",
  imports: [TiltCard],
  template: `
    <markas-tilt-card [maxAngle]="8" class="border border-line bg-surface p-6">
      <div data-depth="20">Pro plan</div>
    </markas-tilt-card>
  `,
})
export class Plan {}
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `maxAngle` | `number` | 10 | Largest rotation in degrees, reached when the pointer is at a card edge. 4 to 8 feels subtle, 12 to 15 playful. |
| `glare` | `boolean` | true | Shows a soft light that follows the pointer across the card. |
| `children / slot` | `ReactNode / slot` | - | Card content. Style the card with your own classes (background, border, padding). Children with data-depth="16" shift up to that many px for parallax. |

## Accessibility

- The tilt, glare, and parallax are visual only; the glare is an aria-hidden layer that never catches the pointer.
- When a link or button inside the card has keyboard focus, the card lifts slightly so the focus is easy to follow.
- With reduced motion the card stays flat and still, with no glare.

## Notes

- The card rotates up to `maxAngle` degrees toward the pointer through the `--tilt-x` and `--tilt-y` custom properties, and eases back when the pointer leaves.
- Children with `data-depth="16"` shift up to 16px for parallax. Use it on one or two elements.
- Keyboard focus on a link or button inside lifts the card slightly. With reduced motion the card stays flat.
- `glare={false}` removes the moving light. Attributes and `class` go to the card itself.
