Stacked 404 Page
A 404 card over a hidden stack that fans out on hover.
Preview
"use client";
import { NotFoundStacked } from "@/components/motion/not-found/stacked";
export function NotFoundStackedPreview() {
return (
<div className="w-full">
<NotFoundStacked />
</div>
);
}
"use client";
// beui.dev/components/blocks/not-found/stacked
import { motion, useReducedMotion } from "motion/react";
import { SPRING_PANEL } from "@/lib/ease";
import { useHoverCapable } from "@/lib/hooks/use-hover-capable";
import {
NOT_FOUND_DEFAULTS,
NotFoundActions,
type NotFoundProps,
NotFoundStage,
useNotFoundMessages,
} from "./shared";
const CARD =
"absolute inset-0 rounded-3xl border border-border bg-card shadow-sm";
export function NotFoundStacked({
className,
code = NOT_FOUND_DEFAULTS.code,
title,
description,
homeHref,
homeLabel,
browseHref,
browseLabel,
labels,
}: NotFoundProps) {
const t = useNotFoundMessages(labels);
const reduce = useReducedMotion();
const canHover = useHoverCapable();
const interactive = !reduce && canHover;
return (
<NotFoundStage className={className}>
<motion.div
initial="rest"
animate="rest"
whileHover={interactive ? "hover" : undefined}
className="relative h-44 w-64"
>
<motion.div
aria-hidden
variants={{ rest: { rotate: 0, x: 0, y: 0 }, hover: { rotate: -9, x: -28, y: 8 } }}
transition={SPRING_PANEL}
className={CARD}
/>
<motion.div
aria-hidden
variants={{ rest: { rotate: 0, x: 0, y: 0 }, hover: { rotate: 9, x: 28, y: 8 } }}
transition={SPRING_PANEL}
className={CARD}
/>
<motion.div
variants={{ rest: { y: 0 }, hover: { y: -6 } }}
transition={SPRING_PANEL}
className="absolute inset-0 flex flex-col items-center justify-center gap-1 rounded-3xl border border-border bg-card shadow-md"
>
<h1 className="select-none font-semibold leading-none tracking-tighter text-foreground [font-size:clamp(3.5rem,9vw,5rem)]">
{code}
</h1>
<span className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
{t("stackedCaption")}
</span>
</motion.div>
</motion.div>
<div className="flex flex-col items-center gap-2">
<p className="text-lg font-medium text-foreground">{title ?? t("title")}</p>
<p className="max-w-sm text-sm text-muted-foreground">{description ?? t("description")}</p>
</div>
<NotFoundActions
homeHref={homeHref}
homeLabel={homeLabel}
browseHref={browseHref}
browseLabel={browseLabel}
labels={labels}
/>
</NotFoundStage>
);
}
Add it with the shadcn CLI, or copy the source manually.
npx shadcn add https://beui.dev/r/theme.json. Theme setupInstall dependencies
npm i clsx motion tailwind-mergeAdd util files
// Shared motion tokens. Easing curves mirror the CSS custom properties in
// globals.css; springs are the canonical physics used across components.
// Strong custom variants — defaults like `ease-in`/`ease-out` feel weak.
export const EASE_OUT = [0.16, 1, 0.3, 1] as const;
/** Accelerating curve for things that fall (a dropped ball, a toppled block). Not for UI entrances. */
export const EASE_IN = [0.55, 0, 1, 0.45] as const;
export const EASE_IN_OUT = [0.77, 0, 0.175, 1] as const;
export const EASE_DRAWER = [0.32, 0.72, 0, 1] as const;
/** CSS string form of EASE_OUT for inline style transitions. */
export const EASE_OUT_CSS = "cubic-bezier(0.16, 1, 0.3, 1)";
/** Press feedback on buttons and other tappable surfaces. */
export const SPRING_PRESS = {
type: "spring",
stiffness: 500,
damping: 30,
mass: 0.6,
} as const;
/** Content swaps — label/icon slots trading places inside a control. */
export const SPRING_SWAP = {
type: "spring",
stiffness: 460,
damping: 30,
mass: 0.55,
} as const;
/** Overlay panel entrances — modals and sheets summoned by pointer. */
export const SPRING_PANEL = {
type: "spring",
stiffness: 420,
damping: 40,
mass: 0.5,
} as const;
/** Shared-layout glides — pills, indicators and panels morphing between positions. */
export const SPRING_LAYOUT = {
type: "spring",
stiffness: 360,
damping: 32,
mass: 0.6,
} as const;
/** Cursor-follow physics for decorative mouse tracking (magnetic, tilt, dock). */
export const SPRING_MOUSE = {
stiffness: 200,
damping: 15,
mass: 0.3,
} as const;
/** Dragged handles and fills (sliders) — critically damped `useSpring` config,
* so the value follows the pointer butterily and never rebounds off an end. */
export const SPRING_GLIDE = {
stiffness: 700,
damping: 50,
mass: 0.5,
} as const;
/** Shared-surface morphs: a trigger growing into its panel and back on one
* weighted spring, so opening and closing travel the same path. */
export const SPRING_MORPH = {
type: "spring",
duration: 0.5,
bounce: 0.22,
} as const;
"use client";
import { useEffect, useState } from "react";
/**
* Returns true only on devices that have a true hover (mouse / trackpad).
* Touch devices fire phantom `:hover` on tap that sticks until tap-elsewhere
* — gate hover-only effects (scale lifts, magnetic pulls) behind this.
*/
export function useHoverCapable() {
const [canHover, setCanHover] = useState(false);
useEffect(() => {
if (typeof window === "undefined" || !window.matchMedia) return;
const mq = window.matchMedia("(hover: hover) and (pointer: fine)");
const update = () => setCanHover(mq.matches);
update();
mq.addEventListener?.("change", update);
return () => mq.removeEventListener?.("change", update);
}, []);
return canHover;
}
"use client";
import {
createContext,
type ReactNode,
useCallback,
useContext,
useMemo,
} from "react";
/**
* A component's messages. Plain strings with `{name}` placeholders, so a
* dictionary stays JSON-serializable and can be passed from a server layout.
* There are no plural forms: write messages that read correctly for any count.
*/
export type Messages = Record<string, string>;
/** A language file: component namespace → any subset of that component's messages. */
export type LocaleMessages = Record<string, Partial<Messages>>;
type LocaleContextValue = {
locale?: string;
messages: LocaleMessages;
};
const NO_MESSAGES: LocaleMessages = {};
const LocaleContext = createContext<LocaleContextValue>({ messages: NO_MESSAGES });
/** Without a locale, digits stay plain so server and client render the same text. */
export function formatNumber(value: number, locale?: string) {
return locale ? new Intl.NumberFormat(locale).format(value) : String(value);
}
export interface LocaleProviderProps {
/** BCP 47 tag, e.g. `de`, `pt-BR`. Drives `Intl` number formatting. */
locale: string;
/**
* Component namespace → translated strings. Missing keys fall back to English.
* Pass a stable object (a module constant, imported JSON or a memoized value):
* a new object each render gives every translated component a new `t`.
*/
messages?: LocaleMessages;
children: ReactNode;
}
export function LocaleProvider({ locale, messages = NO_MESSAGES, children }: LocaleProviderProps) {
const value = useMemo(() => ({ locale, messages }), [locale, messages]);
return <LocaleContext.Provider value={value}>{children}</LocaleContext.Provider>;
}
export function useLocale(): { locale?: string } {
return { locale: useContext(LocaleContext).locale };
}
/**
* Resolves a component's strings: `labels` prop, then the provider's
* messages for `namespace`, then the component's English `defaults`.
* Numbers passed as values are formatted for the provider's locale.
*/
export function useMessages<T extends Messages>(
namespace: string,
defaults: T,
labels?: Partial<T>,
) {
const { locale, messages } = useContext(LocaleContext);
const provided = messages[namespace];
// Inline `labels={{ … }}` is a new object every render. Keying it by content
// keeps `t` one identity until a label changes, so effects and memos that
// depend on `t` don't re-run per render, and render-time reads never lag.
const labelsKey = labels ? JSON.stringify(labels) : "";
const stableLabels = useMemo(
() => (labelsKey ? (JSON.parse(labelsKey) as Partial<T>) : undefined),
[labelsKey],
);
return useCallback(
(key: keyof T & string, values?: Record<string, string | number>) => {
const template = stableLabels?.[key] ?? provided?.[key] ?? defaults[key];
if (!values) return template;
return template.replace(/\{(\w+)\}/g, (match, name: string) => {
const value = values[name];
if (value === undefined) return match;
return typeof value === "number" ? formatNumber(value, locale) : value;
});
},
[defaults, stableLabels, locale, provided],
);
}
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
Copy the source code
"use client";
// beui.dev/components/blocks/not-found/stacked
import { motion, useReducedMotion } from "motion/react";
import { SPRING_PANEL } from "@/lib/ease";
import { useHoverCapable } from "@/lib/hooks/use-hover-capable";
import {
NOT_FOUND_DEFAULTS,
NotFoundActions,
type NotFoundProps,
NotFoundStage,
useNotFoundMessages,
} from "./shared";
const CARD =
"absolute inset-0 rounded-3xl border border-border bg-card shadow-sm";
export function NotFoundStacked({
className,
code = NOT_FOUND_DEFAULTS.code,
title,
description,
homeHref,
homeLabel,
browseHref,
browseLabel,
labels,
}: NotFoundProps) {
const t = useNotFoundMessages(labels);
const reduce = useReducedMotion();
const canHover = useHoverCapable();
const interactive = !reduce && canHover;
return (
<NotFoundStage className={className}>
<motion.div
initial="rest"
animate="rest"
whileHover={interactive ? "hover" : undefined}
className="relative h-44 w-64"
>
<motion.div
aria-hidden
variants={{ rest: { rotate: 0, x: 0, y: 0 }, hover: { rotate: -9, x: -28, y: 8 } }}
transition={SPRING_PANEL}
className={CARD}
/>
<motion.div
aria-hidden
variants={{ rest: { rotate: 0, x: 0, y: 0 }, hover: { rotate: 9, x: 28, y: 8 } }}
transition={SPRING_PANEL}
className={CARD}
/>
<motion.div
variants={{ rest: { y: 0 }, hover: { y: -6 } }}
transition={SPRING_PANEL}
className="absolute inset-0 flex flex-col items-center justify-center gap-1 rounded-3xl border border-border bg-card shadow-md"
>
<h1 className="select-none font-semibold leading-none tracking-tighter text-foreground [font-size:clamp(3.5rem,9vw,5rem)]">
{code}
</h1>
<span className="text-xs font-medium uppercase tracking-wide text-muted-foreground">
{t("stackedCaption")}
</span>
</motion.div>
</motion.div>
<div className="flex flex-col items-center gap-2">
<p className="text-lg font-medium text-foreground">{title ?? t("title")}</p>
<p className="max-w-sm text-sm text-muted-foreground">{description ?? t("description")}</p>
</div>
<NotFoundActions
homeHref={homeHref}
homeLabel={homeLabel}
browseHref={browseHref}
browseLabel={browseLabel}
labels={labels}
/>
</NotFoundStage>
);
}
"use client";
import { motion, useReducedMotion } from "motion/react";
import { SPRING_PRESS } from "@/lib/ease";
import { useHoverCapable } from "@/lib/hooks/use-hover-capable";
import { useMessages } from "@/lib/i18n";
import { cn } from "@/lib/utils";
export interface NotFoundProps {
/** Classes merged onto the root element. */
className?: string;
/** The big status code. */
code?: string;
/** Heading under the status code. Default: "Page not found" */
title?: string;
/** Supporting line under the heading. */
description?: string;
/** Link for the primary button. Default: "/" */
homeHref?: string;
/** Text of the primary button. Default: "Back home" */
homeLabel?: string;
/** Link for the secondary button. Default: "/components/motion" */
browseHref?: string;
/** Text of the secondary button. Default: "Browse components" */
browseLabel?: string;
/** Override any built-in string. Explicit `title`, `description`, `homeLabel` and `browseLabel` props still win. */
labels?: Partial<NotFoundMessages>;
}
export const NOT_FOUND_DEFAULTS = {
code: "404",
homeHref: "/",
browseHref: "/components/motion",
} as const;
/** English defaults. Override per instance with `labels`, or app-wide with `LocaleProvider`. */
export const notFoundMessages = {
title: "Page not found",
description: "The page you are looking for moved, vanished, or never existed.",
homeLabel: "Back home",
browseLabel: "Browse components",
stackedCaption: "out of the deck",
terminalError: "cd: no such file or directory: /page",
};
export type NotFoundMessages = typeof notFoundMessages;
/** Resolves a variant's strings: explicit props, then `labels`, the provider and English. */
export function useNotFoundMessages(labels?: Partial<NotFoundMessages>) {
return useMessages("notFound", notFoundMessages, labels);
}
type ActionsProps = Pick<
NotFoundProps,
"homeHref" | "homeLabel" | "browseHref" | "browseLabel" | "labels" | "className"
>;
/** The shared dual CTA: a primary "Back home" and a secondary "Browse". */
export function NotFoundActions({
homeHref = NOT_FOUND_DEFAULTS.homeHref,
homeLabel,
browseHref = NOT_FOUND_DEFAULTS.browseHref,
browseLabel,
labels,
className,
}: ActionsProps) {
const t = useNotFoundMessages(labels);
const reduce = useReducedMotion();
const canHover = useHoverCapable();
const whileTap = reduce ? undefined : { scale: 0.96 };
const whileHover = reduce || !canHover ? undefined : { scale: 1.02 };
return (
<div
className={cn(
"flex flex-wrap items-center justify-center gap-3",
className,
)}
>
<motion.a
href={homeHref}
whileTap={whileTap}
whileHover={whileHover}
transition={SPRING_PRESS}
className="inline-flex h-11 select-none items-center justify-center rounded-full bg-primary px-6 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90"
>
{homeLabel ?? t("homeLabel")}
</motion.a>
<motion.a
href={browseHref}
whileTap={whileTap}
whileHover={whileHover}
transition={SPRING_PRESS}
className="inline-flex h-11 select-none items-center justify-center rounded-full border border-border bg-card px-6 text-sm font-medium text-foreground transition-colors hover:bg-muted/60"
>
{browseLabel ?? t("browseLabel")}
</motion.a>
</div>
);
}
/** Centers a variant and gives it a consistent minimum stage height. */
export function NotFoundStage({
className,
children,
}: {
className?: string;
children: React.ReactNode;
}) {
return (
<div
className={cn(
"flex min-h-[420px] w-full flex-col items-center justify-center gap-8 px-4 text-center",
className,
)}
>
{children}
</div>
);
}
className?stringClasses merged onto the root element.
—code?stringThe big status code.
404title?stringHeading under the status code. Default: "Page not found"
—description?stringSupporting line under the heading.
—homeHref?stringLink for the primary button. Default: "/"
—homeLabel?stringText of the primary button. Default: "Back home"
—browseHref?stringLink for the secondary button. Default: "/components/motion"
—browseLabel?stringText of the secondary button. Default: "Browse components"
—labels?Partial<{ title: string; description: string; homeLabel: string; browseLabel: string; stackedCaption: string; terminalError: string; }>Override any built-in string. Explicit `title`, `description`, `homeLabel` and `browseLabel` props still win.
—Glitch 404 Page
A 404 whose digits scramble into place and split apart on hover.
Magnetic 404 Page
A 404 whose digits lean toward the cursor and spring back.
Spotlight 404 Page
A dark 404 where a cursor spotlight lights up the error code.
Terminal 404 Page
A terminal that types out a failed command and a 404 status.
Dynamic Island
iOS-style island pill that morphs between live activity views with bouncy shell resize and blur crossfades.
Swipeable List
Mobile-style list rows that swipe left or right to reveal contextual action buttons.
Fixtures
Animated tournament fixtures in two styles: a knockout bracket that pages through rounds, and a wheel that wraps the same tree around the champion. Both read the same array of rounds, so one dataset draws either.
Some components on this site are inspired by or recreated from existing work across the web. I'm not here to take credit; just to learn, experiment, and sometimes push things a bit further. If something looks familiar and I forgot to mention you, reach out and I'll fix that right away.
Updated