A crackling line of electricity wraps a dark panel and jumps between three shapes like an arc. SVG turbulence displaces each copy of the outline, and a stepped opacity loop flips between them.
Also known as: lightning border css, electric border animation, crackling energy border.
<div class="bdr-electric-border">
<svg class="bdr-electric-border-svg" viewBox="0 0 150 85" preserveAspectRatio="none" aria-hidden="true">
<defs>
<filter id="bdr-electric-border-a" x="-10%" y="-15%" width="120%" height="130%"><feTurbulence type="turbulence" baseFrequency="0.06" numOctaves="2" seed="2"/><feDisplacementMap in="SourceGraphic" scale="5"/></filter>
<filter id="bdr-electric-border-b" x="-10%" y="-15%" width="120%" height="130%"><feTurbulence type="turbulence" baseFrequency="0.06" numOctaves="2" seed="7"/><feDisplacementMap in="SourceGraphic" scale="5"/></filter>
<filter id="bdr-electric-border-c" x="-10%" y="-15%" width="120%" height="130%"><feTurbulence type="turbulence" baseFrequency="0.06" numOctaves="2" seed="13"/><feDisplacementMap in="SourceGraphic" scale="5"/></filter>
</defs>
<rect class="bdr-electric-border-halo" x="3" y="3" width="144" height="79" rx="9"/>
<rect class="bdr-electric-border-arc" x="3" y="3" width="144" height="79" rx="9" filter="url(#bdr-electric-border-a)"/>
<rect class="bdr-electric-border-arc" x="3" y="3" width="144" height="79" rx="9" filter="url(#bdr-electric-border-b)"/>
<rect class="bdr-electric-border-arc" x="3" y="3" width="144" height="79" rx="9" filter="url(#bdr-electric-border-c)"/>
</svg>
<span class="bdr-electric-border-text">High voltage</span>
</div>.bdr-electric-border {
--c: var(--bdr-color, #3b82f6);
font-size: var(--bdr-size, 16px);
position: relative;
display: grid;
place-items: center;
width: 15em;
height: 8.5em;
border-radius: 1em;
font-family: system-ui, sans-serif;
font-weight: 600;
background: color-mix(in srgb, var(--c) 8%, #07070c);
color: color-mix(in srgb, var(--c) 30%, #fff);
}
.bdr-electric-border-svg {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
overflow: visible;
filter: drop-shadow(0 0 0.2em var(--c)) drop-shadow(0 0 0.5em color-mix(in srgb, var(--c) 70%, transparent));
pointer-events: none;
}
.bdr-electric-border-svg rect { fill: none; }
.bdr-electric-border-halo {
stroke: color-mix(in srgb, var(--c) 30%, transparent);
stroke-width: 2.5;
}
.bdr-electric-border-arc {
stroke: color-mix(in srgb, var(--c) 45%, #fff);
stroke-width: 1.2;
opacity: 0;
animation: bdr-electric-border-zap 0.36s step-end infinite;
}
.bdr-electric-border-arc:nth-of-type(3) { animation-delay: -0.12s; }
.bdr-electric-border-arc:nth-of-type(4) { animation-delay: -0.24s; }
.bdr-electric-border-text {
position: relative;
letter-spacing: 0.04em;
text-shadow: 0 0 0.4em var(--c);
}
@keyframes bdr-electric-border-zap {
0% { opacity: 1; }
33.3%, 100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
.bdr-electric-border, .bdr-electric-border *, .bdr-electric-border::before, .bdr-electric-border::after, .bdr-electric-border *::before, .bdr-electric-border *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--bdr-color on the element or a parent.
Currently previewing #3b82f6.--bdr-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 16px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.