Text FX JS behaviour

3D extruded text

A headline that climbs out of the page: stacked offset shadows, one step per pixel, build the depth while the stage tilts under the pointer through perspective; a slider pulls the depth from 3 to 12 steps, and in the dark the edges go neon.

Documentation

Real scenarios

The component as it is used in a product — not a specimen grid.

Type that stands off the page

Every shadow layer sits one pixel further out — the stack is rebuilt from the depth slider, and each layer points at a CSS variable so the dark mirror repaints the steps neon without touching the string. Drag the pointer across the badge, or focus it and use the arrow keys.

tilt

Persian carries the same stack — the extrusion never splits letters, it only paints behind them.

Important props

Important props
Prop Type Default What it does
text-shadow stack '1px … 6px' The depth is a shadow stack: the nth layer sits n pixels off, all pointing at var(--xtd-shade) so the dark theme can recolour them.
depth number '6' A 3–12 slider; the shadow string rebuilds on every change and the last step adds a soft 16px blur for the landing.
tilt pointer '±12° · ±16°' The stage carries perspective: 900px and the pointer drives rotateX up to 12° and rotateY up to 16°; arrow keys rotate too, and leaving resets to zero.
--xtd-shade color '#78716c' The steps’ colour; the dark mirror shifts it to a bright violet while --xtd-glow lights the final neon halo.
reduced-motion media 'no tilt' Under prefers-reduced-motion the tilt switches off (a matchMedia check inside the listener) and the text stands on its static shadows.

Snippet

