Neon Button
A React button with a soft neon-tube glow, built on the DuskUI Button with Motion and Tailwind CSS. One glow layer brightens a little on hover and keyboard focus, can flicker on when it scrolls into view, and takes any CSS color. Loading states and every shadcn/ui Button prop keep working.
- Any CSS color
- Flicker-on effect
- Loading state
- Focus-visible glow
- prefers-reduced-motion
import { Zap } from "lucide-react";
import { NeonButton } from "@/components/dusk/neon/neon-button";
export default function NeonButtonDemo() {
return (
<>
<NeonButton size="lg">
<Zap />
Upgrade
</NeonButton>
<NeonButton size="lg" color="#f472b6" flicker>
Book a table
</NeonButton>
<NeonButton size="lg" color="#22d3ee" solid>
Get started
</NeonButton>
</>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/neon-button.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/neon/neon-button.tsx.neon-button.tsx "use client"; import * as React from "react"; import { motion, useReducedMotion, type TargetAndTransition } from "motion/react"; import { MotionButton, type MotionButtonProps } from "@/components/ui/button"; import { cn } from "@/lib/utils"; export interface NeonButtonProps extends Omit<MotionButtonProps, "color" | "variant" | "asChild"> { /** Any CSS color. Defaults to the theme primary. */ color?: string; /** Glow strength multiplier. 0 turns the glow off, 1 is the default. */ intensity?: number; /** Flicker on like a neon tube the first time the button scrolls into view. Skipped for reduced motion. */ flicker?: boolean; /** Filled tube (dark text on the neon color) instead of the outlined default. */ solid?: boolean; } /* * Ignition keyframes for the glow layer. Two soft dips spread over 1.4s: * at most 2 flashes in any one-second window, well under the 3-per-second * photosensitivity limit, and the label itself never blinks. */ const IGNITE: TargetAndTransition = { opacity: [0, 1, 0.35, 1, 0.6, 1], transition: { duration: 1.4, times: [0, 0.15, 0.3, 0.55, 0.75, 1], ease: "easeOut" }, }; /** * A button with a soft neon-tube glow. The single glow layer brightens a * little on hover and keyboard focus, and can optionally flicker on when it * first appears. * * Built on the DuskUI `MotionButton`, so `loading`, `loadingText`, `size` and * every Motion prop keep working. Glow layers are absolutely positioned and * `aria-hidden`, so they never change the button's size. */ export function NeonButton({ color = "var(--color-primary)", intensity = 1, flicker = false, solid = false, className, style, children, ...props }: NeonButtonProps) { const reduceMotion = useReducedMotion(); const ignite = flicker && !reduceMotion; const i = Math.max(0, intensity); const vars = { "--neon": color, "--neon-fg": solid ? "oklch(0.16 0.02 260)" : "color-mix(in oklab, var(--neon) 72%, white)", "--neon-bg": solid ? "var(--neon)" : "color-mix(in oklab, var(--neon) 6%, transparent)", "--neon-bg-hover": solid ? "color-mix(in oklab, var(--neon) 90%, white)" : "color-mix(in oklab, var(--neon) 12%, transparent)", "--neon-ring": "color-mix(in oklab, var(--neon) 45%, transparent)", } as React.CSSProperties; return ( <MotionButton variant="default" className={cn( "group/neon isolate border border-(--neon) bg-(--neon-bg) text-(--neon-fg) shadow-none", "hover:bg-(--neon-bg-hover) focus-visible:border-(--neon) focus-visible:ring-(--neon-ring)", className )} style={{ ...vars, ...style } as MotionButtonProps["style"]} {...props} > {i > 0 && ( <motion.span aria-hidden data-slot="neon-glow" className="pointer-events-none absolute inset-0 -z-10 rounded-[inherit]" initial={ignite ? { opacity: 0 } : false} whileInView={ignite ? IGNITE : undefined} viewport={{ once: true }} > {/* One soft glow layer; hover and focus only raise its opacity. */} <span className="absolute inset-0 rounded-[inherit] opacity-60 transition-opacity duration-200 group-hover/neon:opacity-100 group-focus-visible/neon:opacity-100 motion-reduce:transition-none" style={{ boxShadow: `0 0 ${12 * i}px color-mix(in oklab, var(--neon) 30%, transparent)`, }} /> </motion.span> )} {children} </MotionButton> ); }
Builds on the DuskUI Button; the CLI installs it automatically. Installing by hand? Add components/ui/button.tsx from the Button page first.
Usage
import { NeonButton } from "@/components/dusk/neon/neon-button"
export function HeroCta() {
return (
<NeonButton size="lg" color="#f472b6" flicker>
Get early access
</NeonButton>
)
}Examples
Colors
Pass any CSS color to color — hex, oklch() or a theme variable. The border, text, glow and focus ring are all derived from it with color-mix().
import { NeonButton } from "@/components/dusk/neon/neon-button";
const colors = ["#f472b6", "#22d3ee", "#facc15", "#a78bfa"];
export default function NeonButtonColorsDemo() {
return (
<>
{colors.map((color) => (
<NeonButton key={color} color={color}>
Neon
</NeonButton>
))}
</>
);
}Intensity & solid
intensity scales the glow; 0 turns it off. solid fills the tube for a higher-emphasis call to action.
import { NeonButton } from "@/components/dusk/neon/neon-button";
export default function NeonButtonIntensityDemo() {
return (
<>
<NeonButton intensity={0.5}>Subtle</NeonButton>
<NeonButton>Default</NeonButton>
<NeonButton intensity={0}>No glow</NeonButton>
<NeonButton solid>
Solid tube
</NeonButton>
</>
);
}Loading
loading and loadingText come straight from the base Button: the label crossfades to a spinner without changing the width, and the button stays focusable.
"use client";
import * as React from "react";
import { Rocket } from "lucide-react";
import { NeonButton } from "@/components/dusk/neon/neon-button";
export default function NeonButtonLoadingDemo() {
const [loading, setLoading] = React.useState(false);
const launch = () => {
setLoading(true);
setTimeout(() => setLoading(false), 1800);
};
return (
<NeonButton size="lg" color="#22d3ee" loading={loading} loadingText="Launching…" onClick={launch}>
<Rocket />
Launch
</NeonButton>
);
}API Reference
Also accepts every DuskUI Button prop (size, loading, loadingText, loaderIcon) and Motion props such as whileTap. variant and asChild are not supported.
| Prop | Type | Default | Description |
|---|---|---|---|
| color | string | var(--color-primary) | Any CSS color for the tube, text and glow. |
| intensity | number | 1 | Glow strength multiplier. 0 removes the glow. |
| flicker | boolean | false | Flicker on like a neon tube the first time it scrolls into view. |
| solid | boolean | false | Filled tube with dark text instead of the outline style. |
| className | string | — | Merged with tailwind-merge, so overrides win. |
Accessibility
- Renders a native <button>, so Enter, Space and focus order work as usual.
- Keyboard focus brightens the glow like hover does, plus a focus ring tinted to the neon color.
- The glow layer is aria-hidden and absolutely positioned, so they never shift layout or reach screen readers.
- The flicker-on effect has at most two soft dips per second (under the 3-flashes limit), only dims the glow, and is skipped entirely with prefers-reduced-motion.
- Text is a light tint of the chosen color for strong contrast on dark backgrounds; check contrast if you place it on light surfaces.