Scan Line
A CRT scan line overlay for React: wrap any element to add retro horizontal scanlines, a slowly rolling scan bar, and optional vignette, flicker and screen curvature. Pure CSS with Tailwind — no JavaScript, Server Component friendly, and it never blocks clicks.
- Pure CSS
- Server Component friendly
- pointer-events-none
- Retro CRT
- prefers-reduced-motion
Last login: Mon Nov 23 09:14
Connected to prod-eu-1
3 deploys are queued. Run deploy status to see them.
import { ScanLine } from "@/components/dusk/hacker/scan-line";
export default function ScanLineDemo() {
return (
<ScanLine className="w-full max-w-lg rounded-xl border border-white/10 bg-[oklch(0.1_0.03_150)]">
<div className="space-y-3 p-8 font-mono">
<p className="text-xs text-muted-foreground">Last login: Mon Nov 23 09:14</p>
<h3 className="text-2xl font-semibold text-foreground">Connected to prod-eu-1</h3>
<p className="text-sm leading-relaxed text-muted-foreground">
3 deploys are queued. Run <span className="text-foreground">deploy status</span> to see them.
</p>
</div>
</ScanLine>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/scan-line.json1. Copy the source into
components/dusk/hacker/scan-line.tsx.scan-line.tsx import * as React from "react"; import { cn } from "@/lib/utils"; export interface ScanLineProps extends React.ComponentProps<"div"> { /** Draw horizontal scanlines. */ lines?: boolean; /** Distance between scanlines, in px. */ lineSpacing?: number; /** Darkness of each scanline, 0–1. */ lineOpacity?: number; /** Show the slowly moving bright scan bar. */ bar?: boolean; /** Seconds for the bar to travel from top to bottom. */ barDuration?: number; /** Bar color. Any CSS color, including theme variables. */ barColor?: string; /** Darken the edges like a CRT tube. */ vignette?: boolean; /** Subtle, slow brightness flicker (well under 3 flashes per second). */ flicker?: boolean; /** Fake screen curvature: rounded tube corners, inner shadow and glass glare. */ curvature?: boolean; /** Classes for the overlay layer. */ overlayClassName?: string; } const CSS = ` @keyframes dusk-scan-bar { from { transform: translateY(-60%) } to { transform: translateY(60%) } } @keyframes dusk-scan-flicker { 0%, 100% { opacity: 0.02 } 7% { opacity: 0.05 } 9% { opacity: 0.02 } 46% { opacity: 0.02 } 48% { opacity: 0.045 } 52% { opacity: 0.02 } } .dusk-scan-bar { animation: dusk-scan-bar var(--dusk-scan-duration, 7s) linear infinite } .dusk-scan-flicker { animation: dusk-scan-flicker 3.4s steps(1, end) infinite } @media (prefers-reduced-motion: reduce) { .dusk-scan-bar { display: none } .dusk-scan-flicker { animation: none } } `; /** * Wrap anything to give it a CRT monitor look: fine horizontal scanlines, * a bright scan bar that slowly rolls down, plus optional vignette, flicker * and fake curvature. * * The overlay is pure CSS (no JavaScript, works in Server Components), sits * above the content with `pointer-events: none` and is `aria-hidden`, so * links, text selection and screen readers keep working. Under reduced * motion the bar and flicker are turned off and only static effects remain. */ export function ScanLine({ lines = true, lineSpacing = 3, lineOpacity = 0.25, bar = true, barDuration = 7, barColor = "rgb(255 255 255)", vignette = true, flicker = false, curvature = false, overlayClassName, className, style, children, ...props }: ScanLineProps) { const spacing = Math.max(2, lineSpacing); const dark = `rgb(0 0 0 / ${Math.min(1, Math.max(0, lineOpacity))})`; return ( <div data-slot="scan-line" className={cn("relative isolate overflow-hidden", curvature && "rounded-[2rem/1.5rem]", className)} style={style} {...props} > <style href="duskui-scan-line" precedence="duskui"> {CSS} </style> {children} <div aria-hidden className={cn("pointer-events-none absolute inset-0 z-10 overflow-hidden", curvature && "rounded-[inherit]", overlayClassName)} > {lines && ( <div className="absolute inset-0" style={{ // A dark line plus a faint light one, so the lines show on dark and light content. backgroundImage: `repeating-linear-gradient(to bottom, rgb(255 255 255 / 0.025) 0 1px, transparent 1px ${spacing - 1}px, ${dark} ${spacing - 1}px ${spacing}px)`, }} /> )} {bar && ( <div className="dusk-scan-bar absolute inset-x-0 top-0 h-full mix-blend-screen will-change-transform" style={ { "--dusk-scan-duration": `${barDuration}s`, backgroundImage: `linear-gradient(to bottom, transparent 38%, color-mix(in oklab, ${barColor} 3%, transparent) 46%, color-mix(in oklab, ${barColor} 7%, transparent) 49.6%, color-mix(in oklab, ${barColor} 12%, transparent) 50%, transparent 50.4%)`, } as React.CSSProperties } /> )} {flicker && <div className="dusk-scan-flicker absolute inset-0 bg-white opacity-[0.02]" />} {vignette && ( <div className="absolute inset-0 bg-[radial-gradient(ellipse_at_center,transparent_55%,rgb(0_0_0/0.4)_100%)]" /> )} {curvature && ( <div className="absolute inset-0 rounded-[inherit] bg-[radial-gradient(ellipse_at_28%_18%,rgb(255_255_255/0.07),transparent_45%)] shadow-[inset_0_0_0_1px_rgb(255_255_255/0.05),inset_0_0_70px_rgb(0_0_0/0.65)]" /> )} </div> </div> ); }
No dependencies and no "use client". The keyframes ship in a React 19 <style precedence> tag that's hoisted and de-duplicated automatically.
Usage
import { ScanLine } from "@/components/dusk/hacker/scan-line"
export function Screen() {
return (
<ScanLine className="rounded-xl bg-black p-8">
<h2 className="font-mono text-primary">ACCESS GRANTED</h2>
</ScanLine>
)
}Examples
Retro CRT
Turn on curvature and flicker, space the lines with lineSpacing and lineOpacity, and tint the scan bar with barColor and barDuration.
READY.
10 PRINT "HELLO"
20 GOTO 10
RUN
import { ScanLine } from "@/components/dusk/hacker/scan-line";
export default function ScanLineCrtDemo() {
return (
<ScanLine
curvature
lineSpacing={4}
lineOpacity={0.35}
barColor="#fbbf24"
barDuration={5}
className="w-full max-w-md bg-[#140d02]"
>
<div className="flex aspect-[4/3] flex-col justify-center gap-2 p-10 font-mono text-amber-300">
<p className="text-xs text-amber-300/70">READY.</p>
<p className="text-2xl font-bold">10 PRINT "HELLO"</p>
<p className="text-2xl font-bold">20 GOTO 10</p>
<p className="text-sm text-amber-300/70">RUN</p>
</div>
</ScanLine>
);
}Over Matrix Rain
It wraps anything — including canvas backgrounds like MatrixRain, which fills the relative wrapper.
import { MatrixRain } from "@/components/dusk/hacker/matrix-rain";
import { ScanLine } from "@/components/dusk/hacker/scan-line";
export default function ScanLineMatrixDemo() {
return (
<ScanLine className="h-80 w-full rounded-lg bg-black" barDuration={6}>
<MatrixRain fontSize={14} />
</ScanLine>
);
}API Reference
Also accepts any <div> prop. The wrapper is relative overflow-hidden.
| Prop | Type | Default | Description |
|---|---|---|---|
| lines | boolean | true | Draw horizontal scanlines. |
| lineSpacing | number | 3 | Distance between scanlines, in px (min 2). |
| lineOpacity | number | 0.25 | Darkness of each scanline, 0–1. |
| bar | boolean | true | Show the rolling scan bar. |
| barDuration | number | 7 | Seconds for the bar to travel top to bottom. |
| barColor | string | "rgb(255 255 255)" | Bar color; any CSS color. |
| vignette | boolean | true | Darken the edges like a CRT tube. |
| flicker | boolean | false | Subtle brightness flicker, under one blip per second. |
| curvature | boolean | false | Rounded tube corners, inner shadow and glass glare. |
| overlayClassName | string | — | Classes for the overlay layer. |
Accessibility
- The overlay is aria-hidden and pointer-events-none, so links, buttons and text selection underneath keep working.
- The flicker is a tiny brightness change (a few percent) at well under one blip per second — far below the 3-flashes-per-second threshold.
- With prefers-reduced-motion the scan bar is hidden and the flicker stops; static lines and vignette remain.
- Scanlines and vignette darken content, so check text contrast and lower lineOpacity for small text.