<div class="xtd" x-data="{
        depth: 6, rx: 0, ry: 0,
        reduced: window.matchMedia('(prefers-reduced-motion: reduce)').matches,
        get shadow() {
            const layers = Array.from({ length: this.depth }, (_, i) => (i + 1) + 'px ' + (i + 1) + 'px 0 var(--xtd-shade)');
            layers.push(this.depth + 'px ' + this.depth + 'px 16px var(--xtd-glow)');
            return layers.join(', ');
        },
        move(e) {
            if (this.reduced) return;
            const r = e.currentTarget.getBoundingClientRect();
            this.ry = ((e.clientX - r.left) / r.width - .5) * 32;
            this.rx = -((e.clientY - r.top) / r.height - .5) * 24;
        },
        reset() { this.rx = 0; this.ry = 0; },
    }">
    <div class="xtd-stage" x-on:pointermove="move($event)" x-on:pointerleave="reset()"
         tabindex="0" role="img" aria-label="Nexus 2026, the developer conference">
        <h2 class="xtd-title" x-bind:style="`
            text-shadow: ${shadow};
            transform: perspective(900px) rotateX(${rx}deg) rotateY(${ry}deg);`">NEXUS 2026</h2>
    </div>
    <label class="xtd-depth">
        Depth: <output x-text="depth"></output>
        <input type="range" min="3" max="12" step="1" x-model.number="depth">
    </label>
</div>

<style>
.xtd { display: grid; gap: 1rem; justify-items: center; text-align: center; }
.xtd-stage { display: grid; place-items: center; padding: 2.5rem 1.5rem; border-radius: 1rem;
             background: #fafaf9; touch-action: none; }
.xtd-title { margin: 0; font-weight: 900; font-size: clamp(2.2rem, 9vw, 4.2rem);
             color: #7c3aed; transition: transform .12s ease-out; }
.xtd-depth { display: inline-grid; gap: .35rem; font-size: .8rem; }
@media (prefers-reduced-motion: reduce) { .xtd-title { transition: none; } }
</style>
// app/Pages/Conference.jsx — Inertia (React) page; renders the React
// snippet below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import Extrude3D from '@/components/Extrude3D';

export default function Conference() {
  return (
    <NabuXUIProvider locale="en" linkComponent={Link}>
      <main className="nx-page">
        <Extrude3D />
      </main>
    </NabuXUIProvider>
  );
}
// Extrude3D.jsx — offset shadow stack + pointer tilt
import { useMemo, useState } from 'react';
import '@nabuxai/ui-core/css';

const reduced = () => window.matchMedia('(prefers-reduced-motion: reduce)').matches;

export default function Extrude3D() {
  const [depth, setDepth] = useState(6);
  const [tilt, setTilt] = useState({ rx: 0, ry: 0 });

  // One shadow layer per depth step, then a soft landing blur.
  const shadow = useMemo(() => {
    const layers = Array.from({ length: depth }, (_, i) => `${i + 1}px ${i + 1}px 0 var(--xtd-shade)`);
    layers.push(`${depth}px ${depth}px 16px var(--xtd-glow)`);
    return layers.join(', ');
  }, [depth]);

  const move = (e: React.PointerEvent<HTMLDivElement>) => {
    if (reduced()) return;
    const r = e.currentTarget.getBoundingClientRect();
    setTilt({
      ry: ((e.clientX - r.left) / r.width - 0.5) * 32,
      rx: -((e.clientY - r.top) / r.height - 0.5) * 24,
    });
  };

  return (
    <>
      <style>{`
        .xtd { display: grid; gap: 1rem; justify-items: center; text-align: center; }
        .xtd-stage { display: grid; place-items: center; padding: 2.5rem 1.5rem; border-radius: 1rem;
                     background: #fafaf9; touch-action: none; }
        .xtd-title { margin: 0; font-weight: 900; font-size: clamp(2.2rem, 9vw, 4.2rem);
                     color: #7c3aed; transition: transform .12s ease-out; }
        .xtd-depth { display: inline-grid; gap: .35rem; font-size: .8rem; }
        @media (prefers-reduced-motion: reduce) { .xtd-title { transition: none; } }
      `}</style>
      <div className="xtd">
        <div className="xtd-stage" onPointerMove={move} onPointerLeave={() => setTilt({ rx: 0, ry: 0 })}
             tabIndex={0} role="img" aria-label="Nexus 2026, the developer conference">
          <h2 className="xtd-title" style={{
            textShadow: shadow,
            transform: `perspective(900px) rotateX(${tilt.rx}deg) rotateY(${tilt.ry}deg)`,
          }}>NEXUS 2026</h2>
        </div>
        <label className="xtd-depth">
          Depth: <output>{depth}</output>
          <input type="range" min={3} max={12} step={1} value={depth}
                 onChange={(e) => setDepth(Number(e.target.value))} />
        </label>
      </div>
    </>
  );
}
<!-- Extrude3D.vue — offset shadow stack + pointer tilt -->
<script setup lang="ts">
import { computed, ref } from 'vue';
import '@nabuxai/ui-core/css';

const depth = ref(6);
const rx = ref(0);
const ry = ref(0);
const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

// One shadow layer per depth step, then a soft landing blur.
const shadow = computed(() => {
  const layers = Array.from({ length: depth.value }, (_, i) => `${i + 1}px ${i + 1}px 0 var(--xtd-shade)`);
  layers.push(`${depth.value}px ${depth.value}px 16px var(--xtd-glow)`);
  return layers.join(', ');
});
const transform = computed(() => `perspective(900px) rotateX(${rx.value}deg) rotateY(${ry.value}deg)`);

const move = (e: PointerEvent) => {
  if (reduced) return;
  const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
  ry.value = ((e.clientX - r.left) / r.width - 0.5) * 32;
  rx.value = -((e.clientY - r.top) / r.height - 0.5) * 24;
};
const reset = () => { rx.value = 0; ry.value = 0; };
</script>

<template>
  <div class="xtd">
    <div class="xtd-stage" @pointermove="move" @pointerleave="reset"
         tabindex="0" role="img" aria-label="Nexus 2026, the developer conference">
      <h2 class="xtd-title" :style="{ textShadow: shadow, transform }">NEXUS 2026</h2>
    </div>
    <label class="xtd-depth">
      Depth: <output>{{ depth }}</output>
      <input v-model.number="depth" type="range" min="3" max="12" step="1" />
    </label>
  </div>
</template>

<style scoped>
.xtd { display: grid; gap: 1rem; justify-items: center; text-align: center; }
.xtd-stage { display: grid; place-items: center; padding: 2.5rem 1.5rem; border-radius: 1rem;
             background: #fafaf9; touch-action: none; }
.xtd-title { margin: 0; font-weight: 900; font-size: clamp(2.2rem, 9vw, 4.2rem);
             color: #7c3aed; transition: transform .12s ease-out; }
.xtd-depth { display: inline-grid; gap: .35rem; font-size: .8rem; }
@media (prefers-reduced-motion: reduce) { .xtd-title { transition: none; } }
</style>
<!-- Extrude3D.svelte — offset shadow stack + pointer tilt -->
<script lang="ts">
  import '@nabuxai/ui-core/css';

  let depth = $state(6);
  let rx = $state(0);
  let ry = $state(0);
  const reduced = window.matchMedia('(prefers-reduced-motion: reduce)').matches;

  // One shadow layer per depth step, then a soft landing blur.
  const shadow = $derived(
    Array.from({ length: depth }, (_, i) => `${i + 1}px ${i + 1}px 0 var(--xtd-shade)`)
      .concat([`${depth}px ${depth}px 16px var(--xtd-glow)`])
      .join(', '),
  );
  const transform = $derived(`perspective(900px) rotateX(${rx}deg) rotateY(${ry}deg)`);

  function move(e: PointerEvent) {
    if (reduced) return;
    const r = (e.currentTarget as HTMLElement).getBoundingClientRect();
    ry = ((e.clientX - r.left) / r.width - 0.5) * 32;
    rx = -((e.clientY - r.top) / r.height - 0.5) * 24;
  }
</script>

<div class="xtd">
  <div class="xtd-stage" onpointermove={move} onpointerleave={() => { rx = 0; ry = 0; }}
       tabindex="0" role="img" aria-label="Nexus 2026, the developer conference">
    <h2 class="xtd-title" style={`text-shadow: ${shadow}; transform: ${transform}`}>NEXUS 2026</h2>
  </div>
  <label class="xtd-depth">
    Depth: <output>{depth}</output>
    <input type="range" min="3" max="12" step="1" bind:value={depth}
           oninput={(e) => (depth = Number(e.currentTarget.value))} />
  </label>
</div>

<style>
.xtd { display: grid; gap: 1rem; justify-items: center; text-align: center; }
.xtd-stage { display: grid; place-items: center; padding: 2.5rem 1.5rem; border-radius: 1rem;
             background: #fafaf9; touch-action: none; }
.xtd-title { margin: 0; font-weight: 900; font-size: clamp(2.2rem, 9vw, 4.2rem);
             color: #7c3aed; transition: transform .12s ease-out; }
.xtd-depth { display: inline-grid; gap: .35rem; font-size: .8rem; }
@media (prefers-reduced-motion: reduce) { .xtd-title { transition: none; } }
</style>