Card that tilts in 3D toward the pointer with a moving glare and optional parallax layers, then eases back. Lifts on keyboard focus.
0042 1987 5531
MemberRania Putri
Since2021
0042 1987 5531
MemberRania Putri
Since2021
0042 1987 5531
MemberRania Putri
Since2021
0042 1987 5531
MemberRania Putri
Since2021
0042 1987 5531
MemberRania Putri
Since2021
@php
$stage = 'grid place-items-center py-8';
$card = 'grid aspect-[1.586/1] w-80 content-between bg-linear-to-br from-primary to-primary-strong p-6 text-on-primary';
$row = 'flex items-center justify-between';
$brand = 'text-base font-semibold';
$tier = 'rounded-full bg-on-primary/15 px-2.5 py-0.5 text-xs font-medium';
$chip = 'h-8 w-11 rounded-md bg-linear-to-br from-warning to-warning/50';
$number = 'text-lg font-medium tracking-widest tabular-nums';
$footer = 'flex items-end justify-between text-sm font-medium';
$caption = 'block text-xs font-normal text-on-primary/70';
@endphp
<div class="{{ $stage }}">
<x-markas.tilt-card :class="$card">
<div class="{{ $row }}">
<span class="{{ $brand }}">Markas</span>
<span class="{{ $tier }}">Gold member</span>
</div>
<div data-depth="14" class="{{ $chip }}"></div>
<p data-depth="8" class="{{ $number }}">0042 1987 5531</p>
<div class="{{ $footer }}">
<p><span class="{{ $caption }}">Member</span>Rania Putri</p>
<p><span class="{{ $caption }}">Since</span>2021</p>
</div>
</x-markas.tilt-card>
</div>import { TiltCard } from "@/components/markas/TiltCard";
const stage = "grid place-items-center py-8";
const card =
"grid aspect-[1.586/1] w-80 content-between bg-linear-to-br from-primary to-primary-strong p-6 text-on-primary";
const row = "flex items-center justify-between";
const brand = "text-base font-semibold";
const tier = "rounded-full bg-on-primary/15 px-2.5 py-0.5 text-xs font-medium";
const chip = "h-8 w-11 rounded-md bg-linear-to-br from-warning to-warning/50";
const number = "text-lg font-medium tracking-widest tabular-nums";
const footer = "flex items-end justify-between text-sm font-medium";
const caption = "block text-xs font-normal text-on-primary/70";
export default function TiltCardExample() {
return (
<div className={stage}>
<TiltCard className={card}>
<div className={row}>
<span className={brand}>Markas</span>
<span className={tier}>Gold member</span>
</div>
<div data-depth="14" className={chip}></div>
<p data-depth="8" className={number}>
0042 1987 5531
</p>
<div className={footer}>
<p>
<span className={caption}>Member</span>Rania Putri
</p>
<p>
<span className={caption}>Since</span>2021
</p>
</div>
</TiltCard>
</div>
);
}<script setup lang="ts">
import TiltCard from "@/components/markas/TiltCard.vue";
const stage = "grid place-items-center py-8";
const card =
"grid aspect-[1.586/1] w-80 content-between bg-linear-to-br from-primary to-primary-strong p-6 text-on-primary";
const row = "flex items-center justify-between";
const brand = "text-base font-semibold";
const tier = "rounded-full bg-on-primary/15 px-2.5 py-0.5 text-xs font-medium";
const chip = "h-8 w-11 rounded-md bg-linear-to-br from-warning to-warning/50";
const number = "text-lg font-medium tracking-widest tabular-nums";
const footer = "flex items-end justify-between text-sm font-medium";
const caption = "block text-xs font-normal text-on-primary/70";
</script>
<template>
<div :class="stage">
<TiltCard :class="card">
<div :class="row">
<span :class="brand">Markas</span>
<span :class="tier">Gold member</span>
</div>
<div data-depth="14" :class="chip"></div>
<p data-depth="8" :class="number">0042 1987 5531</p>
<div :class="footer">
<p><span :class="caption">Member</span>Rania Putri</p>
<p><span :class="caption">Since</span>2021</p>
</div>
</TiltCard>
</div>
</template><script lang="ts">
import TiltCard from "$lib/components/markas/TiltCard.svelte";
const stage = "grid place-items-center py-8";
const card =
"grid aspect-[1.586/1] w-80 content-between bg-linear-to-br from-primary to-primary-strong p-6 text-on-primary";
const row = "flex items-center justify-between";
const brand = "text-base font-semibold";
const tier =
"rounded-full bg-on-primary/15 px-2.5 py-0.5 text-xs font-medium";
const chip = "h-8 w-11 rounded-md bg-linear-to-br from-warning to-warning/50";
const number = "text-lg font-medium tracking-widest tabular-nums";
const footer = "flex items-end justify-between text-sm font-medium";
const caption = "block text-xs font-normal text-on-primary/70";
</script>
<div class={stage}>
<TiltCard class={card}>
<div class={row}>
<span class={brand}>Markas</span>
<span class={tier}>Gold member</span>
</div>
<div data-depth="14" class={chip}></div>
<p data-depth="8" class={number}>0042 1987 5531</p>
<div class={footer}>
<p><span class={caption}>Member</span>Rania Putri</p>
<p><span class={caption}>Since</span>2021</p>
</div>
</TiltCard>
</div>---
import TiltCard from "@/components/markas/TiltCard.astro";
const stage = "grid place-items-center py-8";
const card =
"grid aspect-[1.586/1] w-80 content-between bg-linear-to-br from-primary to-primary-strong p-6 text-on-primary";
const row = "flex items-center justify-between";
const brand = "text-base font-semibold";
const tier = "rounded-full bg-on-primary/15 px-2.5 py-0.5 text-xs font-medium";
const chip = "h-8 w-11 rounded-md bg-linear-to-br from-warning to-warning/50";
const number = "text-lg font-medium tracking-widest tabular-nums";
const footer = "flex items-end justify-between text-sm font-medium";
const caption = "block text-xs font-normal text-on-primary/70";
---
<div class={stage}>
<TiltCard class={card}>
<div class={row}>
<span class={brand}>Markas</span>
<span class={tier}>Gold member</span>
</div>
<div data-depth="14" class={chip}></div>
<p data-depth="8" class={number}>0042 1987 5531</p>
<div class={footer}>
<p><span class={caption}>Member</span>Rania Putri</p>
<p><span class={caption}>Since</span>2021</p>
</div>
</TiltCard>
</div>import { Component } from "@angular/core";
import { TiltCard } from "./markas/tilt-card.component";
@Component({
selector: "markas-example",
imports: [TiltCard],
template: `
<div [class]="stage">
<markas-tilt-card [class]="card">
<div [class]="row">
<span [class]="brand">Markas</span>
<span [class]="tier">Gold member</span>
</div>
<div data-depth="14" [class]="chip"></div>
<p data-depth="8" [class]="number">0042 1987 5531</p>
<div [class]="footer">
<p><span [class]="caption">Member</span>Rania Putri</p>
<p><span [class]="caption">Since</span>2021</p>
</div>
</markas-tilt-card>
</div>
`,
})
export default class TiltCardExample {
protected readonly stage = "grid place-items-center py-8";
protected readonly card =
"grid aspect-[1.586/1] w-80 content-between bg-linear-to-br from-primary to-primary-strong p-6 text-on-primary";
protected readonly row = "flex items-center justify-between";
protected readonly brand = "text-base font-semibold";
protected readonly tier =
"rounded-full bg-on-primary/15 px-2.5 py-0.5 text-xs font-medium";
protected readonly chip =
"h-8 w-11 rounded-md bg-linear-to-br from-warning to-warning/50";
protected readonly number =
"text-lg font-medium tracking-widest tabular-nums";
protected readonly footer =
"flex items-end justify-between text-sm font-medium";
protected readonly caption = "block text-xs font-normal text-on-primary/70";
}Examples
Product card with parallax image
Studio headphones
Wireless, 40 hour battery
Studio headphones
Wireless, 40 hour battery
Studio headphones
Wireless, 40 hour battery
Studio headphones
Wireless, 40 hour battery
Studio headphones
Wireless, 40 hour battery
@php
$stage = 'grid place-items-center py-6';
$card = 'w-64 border border-line bg-surface p-4';
$image = 'grid h-36 place-items-center rounded-lg bg-linear-to-br from-primary-soft to-warning/25 text-ink';
$icon = 'size-14';
$title = 'mt-4 text-base font-semibold text-ink';
$text = 'mt-0.5 text-sm text-muted';
$row = 'mt-4 flex items-center justify-between';
$price = 'text-base font-semibold text-ink';
$button = 'inline-flex h-9 items-center rounded-lg bg-primary px-3 text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none';
@endphp
<div class="{{ $stage }}">
<x-markas.tilt-card :max-angle="12" :class="$card">
<div data-depth="18" class="{{ $image }}">
<svg class="{{ $icon }}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 18v-6a9 9 0 0 1 18 0v6M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z" /></svg>
</div>
<p class="{{ $title }}">Studio headphones</p>
<p class="{{ $text }}">Wireless, 40 hour battery</p>
<div class="{{ $row }}">
<span class="{{ $price }}">$129</span>
<button type="button" class="{{ $button }}">Add to cart</button>
</div>
</x-markas.tilt-card>
</div>import { TiltCard } from "@/components/markas/TiltCard";
const stage = "grid place-items-center py-6";
const card = "w-64 border border-line bg-surface p-4";
const image =
"grid h-36 place-items-center rounded-lg bg-linear-to-br from-primary-soft to-warning/25 text-ink";
const icon = "size-14";
const title = "mt-4 text-base font-semibold text-ink";
const text = "mt-0.5 text-sm text-muted";
const row = "mt-4 flex items-center justify-between";
const price = "text-base font-semibold text-ink";
const button =
"inline-flex h-9 items-center rounded-lg bg-primary px-3 text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
export default function Example() {
return (
<div className={stage}>
<TiltCard maxAngle={12} className={card}>
<div data-depth="18" className={image}>
<svg
className={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<path d="M3 18v-6a9 9 0 0 1 18 0v6M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z" />
</svg>
</div>
<p className={title}>Studio headphones</p>
<p className={text}>Wireless, 40 hour battery</p>
<div className={row}>
<span className={price}>$129</span>
<button type="button" className={button}>
Add to cart
</button>
</div>
</TiltCard>
</div>
);
}<script setup lang="ts">
import TiltCard from "@/components/markas/TiltCard.vue";
const stage = "grid place-items-center py-6";
const card = "w-64 border border-line bg-surface p-4";
const image =
"grid h-36 place-items-center rounded-lg bg-linear-to-br from-primary-soft to-warning/25 text-ink";
const icon = "size-14";
const title = "mt-4 text-base font-semibold text-ink";
const text = "mt-0.5 text-sm text-muted";
const row = "mt-4 flex items-center justify-between";
const price = "text-base font-semibold text-ink";
const button =
"inline-flex h-9 items-center rounded-lg bg-primary px-3 text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
</script>
<template>
<div :class="stage">
<TiltCard :max-angle="12" :class="card">
<div data-depth="18" :class="image">
<svg
:class="icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path
d="M3 18v-6a9 9 0 0 1 18 0v6M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"
/>
</svg>
</div>
<p :class="title">Studio headphones</p>
<p :class="text">Wireless, 40 hour battery</p>
<div :class="row">
<span :class="price">$129</span>
<button type="button" :class="button">Add to cart</button>
</div>
</TiltCard>
</div>
</template><script lang="ts">
import TiltCard from "$lib/components/markas/TiltCard.svelte";
const stage = "grid place-items-center py-6";
const card = "w-64 border border-line bg-surface p-4";
const image =
"grid h-36 place-items-center rounded-lg bg-linear-to-br from-primary-soft to-warning/25 text-ink";
const icon = "size-14";
const title = "mt-4 text-base font-semibold text-ink";
const text = "mt-0.5 text-sm text-muted";
const row = "mt-4 flex items-center justify-between";
const price = "text-base font-semibold text-ink";
const button =
"inline-flex h-9 items-center rounded-lg bg-primary px-3 text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
</script>
<div class={stage}>
<TiltCard maxAngle={12} class={card}>
<div data-depth="18" class={image}>
<svg
class={icon}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path
d="M3 18v-6a9 9 0 0 1 18 0v6M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"
/>
</svg>
</div>
<p class={title}>Studio headphones</p>
<p class={text}>Wireless, 40 hour battery</p>
<div class={row}>
<span class={price}>$129</span>
<button type="button" class={button}>Add to cart</button>
</div>
</TiltCard>
</div>---
import TiltCard from "@/components/markas/TiltCard.astro";
const stage = "grid place-items-center py-6";
const card = "w-64 border border-line bg-surface p-4";
const image =
"grid h-36 place-items-center rounded-lg bg-linear-to-br from-primary-soft to-warning/25 text-ink";
const icon = "size-14";
const title = "mt-4 text-base font-semibold text-ink";
const text = "mt-0.5 text-sm text-muted";
const row = "mt-4 flex items-center justify-between";
const price = "text-base font-semibold text-ink";
const button =
"inline-flex h-9 items-center rounded-lg bg-primary px-3 text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
---
<div class={stage}>
<TiltCard maxAngle={12} class={card}>
<div data-depth="18" class={image}>
<svg class={icon} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M3 18v-6a9 9 0 0 1 18 0v6M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z" />
</svg>
</div>
<p class={title}>Studio headphones</p>
<p class={text}>Wireless, 40 hour battery</p>
<div class={row}>
<span class={price}>$129</span>
<button type="button" class={button}>Add to cart</button>
</div>
</TiltCard>
</div>import { Component } from "@angular/core";
import { TiltCard } from "./markas/tilt-card.component";
@Component({
selector: "markas-example",
imports: [TiltCard],
template: `
<div [class]="stage">
<markas-tilt-card [maxAngle]="12" [class]="card">
<div data-depth="18" [class]="image">
<svg
[class]="icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path
d="M3 18v-6a9 9 0 0 1 18 0v6M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"
/>
</svg>
</div>
<p [class]="title">Studio headphones</p>
<p [class]="text">Wireless, 40 hour battery</p>
<div [class]="row">
<span [class]="price">$129</span>
<button type="button" [class]="button">Add to cart</button>
</div>
</markas-tilt-card>
</div>
`,
})
export default class TiltCardProductExample {
protected readonly stage = "grid place-items-center py-6";
protected readonly card = "w-64 border border-line bg-surface p-4";
protected readonly image =
"grid h-36 place-items-center rounded-lg bg-linear-to-br from-primary-soft to-warning/25 text-ink";
protected readonly icon = "size-14";
protected readonly title = "mt-4 text-base font-semibold text-ink";
protected readonly text = "mt-0.5 text-sm text-muted";
protected readonly row = "mt-4 flex items-center justify-between";
protected readonly price = "text-base font-semibold text-ink";
protected readonly button =
"inline-flex h-9 items-center rounded-lg bg-primary px-3 text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
}Profile card
Adi Santoso
Product designer, Bandung
48Projects
1.2kFollowers
312Following
Adi Santoso
Product designer, Bandung
48Projects
1.2kFollowers
312Following
Adi Santoso
Product designer, Bandung
48Projects
1.2kFollowers
312Following
Adi Santoso
Product designer, Bandung
48Projects
1.2kFollowers
312Following
Adi Santoso
Product designer, Bandung
48Projects
1.2kFollowers
312Following
@php
$stage = 'grid place-items-center py-6';
$card = 'w-72 border border-line bg-surface p-6 text-center';
$avatar = 'mx-auto grid size-20 place-items-center rounded-full bg-linear-to-br from-success/50 to-primary-soft text-xl font-semibold text-ink';
$name = 'mt-4 text-base font-semibold text-ink';
$role = 'text-sm text-muted';
$stats = 'mt-5 grid grid-cols-3 gap-2 border-y border-line py-3';
$value = 'block text-base font-semibold text-ink tabular-nums';
$label = 'text-xs text-muted';
$button = 'mt-5 inline-flex h-9 w-full items-center justify-center rounded-lg border border-line bg-surface text-sm font-medium text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none';
$numbers = [
['value' => '48', 'label' => 'Projects'],
['value' => '1.2k', 'label' => 'Followers'],
['value' => '312', 'label' => 'Following'],
];
@endphp
<div class="{{ $stage }}">
<x-markas.tilt-card :max-angle="8" :class="$card">
<div data-depth="20" aria-hidden="true" class="{{ $avatar }}">AS</div>
<p class="{{ $name }}">Adi Santoso</p>
<p class="{{ $role }}">Product designer, Bandung</p>
<div class="{{ $stats }}">
@foreach ($numbers as $stat)
<p><span class="{{ $value }}">{{ $stat['value'] }}</span><span class="{{ $label }}">{{ $stat['label'] }}</span></p>
@endforeach
</div>
<button type="button" class="{{ $button }}">Follow</button>
</x-markas.tilt-card>
</div>import { TiltCard } from "@/components/markas/TiltCard";
const stage = "grid place-items-center py-6";
const card = "w-72 border border-line bg-surface p-6 text-center";
const avatar =
"mx-auto grid size-20 place-items-center rounded-full bg-linear-to-br from-success/50 to-primary-soft text-xl font-semibold text-ink";
const name = "mt-4 text-base font-semibold text-ink";
const role = "text-sm text-muted";
const stats = "mt-5 grid grid-cols-3 gap-2 border-y border-line py-3";
const value = "block text-base font-semibold text-ink tabular-nums";
const label = "text-xs text-muted";
const button =
"mt-5 inline-flex h-9 w-full items-center justify-center rounded-lg border border-line bg-surface text-sm font-medium text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const numbers = [
{ value: "48", label: "Projects" },
{ value: "1.2k", label: "Followers" },
{ value: "312", label: "Following" },
];
export default function Example() {
return (
<div className={stage}>
<TiltCard maxAngle={8} className={card}>
<div data-depth="20" aria-hidden="true" className={avatar}>
AS
</div>
<p className={name}>Adi Santoso</p>
<p className={role}>Product designer, Bandung</p>
<div className={stats}>
{numbers.map((stat) => (
<p key={stat.label}>
<span className={value}>{stat.value}</span>
<span className={label}>{stat.label}</span>
</p>
))}
</div>
<button type="button" className={button}>
Follow
</button>
</TiltCard>
</div>
);
}<script setup lang="ts">
import TiltCard from "@/components/markas/TiltCard.vue";
const stage = "grid place-items-center py-6";
const card = "w-72 border border-line bg-surface p-6 text-center";
const avatar =
"mx-auto grid size-20 place-items-center rounded-full bg-linear-to-br from-success/50 to-primary-soft text-xl font-semibold text-ink";
const name = "mt-4 text-base font-semibold text-ink";
const role = "text-sm text-muted";
const stats = "mt-5 grid grid-cols-3 gap-2 border-y border-line py-3";
const value = "block text-base font-semibold text-ink tabular-nums";
const label = "text-xs text-muted";
const button =
"mt-5 inline-flex h-9 w-full items-center justify-center rounded-lg border border-line bg-surface text-sm font-medium text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const numbers = [
{ value: "48", label: "Projects" },
{ value: "1.2k", label: "Followers" },
{ value: "312", label: "Following" },
];
</script>
<template>
<div :class="stage">
<TiltCard :max-angle="8" :class="card">
<div data-depth="20" aria-hidden="true" :class="avatar">AS</div>
<p :class="name">Adi Santoso</p>
<p :class="role">Product designer, Bandung</p>
<div :class="stats">
<p v-for="stat in numbers" :key="stat.label">
<span :class="value">{{ stat.value }}</span
><span :class="label">{{ stat.label }}</span>
</p>
</div>
<button type="button" :class="button">Follow</button>
</TiltCard>
</div>
</template><script lang="ts">
import TiltCard from "$lib/components/markas/TiltCard.svelte";
const stage = "grid place-items-center py-6";
const card = "w-72 border border-line bg-surface p-6 text-center";
const avatar =
"mx-auto grid size-20 place-items-center rounded-full bg-linear-to-br from-success/50 to-primary-soft text-xl font-semibold text-ink";
const name = "mt-4 text-base font-semibold text-ink";
const role = "text-sm text-muted";
const stats = "mt-5 grid grid-cols-3 gap-2 border-y border-line py-3";
const value = "block text-base font-semibold text-ink tabular-nums";
const label = "text-xs text-muted";
const button =
"mt-5 inline-flex h-9 w-full items-center justify-center rounded-lg border border-line bg-surface text-sm font-medium text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const numbers = [
{ value: "48", label: "Projects" },
{ value: "1.2k", label: "Followers" },
{ value: "312", label: "Following" },
];
</script>
<div class={stage}>
<TiltCard maxAngle={8} class={card}>
<div data-depth="20" aria-hidden="true" class={avatar}>AS</div>
<p class={name}>Adi Santoso</p>
<p class={role}>Product designer, Bandung</p>
<div class={stats}>
{#each numbers as stat (stat.label)}<p>
<span class={value}>{stat.value}</span><span class={label}
>{stat.label}</span
>
</p>{/each}
</div>
<button type="button" class={button}>Follow</button>
</TiltCard>
</div>---
import TiltCard from "@/components/markas/TiltCard.astro";
const stage = "grid place-items-center py-6";
const card = "w-72 border border-line bg-surface p-6 text-center";
const avatar =
"mx-auto grid size-20 place-items-center rounded-full bg-linear-to-br from-success/50 to-primary-soft text-xl font-semibold text-ink";
const name = "mt-4 text-base font-semibold text-ink";
const role = "text-sm text-muted";
const stats = "mt-5 grid grid-cols-3 gap-2 border-y border-line py-3";
const value = "block text-base font-semibold text-ink tabular-nums";
const label = "text-xs text-muted";
const button =
"mt-5 inline-flex h-9 w-full items-center justify-center rounded-lg border border-line bg-surface text-sm font-medium text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const numbers = [
{ value: "48", label: "Projects" },
{ value: "1.2k", label: "Followers" },
{ value: "312", label: "Following" },
];
---
<div class={stage}>
<TiltCard maxAngle={8} class={card}>
<div data-depth="20" aria-hidden="true" class={avatar}>AS</div>
<p class={name}>Adi Santoso</p>
<p class={role}>Product designer, Bandung</p>
<div class={stats}>
{numbers.map((stat) => (<p>
<span class={value}>{stat.value}</span><span class={label}>{stat.label}</span>
</p>))}
</div>
<button type="button" class={button}>Follow</button>
</TiltCard>
</div>import { Component } from "@angular/core";
import { TiltCard } from "./markas/tilt-card.component";
@Component({
selector: "markas-example",
imports: [TiltCard],
template: `
<div [class]="stage">
<markas-tilt-card [maxAngle]="8" [class]="card">
<div data-depth="20" aria-hidden="true" [class]="avatar">AS</div>
<p [class]="name">Adi Santoso</p>
<p [class]="role">Product designer, Bandung</p>
<div [class]="stats">
@for (stat of numbers; track stat.label) {
<p>
<span [class]="value">{{ stat.value }}</span
><span [class]="label">{{ stat.label }}</span>
</p>
}
</div>
<button type="button" [class]="button">Follow</button>
</markas-tilt-card>
</div>
`,
})
export default class TiltCardProfileExample {
protected readonly stage = "grid place-items-center py-6";
protected readonly card =
"w-72 border border-line bg-surface p-6 text-center";
protected readonly avatar =
"mx-auto grid size-20 place-items-center rounded-full bg-linear-to-br from-success/50 to-primary-soft text-xl font-semibold text-ink";
protected readonly name = "mt-4 text-base font-semibold text-ink";
protected readonly role = "text-sm text-muted";
protected readonly stats =
"mt-5 grid grid-cols-3 gap-2 border-y border-line py-3";
protected readonly value =
"block text-base font-semibold text-ink tabular-nums";
protected readonly label = "text-xs text-muted";
protected readonly button =
"mt-5 inline-flex h-9 w-full items-center justify-center rounded-lg border border-line bg-surface text-sm font-medium text-ink transition-colors duration-150 ease-out hover:bg-subtle focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
protected readonly numbers = [
{ value: "48", label: "Projects" },
{ value: "1.2k", label: "Followers" },
{ value: "312", label: "Following" },
];
}Subtle tilt without glare
@php
$stage = 'grid place-items-center py-6';
$card = 'w-72 border border-line bg-surface p-6';
$head = 'flex items-center justify-between';
$plan = 'text-base font-semibold text-ink';
$badge = 'rounded-full bg-primary-soft px-2.5 py-0.5 text-xs font-medium text-ink';
$price = 'mt-3 text-3xl font-semibold text-ink';
$per = 'text-sm font-normal text-muted';
$list = 'mt-4 grid gap-2 text-sm text-ink';
$item = 'flex items-center gap-2';
$check = 'size-4 text-success';
$link = 'mt-6 inline-flex h-10 w-full items-center justify-center rounded-lg bg-primary text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none';
$features = ['Unlimited projects', 'Custom domains', 'Priority support'];
@endphp
<div class="{{ $stage }}">
<x-markas.tilt-card :max-angle="4" :glare="false" :class="$card">
<div class="{{ $head }}">
<p class="{{ $plan }}">Pro</p>
<span class="{{ $badge }}">Popular</span>
</div>
<p class="{{ $price }}">$12 <span class="{{ $per }}">per month</span></p>
<ul class="{{ $list }}">
@foreach ($features as $feature)
<li class="{{ $item }}"><svg class="{{ $check }}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 12 5 5 9-10" /></svg>{{ $feature }}</li>
@endforeach
</ul>
<a href="#pricing" class="{{ $link }}">Choose Pro</a>
</x-markas.tilt-card>
</div>import { TiltCard } from "@/components/markas/TiltCard";
const stage = "grid place-items-center py-6";
const card = "w-72 border border-line bg-surface p-6";
const head = "flex items-center justify-between";
const plan = "text-base font-semibold text-ink";
const badge =
"rounded-full bg-primary-soft px-2.5 py-0.5 text-xs font-medium text-ink";
const price = "mt-3 text-3xl font-semibold text-ink";
const per = "text-sm font-normal text-muted";
const list = "mt-4 grid gap-2 text-sm text-ink";
const item = "flex items-center gap-2";
const check = "size-4 text-success";
const link =
"mt-6 inline-flex h-10 w-full items-center justify-center rounded-lg bg-primary text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const features = ["Unlimited projects", "Custom domains", "Priority support"];
export default function Example() {
return (
<div className={stage}>
<TiltCard maxAngle={4} glare={false} className={card}>
<div className={head}>
<p className={plan}>Pro</p>
<span className={badge}>Popular</span>
</div>
<p className={price}>
$12 <span className={per}>per month</span>
</p>
<ul className={list}>
{features.map((feature) => (
<li key={feature} className={item}>
<svg
className={check}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
>
<path d="m5 12 5 5 9-10" />
</svg>
{feature}
</li>
))}
</ul>
<a href="#pricing" className={link}>
Choose Pro
</a>
</TiltCard>
</div>
);
}<script setup lang="ts">
import TiltCard from "@/components/markas/TiltCard.vue";
const stage = "grid place-items-center py-6";
const card = "w-72 border border-line bg-surface p-6";
const head = "flex items-center justify-between";
const plan = "text-base font-semibold text-ink";
const badge =
"rounded-full bg-primary-soft px-2.5 py-0.5 text-xs font-medium text-ink";
const price = "mt-3 text-3xl font-semibold text-ink";
const per = "text-sm font-normal text-muted";
const list = "mt-4 grid gap-2 text-sm text-ink";
const item = "flex items-center gap-2";
const check = "size-4 text-success";
const link =
"mt-6 inline-flex h-10 w-full items-center justify-center rounded-lg bg-primary text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const features = ["Unlimited projects", "Custom domains", "Priority support"];
</script>
<template>
<div :class="stage">
<TiltCard :max-angle="4" :glare="false" :class="card">
<div :class="head">
<p :class="plan">Pro</p>
<span :class="badge">Popular</span>
</div>
<p :class="price">$12 <span :class="per">per month</span></p>
<ul :class="list">
<li v-for="feature in features" :key="feature" :class="item">
<svg
:class="check"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m5 12 5 5 9-10" /></svg
>{{ feature }}
</li>
</ul>
<a href="#pricing" :class="link">Choose Pro</a>
</TiltCard>
</div>
</template><script lang="ts">
import TiltCard from "$lib/components/markas/TiltCard.svelte";
const stage = "grid place-items-center py-6";
const card = "w-72 border border-line bg-surface p-6";
const head = "flex items-center justify-between";
const plan = "text-base font-semibold text-ink";
const badge =
"rounded-full bg-primary-soft px-2.5 py-0.5 text-xs font-medium text-ink";
const price = "mt-3 text-3xl font-semibold text-ink";
const per = "text-sm font-normal text-muted";
const list = "mt-4 grid gap-2 text-sm text-ink";
const item = "flex items-center gap-2";
const check = "size-4 text-success";
const link =
"mt-6 inline-flex h-10 w-full items-center justify-center rounded-lg bg-primary text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const features = ["Unlimited projects", "Custom domains", "Priority support"];
</script>
<div class={stage}>
<TiltCard maxAngle={4} glare={false} class={card}>
<div class={head}>
<p class={plan}>Pro</p>
<span class={badge}>Popular</span>
</div>
<p class={price}>$12 <span class={per}>per month</span></p>
<ul class={list}>
{#each features as feature (feature)}<li class={item}>
<svg
class={check}
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m5 12 5 5 9-10" /></svg
>{feature}
</li>{/each}
</ul>
<a href="#pricing" class={link}>Choose Pro</a>
</TiltCard>
</div>---
import TiltCard from "@/components/markas/TiltCard.astro";
const stage = "grid place-items-center py-6";
const card = "w-72 border border-line bg-surface p-6";
const head = "flex items-center justify-between";
const plan = "text-base font-semibold text-ink";
const badge =
"rounded-full bg-primary-soft px-2.5 py-0.5 text-xs font-medium text-ink";
const price = "mt-3 text-3xl font-semibold text-ink";
const per = "text-sm font-normal text-muted";
const list = "mt-4 grid gap-2 text-sm text-ink";
const item = "flex items-center gap-2";
const check = "size-4 text-success";
const link =
"mt-6 inline-flex h-10 w-full items-center justify-center rounded-lg bg-primary text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
const features = ["Unlimited projects", "Custom domains", "Priority support"];
---
<div class={stage}>
<TiltCard maxAngle={4} glare={false} class={card}>
<div class={head}>
<p class={plan}>Pro</p>
<span class={badge}>Popular</span>
</div>
<p class={price}>$12 <span class={per}>per month</span></p>
<ul class={list}>
{features.map((feature) => (<li class={item}>
<svg class={check} viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="m5 12 5 5 9-10" /></svg>{feature}
</li>))}
</ul>
<a href="#pricing" class={link}>Choose Pro</a>
</TiltCard>
</div>import { Component } from "@angular/core";
import { TiltCard } from "./markas/tilt-card.component";
@Component({
selector: "markas-example",
imports: [TiltCard],
template: `
<div [class]="stage">
<markas-tilt-card [maxAngle]="4" [glare]="false" [class]="card">
<div [class]="head">
<p [class]="plan">Pro</p>
<span [class]="badge">Popular</span>
</div>
<p [class]="price">$12 <span [class]="per">per month</span></p>
<ul [class]="list">
@for (feature of features; track feature) {
<li [class]="item">
<svg
[class]="check"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m5 12 5 5 9-10" /></svg
>{{ feature }}
</li>
}
</ul>
<a href="#pricing" [class]="link">Choose Pro</a>
</markas-tilt-card>
</div>
`,
})
export default class TiltCardSubtleExample {
protected readonly stage = "grid place-items-center py-6";
protected readonly card = "w-72 border border-line bg-surface p-6";
protected readonly head = "flex items-center justify-between";
protected readonly plan = "text-base font-semibold text-ink";
protected readonly badge =
"rounded-full bg-primary-soft px-2.5 py-0.5 text-xs font-medium text-ink";
protected readonly price = "mt-3 text-3xl font-semibold text-ink";
protected readonly per = "text-sm font-normal text-muted";
protected readonly list = "mt-4 grid gap-2 text-sm text-ink";
protected readonly item = "flex items-center gap-2";
protected readonly check = "size-4 text-success";
protected readonly link =
"mt-6 inline-flex h-10 w-full items-center justify-center rounded-lg bg-primary text-sm font-medium text-on-primary transition-colors duration-150 ease-out hover:bg-primary-strong focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary motion-reduce:transition-none";
protected readonly features = [
"Unlimited projects",
"Custom domains",
"Priority support",
];
}Installation
npx markasui@latest add tilt-cardpnpm dlx markasui@latest add tilt-cardyarn dlx markasui@latest add tilt-cardbunx --bun markasui@latest add tilt-card- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Install the dependency:
npm install alpinejs - Copy the component source below to
resources/views/components/markas/tilt-card.blade.php.
@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>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/TiltCard.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>
);
}- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/TiltCard.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>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/lib/components/markas/TiltCard.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>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/components/markas/TiltCard.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>- Make sure Tailwind CSS v4 and markas.css are installed. See Installation.
- Copy the component source below to
src/app/markas/tilt-card.component.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);
}
}Usage
<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.
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>;<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><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>---
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.
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 {}- The card rotates up to
maxAngledegrees toward the pointer through the--tilt-xand--tilt-ycustom 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 andclassgo to the card itself.
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.
Related components
More markasui components with the same classes in every framework.
- Bottom NavigationMobile app style bottom bar. A pill glides to the selected item, its label rises in, and the bar can shrink to icons while content scrolls.
- Card StackLayered stack of cards. Swipe, arrow keys, or buttons throw the top card away and the next one rises. Loops, with a position indicator.
- Chat MessageMessage in an AI conversation. User bubbles on the right, assistant replies with an avatar, hover actions, a typing indicator, and optional token streaming.
- Currency InputMoney field that formats as you type (Rp 12.500.000), keeps the caret in place, and posts the plain number. Optional quick amount chips.
- DockmacOS style dock. Icons grow smoothly toward the pointer or focus, show a label above, mark open items with a dot, and bounce on launch.
- Drag ElementsArea of cards or stickers you can drag around with light momentum, kept inside its bounds. Arrow keys move a focused item, Escape puts it back.