Glow Text
A neon text effect for React and Tailwind CSS: a single soft text-shadow glow, static by default with optional breathing or flickering, in any color and at any heading level. It stays real, selectable text, so headings remain readable by search engines and screen readers.
- SEO-friendly real text
- Heading levels via as
- Breathe & flicker
- No re-renders
- prefers-reduced-motion
Open all night
import { GlowText } from "@/components/dusk/neon/glow-text";
export default function GlowTextDemo() {
return (
<GlowText
as="h2"
color="#f472b6"
className="text-center text-5xl font-bold tracking-tight sm:text-6xl"
>
Open all night
</GlowText>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/glow-text.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/neon/glow-text.tsx.glow-text.tsx "use client"; import * as React from "react"; import { animate, useMotionValue, useMotionValueEvent, useReducedMotion } from "motion/react"; import { cn } from "@/lib/utils"; type GlowTextTag = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "p" | "span" | "div" | "strong"; export interface GlowTextProps extends Omit<React.HTMLAttributes<HTMLElement>, "color"> { /** Element to render. Use a heading level for titles so the text stays in the document outline. */ as?: GlowTextTag; /** Any CSS color. Defaults to the theme primary. */ color?: string; /** Glow strength multiplier. 1 is the default, 0 removes the glow. */ intensity?: number; /** * `breathe`: the glow slowly swells and fades. * `flicker`: steady glow with an occasional double flicker, like an old neon sign. * `none`: static glow (default). Reduced-motion users always get `none`. */ animation?: "none" | "breathe" | "flicker"; /** Seconds per animation cycle. Flicker cycles are clamped to at least 2s. */ speed?: number; } /* * Flicker cycle: steady most of the time, then two short dips close together. * With the cycle clamped to >= 2s this is at most 2 flashes per second, under * the WCAG 2.3.1 limit of 3. Only the glow dims; the letters stay readable. */ const FLICKER = { values: [1, 1, 0.3, 1, 1, 0.45, 1, 1], times: [0, 0.62, 0.66, 0.7, 0.78, 0.82, 0.86, 1], }; /** * Real, selectable text with a single soft neon glow. The glow is a `text-shadow` * driven by a CSS variable that Motion animates outside React, so the text * never re-renders and search engines and screen readers see plain text. */ export function GlowText({ as: Tag = "span", color = "var(--color-primary)", intensity = 1, animation = "none", speed, className, style, children, ...props }: GlowTextProps) { const ref = React.useRef<HTMLElement>(null); const reduceMotion = useReducedMotion(); const mode = reduceMotion ? "none" : animation; const glow = useMotionValue(1); useMotionValueEvent(glow, "change", (value) => { ref.current?.style.setProperty("--glow", value.toFixed(3)); }); React.useEffect(() => { if (mode === "none") { glow.set(1); return; } const controls = mode === "breathe" ? animate(glow, [1, 0.7, 1], { duration: Math.max(1, speed ?? 3.2), ease: "easeInOut", repeat: Infinity, }) : animate(glow, FLICKER.values, { duration: Math.max(2, speed ?? 4), times: FLICKER.times, ease: "linear", repeat: Infinity, }); return () => controls.stop(); }, [mode, speed, glow]); const i = Math.max(0, intensity); const vars = { "--glow": 1, "--glow-color": color, color: "color-mix(in oklab, var(--glow-color) 35%, white)", // One soft layer: enough to read as neon, not a bloom. textShadow: i === 0 ? undefined : `0 0 calc(${12 * i}px * var(--glow)) color-mix(in oklab, var(--glow-color) 35%, transparent)`, } as React.CSSProperties; // Cast keeps JSX happy with a union of intrinsic tags; every option accepts the same props. const Comp = Tag as "span"; return ( <Comp ref={ref as React.Ref<HTMLSpanElement>} data-slot="glow-text" className={cn("[text-wrap:balance]", className)} style={{ ...vars, ...style }} {...props} > {children} </Comp> ); }
Usage
import { GlowText } from "@/components/dusk/neon/glow-text"
export function PageTitle() {
return (
<GlowText as="h1" color="#22d3ee" className="text-5xl font-bold">
Night Market
</GlowText>
)
}Examples
Animations
none (default) keeps the glow static; breathe slowly swells it; flicker holds steady and occasionally stutters like an old sign. Tune the cycle with speed.
Static
Breathe
Flicker
import { GlowText } from "@/components/dusk/neon/glow-text";
export default function GlowTextAnimationsDemo() {
return (
<div className="grid gap-6 text-center sm:grid-cols-3">
<GlowText as="p" animation="none" className="text-3xl font-semibold">
Static
</GlowText>
<GlowText as="p" animation="breathe" className="text-3xl font-semibold">
Breathe
</GlowText>
<GlowText as="p" animation="flicker" className="text-3xl font-semibold">
Flicker
</GlowText>
</div>
);
}Colors & intensity
Any CSS color works. intensity scales the glow, and the font is entirely yours.
import { GlowText } from "@/components/dusk/neon/glow-text";
export default function GlowTextColorsDemo() {
return (
<div className="flex flex-wrap items-center justify-center gap-x-8 gap-y-4 text-4xl font-bold">
<GlowText color="#22d3ee">Cyan</GlowText>
<GlowText color="#facc15">
Amber
</GlowText>
<GlowText color="#a78bfa" className="font-serif italic">
Violet
</GlowText>
<GlowText color="oklch(0.7 0.25 25)" intensity={0.6}>
Ember
</GlowText>
</div>
);
}Inline
Render it as strong or span to highlight a word inside running text.
Ship animated interfaces with DuskUI. The glow is a plain text-shadow, so the words stay selectable and searchable.
import { GlowText } from "@/components/dusk/neon/glow-text";
export default function GlowTextInlineDemo() {
return (
<p className="max-w-md text-center text-lg leading-relaxed text-white/70">
Ship animated interfaces with{" "}
<GlowText as="strong" intensity={0.7} className="font-semibold">
DuskUI
</GlowText>
. The glow is a plain text-shadow, so the words stay selectable and searchable.
</p>
);
}API Reference
Also accepts any HTML attribute for the rendered element.
| Prop | Type | Default | Description |
|---|---|---|---|
| as | "h1" … "h6" | "p" | "span" | "div" | "strong" | "span" | Element to render. Use a heading level for titles. |
| color | string | var(--color-primary) | Any CSS color for the glow; the letters use a light tint of it. |
| intensity | number | 1 | Glow strength multiplier. 0 removes the glow. |
| animation | "none" | "breathe" | "flicker" | "none" | Glow animation. Always none with reduced motion. |
| speed | number | 3.2 (breathe) / 4 (flicker) | Seconds per cycle. Flicker is clamped to at least 2s. |
| className | string | — | Font size, weight and other text styles. |
Accessibility
- The text is a single real element with no duplicated or aria-hidden copies, so it is selectable, translatable and indexed like any heading.
- Use
asto keep the correct heading level in the document outline. - Only the glow animates; the letters never blink. Flicker produces at most two soft dips per second, under the WCAG 3-flashes threshold.
- With prefers-reduced-motion the glow is static.
- Letters are rendered as a light tint of the color for strong contrast on dark backgrounds.