opensourceui
GitHubTwitter/X
  1. Home
  2. Components
  3. Buttons
  4. 3D Button
Back to Buttons

Components / Buttons

3D Button

Free Buttons React component — ThreeDButton. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Universal 3D button with tactile keycap shadows — pass any children (label, icon + label). Variants: solid, soft, muted. Sizes: sm, md, lg, icon. Press sinks the key in.

Preview

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/buttons/three-d-button.tsx in your project.

  4. 4

    Import and render:

    Example

    import { ThreeDButton } from "@/components/buttons/three-d-button";

    <ThreeDButton variant="solid"><ArrowRight /> Continue</ThreeDButton>

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/buttons/three-d-button.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"use client";
 
import {
forwardRef,
type ComponentPropsWithoutRef,
type ReactNode,
} from "react";
 
import { cn } from "@/lib/cn";
 
export type ThreeDButtonVariant = "solid" | "soft" | "muted";
export type ThreeDButtonSize = "sm" | "md" | "lg" | "icon";
 
export type ThreeDButtonProps = Readonly<
{
children: ReactNode;
variant?: ThreeDButtonVariant;
size?: ThreeDButtonSize;
} & ComponentPropsWithoutRef<"button">
>;
 
const SIZE: Record<ThreeDButtonSize, string> = {
sm: "h-9 gap-1.5 rounded-lg px-3 text-xs",
md: "h-10 gap-2 rounded-lg px-4 text-sm",
lg: "h-12 gap-2 rounded-xl px-5 text-sm",
icon: "size-10 rounded-lg p-0",
};
 
// Soft diffused top light + bottom shade — no hard white rim.
const BEVEL_LIGHT =
"shadow-[0_1px_1px_rgba(0,0,0,0.08),0_2px_4px_rgba(0,0,0,0.1),0_6px_12px_rgba(0,0,0,0.08),inset_0_1px_2px_rgba(255,255,255,0.35),inset_0_-2px_4px_rgba(0,0,0,0.08)]";
const PRESSED_LIGHT =
"active:shadow-[0_1px_1px_rgba(0,0,0,0.05),inset_0_1px_2px_rgba(0,0,0,0.08),inset_0_2px_4px_rgba(0,0,0,0.04),inset_0_-1px_2px_rgba(0,0,0,0.05)]";
 
// Dark key: soft top sheen (blurred, not a sharp bar) + deep lift + bottom recess.
const BEVEL_DARK =
"shadow-[0_1px_1px_rgba(0,0,0,0.35),0_3px_6px_rgba(0,0,0,0.28),0_8px_16px_rgba(0,0,0,0.22),inset_0_1px_2px_rgba(255,255,255,0.14),inset_0_-3px_6px_rgba(0,0,0,0.55)]";
const PRESSED_DARK =
"active:shadow-[0_1px_2px_rgba(0,0,0,0.25),inset_0_2px_6px_rgba(0,0,0,0.55),inset_0_-1px_1px_rgba(255,255,255,0.06)]";
 
const VARIANT: Record<ThreeDButtonVariant, string> = {
solid: cn(
"bg-neutral-800 text-white hover:bg-neutral-700 active:bg-neutral-900",
BEVEL_DARK,
PRESSED_DARK,
),
soft: cn(
"bg-neutral-50 text-neutral-800 hover:text-neutral-900 active:bg-neutral-100",
BEVEL_LIGHT,
PRESSED_LIGHT,
),
muted: cn(
"bg-neutral-100 text-neutral-700 hover:bg-neutral-200/80 hover:text-neutral-900 active:bg-neutral-200",
BEVEL_LIGHT,
PRESSED_LIGHT,
),
};
 
// Universal 3D button — pass any children (label, icon + label, icon only).
export const ThreeDButton = forwardRef<HTMLButtonElement, ThreeDButtonProps>(
(
{
className,
children,
variant = "solid",
size = "md",
type = "button",
disabled,
...props
},
ref,
) => {
return (
<button
ref={ref}
type={type}
disabled={disabled}
data-slot="3d-button"
data-variant={variant}
data-size={size}
className={cn(
"inline-flex cursor-pointer items-center justify-center font-sans font-semibold outline-none select-none",
"transition-[background-color,box-shadow,color] duration-200 ease-[cubic-bezier(0.32,0.72,0,1)] motion-reduce:transition-none",
"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-neutral-900",
"disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-40",
SIZE[size],
VARIANT[variant],
size === "icon" && "shrink-0",
className,
)}
{...props}
>
{children}
</button>
);
},
);
 
ThreeDButton.displayName = "ThreeDButton";
Next

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/buttons/three-d-button.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.