Wensity Labs

Text Cycle

Text 4

About

A rotating words headline that cycles through phrases with a per character blur stagger. Use it in hero sections to rotate audiences, features or use cases.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Text Cycle to your project and fits it to your theme.

Code

How Text Cycle is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import { TextCycle } from "@/components/ui/text-cycle";

import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";

function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

const DEFAULT_WORDS = ["engineer", "developer", "designer"] as const;

const settings = {
  words: DEFAULT_WORDS.join("\n"),
  interval: 2500,
  paused: false,
};

const previewClass =
  "font-display text-4xl font-semibold tracking-tight text-foreground sm:text-5xl";

function parseWords(raw: string): string[] {
  return raw
    .split("\n")
    .map((line) => line.trim())
    .filter(Boolean);
}

function CycleLine({
  words,
  interval,
  paused,
  className,
  cycleKey,
}: {
  words: string[];
  interval?: number;
  paused?: boolean;
  className?: string;
  cycleKey?: string;
}) {
  let longest = words[0] ?? "developer";
  for (const word of words) {
    if (word.length > longest.length) longest = word;
  }

  return (
    <span className={cn("relative inline-flex", className)}>
      {/* Width lock so the block stays centered while words change */}
      <span className="invisible whitespace-nowrap" aria-hidden="true">
        21&nbsp;·&nbsp;{longest}
      </span>
      <span className="absolute inset-0 flex items-baseline justify-start whitespace-nowrap">
        <span className="shrink-0 text-muted-foreground">21&nbsp;·&nbsp;</span>
        <TextCycle
          key={cycleKey}
          words={words}
          interval={interval}
          paused={paused}
        />
      </span>
    </span>
  );
}

export function TextCyclePreview(props: Partial<typeof settings> = {}) {
  const state = { ...settings, ...props };
  const words = parseWords(state.words);
  const resolved = words.length > 0 ? words : [...DEFAULT_WORDS];

  return (
    <div className="flex min-h-[360px] w-full items-center justify-center px-4 py-12 sm:px-8">
      <CycleLine
        cycleKey={`${state.interval}-${resolved.join("|")}`}
        words={resolved}
        interval={state.interval}
        paused={state.paused}
        className={previewClass}
      />
    </div>
  );
}

export default function Demo(props: Partial<typeof settings>) {
  return <TextCyclePreview {...props} />;
}

Dependencies

More by Wensity Labs

View all
  • Sidebar

    Sidebar

    234
  • Calendar

    Calendar

    173
  • Button

    Button

    76
  • Color Picker

    Color Picker

    64
  • Image Comparison Slider

    Image Comparison Slider

    55
  • AI Prompt Input

    AI Prompt Input

    50
  • Navigation Menu

    Navigation Menu

    36
  • Text Morphing

    Text Morphing

    36

More in Text

View all
  • Vertical Cut Reveal Characters

    Vertical Cut Reveal Characters

    103
  • Rainbow Text Effect

    Rainbow Text Effect

    47
  • Motion Blur Text

    Motion Blur Text

    36
  • Text Loop

    Text Loop

    309
  • Text Reveal

    Text Reveal

    27
  • Apple Hello Effect

    Apple Hello Effect

    610
  • Typography

    Typography

    4
  • Animated Text

    Animated Text

    8