Source:CSS

DPI-Locked Scanlines

Locks the scanline period to integer device pixels using CSS round() and the --dpr CSS variable, preventing subpixel shimmer and moiré artifacts at fractional display scales.

crt-screen-dpi.css.ts
const devicePixelRatio = 'var(--dpr, 1)';
const snapToDevicePixels = (cssPixels: string) => [
`calc(round(${cssPixels} * ${devicePixelRatio}, 1)`,
`* 1px / ${devicePixelRatio})`,
].join(' ');
const scanLinePeriod = snapToDevicePixels('4');
const scanLineOverlayStyles = {
position: 'fixed',
background: `repeating-linear-gradient(0deg, black, white ${scanLinePeriod})`,
mixBlendMode: 'overlay',
} as const;
ts

Experiments