- CSS Sorcery: 3D Text Hover Effects Without (Real) JavaScript
- 1. How the 3D-Card Effect Works
- 2. My Idea
- 3. The Implementation
- The React Part: The Trojan Horse
- The CSS: Where the Magic Happens
- 1. Type Safety in CSS? @property
- 2. The Grid as a Controller
- 3. The :has() Selector – The Parent Spy
- 4. Math Class (Trigonometry in calc())
- The End
CSS Sorcery: 3D Text Hover Effects Without (Real) JavaScript
Picture this: It's Christmas, I'm on my way to visit the family, staring out the window, and suddenly a thought pops into my head. I wanted to build a 3D hover effect for text. You know, something where a multi-colored drop shadow appears behind the text, and the whole thing looks like you're physically dragging the letters around.
If you know me or follow my ramblings, you know I’ve recently fallen head over heels for Daisy. DaisyUI, to be precise. DaisyUI recently introduced a 3D Card component, and they did the whole thing entirely in CSS.
Now, I could give you a long-winded lecture on why I will always choose CSS over JavaScript given the chance, and why that’s exactly why I love DaisyUI so much... but that’s not what we're here for today.
First, let's quickly break down how DaisyUI solved the card hover effect using only CSS.
1. How the 3D-Card Effect Works
Unlike JavaScript, CSS can't simply grab the X and Y coordinates of your cursor. So, we need a creative hack. Specifically, we need a Grid where every cell acts as a sort of coordinate trigger for the image.
Imagine a 3x3 grid:
- Top Left = A1
- Top Center = A2
- Top Right = A3
- ...and so on, down to Bottom Right = C3.

When you hover over one of these invisible grid areas, it triggers the 3D animation in a specific direction. Combine that with a strong CSS transition, and the user barely notices that it’s not pixel-perfect tracking, but rather coarse zones triggering the movement. It’s basically like those dance dance revolution pads from the 80s, but for your mouse.
And that’s really it. The image scales and rotates three-dimensionally depending on which "platform" (grid cell) is being hovered.
2. My Idea
My idea was basically to reverse-engineer this and apply it to typography. I wanted the text to consist of three layers that follow the mouse circularly on different radii.
3. The Implementation
Ever since I moved my projects over to Netlify, I’ve been using for little experiments like this. Deno is insanely fast, supports TypeScript by default, and allows me to just use my familiar NPM packages. So, I fired up Vite with React, and I was ready to roll.
