sigilUI

Box 3D

A CSS 3D box with six faces, configurable dimensions, and GSAP-powered rotation. No WebGL required.

@sigil-ui/componentsReact

Preview

Live preview Interactive

Import

import { Box3D } from "@sigil-ui/components";

Usage

<Box3D className="w-full max-w-sm p-8" hoverLift><strong>Token-driven surfaces</strong><p>Move over the panel to explore its depth.</p></Box3D>

Renders a cube using CSS 3D transforms (transform-style: preserve-3d). Each face is a positioned <div>. GSAP handles smooth rotation on hover and idle animation.

Size

<Box3D size={80} />
<Box3D size={120} />
<Box3D size={200} />

Custom dimensions

For non-cubic shapes:

<Box3D width={200} height={120} depth={80} />

Colors

Each face can be styled independently, or use a single color that shifts lightness per face:

{/* Uniform color with automatic face shading */}
<Box3D color="var(--s-primary)" />

{/* Per-face colors */}
<Box3D
  faces={{
    front: "var(--s-primary)",
    back: "var(--s-primary-muted)",
    left: "oklch(0.60 0.15 280)",
    right: "oklch(0.70 0.15 280)",
    top: "oklch(0.75 0.10 280)",
    bottom: "oklch(0.50 0.15 280)",
  }}
/>

Rotation

Interactive (hover)

<Box3D interactive />

The box follows the cursor on hover using GSAP for smooth interpolation.

Auto-rotate

<Box3D autoRotate />
<Box3D autoRotate speed={0.5} />
<Box3D autoRotate speed={2} axis="y" />

Static angle

<Box3D rotateX={-20} rotateY={30} />

Face content

Render content on any face:

<Box3D size={150}>
  <Box3D.Face side="front">
    <span className="text-2xl">✦</span>
  </Box3D.Face>
  <Box3D.Face side="top">
    <span className="text-sm">TOP</span>
  </Box3D.Face>
</Box3D>

Wireframe mode

<Box3D variant="wireframe" color="var(--s-border)" />

Renders only edges — no filled faces. Uses --s-border for line color and --s-border-width-thin for stroke.

Glass mode

<Box3D variant="glass" />

Semi-transparent faces with backdrop-filter: blur() for a frosted-glass cube.

Token integration

CSS VariableUsed for
--s-primaryDefault face color
--s-surfaceWireframe face background
--s-borderWireframe edge color
--s-border-width-thinWireframe stroke
--s-shadow-lgDrop shadow beneath the box
--s-duration-normalHover transition
--s-duration-slowerAuto-rotate cycle
--s-ease-defaultRotation easing
--s-ease-springInteractive hover spring

Props

PropTypeDefaultDescription
sizenumber100Uniform width/height/depth
widthnumber—Box width (overrides size)
heightnumber—Box height (overrides size)
depthnumber—Box depth (overrides size)
colorstringvar(--s-primary)Face color
facesRecord<Face, string>—Per-face color map
variant"solid" | "wireframe" | "glass""solid"Rendering mode
interactivebooleanfalseFollow cursor on hover
autoRotatebooleanfalseContinuous rotation
speednumber1Auto-rotate speed multiplier
axis"x" | "y" | "xy""xy"Rotation axis
rotateXnumber0Static X rotation (degrees)
rotateYnumber0Static Y rotation (degrees)
classNamestring—Additional CSS classes
childrenReactNode—Face content via Box3D.Face

Box3D.Face

PropTypeDefaultDescription
side"front" | "back" | "left" | "right" | "top" | "bottom"—Which face to render on
classNamestring—Additional CSS classes
childrenReactNode—Face content

Browser support

CSS 3D transforms are supported in all modern browsers. GSAP animation uses requestAnimationFrame with automatic fallback. The glass variant requires backdrop-filter support (all modern browsers except Firefox < 103).

Accessibility

  • Decorative by default: role="presentation" and aria-hidden="true"
  • Add role="img" and aria-label if the box conveys meaning
  • prefers-reduced-motion disables auto-rotate and hover animations