Electric Border shader preview: Living energy crackling around a card's edge.
ittybitty

Electric Border

Living energy crackling around a card's edge.

Code

The usage always matches the preview, layers and performance settings included. No build step or package.

Use as
Code view

Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add electric-border.js, ittybitty-shader.js, runtime.js, pointer.js next to this page. Highlighted values follow the controls.

<!-- Quickest: one element. Size it with CSS; it fills its box. -->
<script type="module" src="./ittybitty-shader.js"></script>
<ittybitty-shader effect="electric-border" style="position: absolute; inset: -32px; width: calc(100% + 64px); height: calc(100% + 64px); pointer-events: none"></ittybitty-shader>

<!-- Or with JavaScript, for full control: -->
<div style="position: relative">
  <!-- your content -->
  <canvas id="electric-border" aria-hidden="true" style="position: absolute; inset: -32px; width: calc(100% + 64px); height: calc(100% + 64px); pointer-events: none"></canvas>
</div>

<script type="module">
  import { electricBorder } from './electric-border.js';

  const canvas = document.getElementById('electric-border');
  const effect = electricBorder(canvas, {
    showBorder: true,
    showGlow: true,
    showFill: true,
    speed: 0.8,
    inset: 120,
    radius: 28,
    thickness: 1.5,
    turbulence: 0.6,
    glow: 0.6,
    style: 'electric',
    interactive: true,
    responsiveness: 0.5,
    palette: [[0, '#6be4ff'], [0.5, '#8f7bff'], [1, '#6be4ff']],
    fill: '#0e0f14',
    // Performance
    dpr: 2,
    adaptive: true,
  });

  // Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>

Details

A crackling core line, flickering arcs and a soft glow run around a rounded rectangle. The canvas sits over your card and bleeds past it by Inset pixels so the glow has room. It is transparent outside the border, and can paint the card surface too.

Payload
6.2 KB brotli for electric-border.js and ittybitty-shader.js and runtime.js and pointer.js, measured at build time. See the method.
Resolution
Device pixel ratio capped at 2, so the line stays fine.
Frame rate
Display rate.
When unseen
Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
Reduced motion
Shows a single still frame. Controls still update it.
Layers
Up to five effects fuse into one shader and one draw call. Filters such as dithering and halftone process the layers beneath them.
Browsers
Any browser with WebGL2: Chrome and Edge 56+, Firefox 51+, Safari 15+.
Licence
MIT. Copy it, change it, ship it.