# Text Halo
*URL: https://www.grettech.com/components/text-halo*

A ring of text orbiting your content in 3D, like a planet's ring. The far side passes behind, dimmed. Pure CSS.

- Real 3D ring with depth: the back half passes behind the content
- Text repeats to fill the ring evenly
- Tilt, radius, speed and direction are props; pauses on hover
- Pure CSS: renders on the server, no JavaScript

## Install with the shadcn CLI
```bash
npx shadcn@latest add https://www.grettech.com/api/registry/text-halo
```
With its demo: `npx shadcn@latest add https://www.grettech.com/api/registry/text-halo-demo`

**Dependencies:** npm: clsx, tailwind-merge

## Manual installation
**Step 1: Install dependencies**
Install the packages this component uses and the shadcn/ui components it builds on. It also needs the `cn` helper in `lib/utils.ts`, which `npx shadcn@latest init` adds.

```bash
npm install clsx tailwind-merge
```

**Step 2: Copy the source code**
Add these files to your project components directory.

File: `components/ui/text-halo.tsx`
```tsx
import { cn } from "@/lib/utils"
import * as React from "react"

export interface TextHaloProps extends React.HTMLAttributes<HTMLDivElement> {
  /** Text on the ring; repeated to fill it */
  text: string
  /** Placed between repeats */
  separator?: string
  /** Content inside the ring */
  children?: React.ReactNode
  /** Ring radius in px */
  radius?: number
  /** Ring tilt toward the viewer, in degrees */
  tilt?: number
  /** Seconds per revolution */
  duration?: number
  reverse?: boolean
  /** Letter size in px */
  fontSize?: number
  /** Pause while hovered */
  pauseOnHover?: boolean
  /** Classes for the ring's letters (colour, weight, font) */
  textClassName?: string
}

const KEYFRAMES = `
@keyframes gridtic-halo-spin { from { transform: rotateY(0deg); } to { transform: rotateY(-360deg); } }
@media (prefers-reduced-motion: reduce) { .gridtic-halo-ring { animation: none !important; } }
`

/**
 * Text orbiting its content on a tilted 3D ring. The far side passes behind
 * the content, dimmed. Pure CSS: it renders on the server and needs no JS.
 */
export const TextHalo = React.forwardRef<HTMLDivElement, TextHaloProps>(
  (
    {
      text,
      separator = " • ",
      children,
      radius = 170,
      tilt = 16,
      duration = 18,
      reverse = false,
      fontSize = 16,
      pauseOnHover = true,
      textClassName,
      className,
      style,
      ...props
    },
    ref
  ) => {
    // Enough repeats to wrap the ring once with roughly even spacing
    const unit = `${text}${separator}`
    const charWidth = fontSize * 0.62
    const fit = Math.max(
      unit.length,
      Math.round((2 * Math.PI * radius) / charWidth)
    )
    const chars = [...unit.repeat(Math.ceil(fit / unit.length))].slice(0, fit)
    const step = 360 / chars.length
    const size = radius * 2 + fontSize * 4

    return (
      <div
        ref={ref}
        role="group"
        aria-label={text}
        className={cn(
          "group/halo relative mx-auto flex max-w-full items-center justify-center [perspective:1100px]",
          className
        )}
        style={{ width: size, height: size, ...style }}
        {...props}
      >
        <style href="gridtic-text-halo" precedence="default">
          {KEYFRAMES}
        </style>

        <div
          className="absolute inset-0 [transform-style:preserve-3d]"
          style={{ transform: `rotateX(${-tilt}deg)` }}
        >
          {/* Content sits inside the ring, facing the viewer */}
          <div
            className="absolute inset-0 flex items-center justify-center"
            style={{ transform: `rotateX(${tilt}deg)` }}
          >
            {children}
          </div>

          <div
            aria-hidden="true"
            className={cn(
              "gridtic-halo-ring absolute inset-0 [transform-style:preserve-3d]",
              pauseOnHover && "group-hover/halo:[animation-play-state:paused]"
            )}
            // Longhands only, so changing duration or direction updates cleanly
            style={{
              animationName: "gridtic-halo-spin",
              animationDuration: `${duration}s`,
              animationTimingFunction: "linear",
              animationIterationCount: "infinite",
              animationDirection: reverse ? "reverse" : "normal",
            }}
          >
            {chars.map((char, i) => (
              <span
                key={i}
                className="absolute top-1/2 left-1/2 [transform-style:preserve-3d]"
                style={{
                  transform: `rotateY(${i * step}deg) translateZ(${radius}px)`,
                }}
              >
                {/* Front face, and a dimmed face seen from behind */}
                <span
                  className={cn(
                    "absolute -translate-x-1/2 -translate-y-1/2 font-semibold whitespace-pre uppercase [backface-visibility:hidden]",
                    textClassName
                  )}
                  style={{ fontSize }}
                >
                  {char}
                </span>
                <span
                  className={cn(
                    "absolute -translate-x-1/2 -translate-y-1/2 [transform:rotateY(180deg)] font-semibold whitespace-pre uppercase opacity-25 [backface-visibility:hidden]",
                    textClassName
                  )}
                  style={{ fontSize }}
                >
                  {char}
                </span>
              </span>
            ))}
          </div>
        </div>
      </div>
    )
  }
)
TextHalo.displayName = "TextHalo"

```

**Step 3: Framework Adjustments (Optional)**
If you are manually copying this code into a Vite or Remix project (without using the CLI), make sure to remove the `"use client";` directive from the very top of the file.

## Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| `text` | `string` | - | Yes | Text on the ring, repeated to fill it. Also the accessible name. |
| `separator` | `string` | `" • "` | No | Placed between repeats. |
| `children` | `React.ReactNode` | - | No | Content inside the ring, e.g. a logo or an orb. |
| `radius` | `number` | `170` | No | Ring radius in px. |
| `tilt` | `number` | `16` | No | Ring tilt toward the viewer, in degrees. |
| `duration` | `number` | `18` | No | Seconds per revolution. |
| `reverse` | `boolean` | `false` | No | Spin the other way. |
| `fontSize` | `number` | `16` | No | Letter size in px. |
| `pauseOnHover` | `boolean` | `true` | No | Pause while hovered. |
| `textClassName` | `string` | - | No | Classes for the ring's letters, e.g. a colour or font. |
| `className` | `string` | - | No | Extra classes for the root element. |
| `...props` | `React.HTMLAttributes<HTMLDivElement>` | - | No | Any other attributes, passed to the root element. |

## Usage
```tsx
"use client"

import { TextHalo } from "@/components/ui/text-halo"

export default function TextHaloDemo() {
  return (
    <div className="flex w-full items-center justify-center py-6">
      <TextHalo
        text="Design · Develop · Deploy"
        textClassName="text-cyan-600 dark:text-cyan-300"
      >
        <div className="size-40 rounded-full bg-[radial-gradient(circle_at_30%_30%,#a5f3fc,#6366f1_45%,#1e1b4b_75%)] shadow-[0_0_80px_10px_rgba(99,102,241,0.45)]" />
      </TextHalo>
    </div>
  )
}

```
