Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="bard">
  <div class="strip" style="
    --glitch-x-1: -2em;
    --glitch-hue-1: -16deg;
    --glitch-x-2: 2em;
    --glitch-hue-2: 13deg;

    background-position: 0 -0em;
    height: 5em; 
    animation-name: glitch-9;
    animation-duration: 9000ms; 
    animation-delay: 2s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -1em;
    --glitch-hue-1: -42deg;
    --glitch-x-2: -6em;
    --glitch-hue-2: -23deg;

    background-position: 0 -5em;
    height: 3em; 
    animation-name: glitch-5;
    animation-duration: 5000ms; 
    animation-delay: 1s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -10em;
    --glitch-hue-1: -42deg;
    --glitch-x-2: -9em;
    --glitch-hue-2: 45deg;

    background-position: 0 -8em;
    height: 3em; 
    animation-name: glitch-7;
    animation-duration: 7000ms; 
    animation-delay: 0s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -6em;
    --glitch-hue-1: -11deg;
    --glitch-x-2: 2em;
    --glitch-hue-2: 29deg;

    background-position: 0 -11em;
    height: 5em; 
    animation-name: glitch-8;
    animation-duration: 8000ms; 
    animation-delay: 1s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: 0em;
    --glitch-hue-1: 42deg;
    --glitch-x-2: 2em;
    --glitch-hue-2: -28deg;

    background-position: 0 -16em;
    height: 5em; 
    animation-name: glitch-6;
    animation-duration: 6000ms; 
    animation-delay: 0s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -3em;
    --glitch-hue-1: -45deg;
    --glitch-x-2: -5em;
    --glitch-hue-2: -15deg;

    background-position: 0 -21em;
    height: 2em; 
    animation-name: glitch-7;
    animation-duration: 7000ms; 
    animation-delay: 0s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -5em;
    --glitch-hue-1: 35deg;
    --glitch-x-2: 9em;
    --glitch-hue-2: 35deg;

    background-position: 0 -23em;
    height: 2em; 
    animation-name: glitch-6;
    animation-duration: 6000ms; 
    animation-delay: 0s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: 10em;
    --glitch-hue-1: 39deg;
    --glitch-x-2: -8em;
    --glitch-hue-2: 24deg;

    background-position: 0 -25em;
    height: 6em; 
    animation-name: glitch-7;
    animation-duration: 7000ms; 
    animation-delay: 1s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -6em;
    --glitch-hue-1: -46deg;
    --glitch-x-2: -3em;
    --glitch-hue-2: 18deg;

    background-position: 0 -31em;
    height: 6em; 
    animation-name: glitch-10;
    animation-duration: 10000ms; 
    animation-delay: 1s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -8em;
    --glitch-hue-1: -37deg;
    --glitch-x-2: -6em;
    --glitch-hue-2: 15deg;

    background-position: 0 -37em;
    height: 1em; 
    animation-name: glitch-9;
    animation-duration: 9000ms; 
    animation-delay: 1s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -1em;
    --glitch-hue-1: 16deg;
    --glitch-x-2: 2em;
    --glitch-hue-2: 25deg;

    background-position: 0 -38em;
    height: 2em; 
    animation-name: glitch-5;
    animation-duration: 5000ms; 
    animation-delay: 1s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: 5em;
    --glitch-hue-1: 32deg;
    --glitch-x-2: 10em;
    --glitch-hue-2: -3deg;

    background-position: 0 -40em;
    height: 2em; 
    animation-name: glitch-9;
    animation-duration: 9000ms; 
    animation-delay: 1s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: 10em;
    --glitch-hue-1: -26deg;
    --glitch-x-2: 6em;
    --glitch-hue-2: -45deg;

    background-position: 0 -42em;
    height: 4em; 
    animation-name: glitch-6;
    animation-duration: 6000ms; 
    animation-delay: 1s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -7em;
    --glitch-hue-1: -45deg;
    --glitch-x-2: -8em;
    --glitch-hue-2: 45deg;

    background-position: 0 -46em;
    height: 3em; 
    animation-name: glitch-5;
    animation-duration: 5000ms; 
    animation-delay: 2s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: 4em;
    --glitch-hue-1: 40deg;
    --glitch-x-2: -8em;
    --glitch-hue-2: 29deg;

    background-position: 0 -49em;
    height: 3em; 
    animation-name: glitch-6;
    animation-duration: 6000ms; 
    animation-delay: 1s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: -4em;
    --glitch-hue-1: 26deg;
    --glitch-x-2: -6em;
    --glitch-hue-2: -3deg;

    background-position: 0 -52em;
    height: 6em; 
    animation-name: glitch-10;
    animation-duration: 10000ms; 
    animation-delay: 0s;
  "></div>

  <div class="strip" style="
    --glitch-x-1: 6em;
    --glitch-hue-1: 43deg;
    --glitch-x-2: -1em;
    --glitch-hue-2: -1deg;

    background-position: 0 -58em;
    height: 4em; 
    animation-name: glitch-8;
    animation-duration: 8000ms; 
    animation-delay: 0s;
  "></div>
</div>

<p>
  The effect itself is CSS-only, although styles are generated by JavaScript. Feel free to check the JavaScript code, but you'll see it is commented out.
</p>
<p>
  For details read the <a target="_parent" href="https://muffinman.io/blog/css-image-glitch/">blog post</a>.
</p>

<div class="debug">
  <div class="code"></div>
</div>
              
            
!

CSS

              
                body {
  background: #0d0a14;
  padding: 40px 20px;
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas,
    "DejaVu Sans Mono", monospace;
  color: #9d9aa4;
}

.bard {
  margin: 0 auto 40px;
  width: 65em;
  height: 62em;
  font-size: 2px;

  @media (min-width: 360px) {
    font-size: 3px;
  }

  @media (min-width: 600px) {
    font-size: 4px;
  }

  @media (min-width: 1000px) {
    font-size: 5px;
  }
}

.bard img {
  width: 100%;
  height: auto;
  position: absolute;
  left: 0;
  top: 0;
}

.strip {
  overflow: hidden;
  position: relative;
  animation-iteration-count: infinite;
  animation-direction: alternate;
  animation-timing-function: linear;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  background-size: 100% auto;
  // base64 encoded image
  background-image: url(data:image/gif;base64,R0lGODdhQQA+AHcAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQJCgAAACwAAAAAQQA+AIMAAAAYESMiGisyLDt+GRk9MFO8OjrbR19rf4Ee5Ot+6+qNwbkAAAAAAAAAAAAAAAAE/xDISau9FOnFF/5gKFYaUpxo0Y1si2lpnHJuPcJyjtJ2n5m64M7jq+GEyBOvGDomnyoi0+KEWpfTqnUbZWq5YCzrCy53x+a0TgoCqt8zkRsOZ18Gc7p6gQAN8HpvfH0Yfyd5gVAKiwoahQV/homKjSWNGJCRf4iTKYsloAp3mqSciZ+gqYQUmaSapm+oqqEWra6vgbKztBW2t7hquru8rL/GsELCw8QTvsalVsrLzBLOz6XI0tPUANbXrqAdHNvbor3XAQHfOeQlkarmxcYBAgLpz3mD5H8J/anxzZ7Rq2cP3452CPj182eplkCCBZ8d3DcgwaKFCRqemwdRnUF92//4MVqoUZ6Bk6QG1vMoEeQyhRYvZtQAsNrJmyj/qIz4zKWGd6BgxlQwE0FNnDcPHIi0k6UxnzCDVsR4sSTSk0qVMu34zaXQol9J0gRw1UDWrFsJOv0FUiRRsWGLGiVAAOfZs2lXdpU6FO5UjHIV0KV7925enk/d/R0J9i9DS4MJFMark+s1fUJH8u2HJ1Tk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K91wEB3znkJZGq5sXGBfTpz3mD5H8I/Knxzb/oCax3b0e7A/v49bNUy9VAgQYMqHtmUJ8ABIsUImB4LtJDehH/I048puLgPkYKOcr7WCBkyJHGSlpUiHKjhn/VBAwYMNClS5i/8oF6N/QizYwqAe7c6dMn0FtCNSS0KdXoUao4u+lc2vTnt6hTFyK0qhFrw6UDur78WhRjAo1Vy4o9kBUSWrUi2bq7WNNm2JRJc97F+9RVvqk195b1d5YrYb1jNaJsyw8PN7uO1RYmdZisW6pVNzE+N1gz5L+AydXdyvTxtc5yQZdr3Nr0a8VyD9K9QKB0182ahP7VnbWa75/Ag6eaarldcQnHDXzjrOrVwefQM0ufTl33MOzG027n3t07vBHkn0U172iEt/TrzdsBcSK94eW6xbh/f9vdQf0u1GffRGFSTQNgDwJyR6CB803RDX/KIcSgg/RBKMAgzalyIIW98EdAgRo2yOEHCWoCSXwbjlihiZEIlaKKIqTA2QowUpgDhxEAACH5BAUKAAAALAAAAABBAD4AgQAAADIsO34ZGT0wUwJphI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+DwwKh8RGQCAIBo7IpG9pQP6gAOkzEHX2qNYttqrlccO78fTbFaPJOvM1e4b7BusffZn2Uov8vv8PGCg4SFhoSFMAACH5BAVkAAAALAAAAABBAD4AgQAAADIsO34ZGQAAAAJnhI+py+0Po5y02ouz3rz7D4biSJbmiabqyrbuC8fyTNf2jef6zvf+DwwKh46AQBAMGI9In9Jw/D0BUWcA2uxNq9orNcvbgndiqZcbPo91ZSvW/HZ/zUp0d0rM6/f8vv8PGCg4SDhTAAA7);
}

@keyframes glitch-5 {
  0.00%,
  33.33%,
  43.33%,
  66.67%,
  76.67%,
  100.00% {
    transform: none;
    filter: hue-rotate(0) drop-shadow(0 0 0 transparent);
  }

  33.43%,
  43.23% {
    transform: translateX(var(--glitch-x-1));
    filter: hue-rotate(var(--glitch-hue-1))
      drop-shadow(0px -4px 0 rgb(0 0 255 / 0.1));
  }

  66.77%,
  76.57% {
    transform: translateX(var(--glitch-x-2));
    filter: hue-rotate(var(--glitch-hue-2))
      drop-shadow(-1px 0px 0 rgb(255 0 0 / 0.1));
  }
}

@keyframes glitch-6 {
  0.00%,
  33.33%,
  41.67%,
  66.67%,
  75.00%,
  100.00% {
    transform: none;
    filter: hue-rotate(0) drop-shadow(0 0 0 transparent);
  }

  33.43%,
  41.57% {
    transform: translateX(var(--glitch-x-1));
    filter: hue-rotate(var(--glitch-hue-1))
      drop-shadow(-2px 3px 0 rgb(255 0 0 / 0.1));
  }

  66.77%,
  74.90% {
    transform: translateX(var(--glitch-x-2));
    filter: hue-rotate(var(--glitch-hue-2))
      drop-shadow(-3px -2px 0 rgb(0 0 255 / 0.1));
  }
}

@keyframes glitch-7 {
  0.00%,
  33.33%,
  40.48%,
  66.67%,
  73.81%,
  100.00% {
    transform: none;
    filter: hue-rotate(0) drop-shadow(0 0 0 transparent);
  }

  33.43%,
  40.38% {
    transform: translateX(var(--glitch-x-1));
    filter: hue-rotate(var(--glitch-hue-1))
      drop-shadow(0px -3px 0 rgb(0 0 255 / 0.1));
  }

  66.77%,
  73.71% {
    transform: translateX(var(--glitch-x-2));
    filter: hue-rotate(var(--glitch-hue-2))
      drop-shadow(4px 1px 0 rgb(255 0 0 / 0.1));
  }
}

@keyframes glitch-8 {
  0.00%,
  33.33%,
  39.58%,
  66.67%,
  72.92%,
  100.00% {
    transform: none;
    filter: hue-rotate(0) drop-shadow(0 0 0 transparent);
  }

  33.43%,
  39.48% {
    transform: translateX(var(--glitch-x-1));
    filter: hue-rotate(var(--glitch-hue-1))
      drop-shadow(-1px -1px 0 rgb(0 0 255 / 0.1));
  }

  66.77%,
  72.82% {
    transform: translateX(var(--glitch-x-2));
    filter: hue-rotate(var(--glitch-hue-2))
      drop-shadow(3px -1px 0 rgb(0 0 255 / 0.1));
  }
}

@keyframes glitch-9 {
  0.00%,
  33.33%,
  38.89%,
  66.67%,
  72.22%,
  100.00% {
    transform: none;
    filter: hue-rotate(0) drop-shadow(0 0 0 transparent);
  }

  33.43%,
  38.79% {
    transform: translateX(var(--glitch-x-1));
    filter: hue-rotate(var(--glitch-hue-1))
      drop-shadow(1px -3px 0 rgb(255 0 0 / 0.1));
  }

  66.77%,
  72.12% {
    transform: translateX(var(--glitch-x-2));
    filter: hue-rotate(var(--glitch-hue-2))
      drop-shadow(1px 1px 0 rgb(255 0 0 / 0.1));
  }
}

@keyframes glitch-10 {
  0.00%,
  33.33%,
  38.33%,
  66.67%,
  71.67%,
  100.00% {
    transform: none;
    filter: hue-rotate(0) drop-shadow(0 0 0 transparent);
  }

  33.43%,
  38.23% {
    transform: translateX(var(--glitch-x-1));
    filter: hue-rotate(var(--glitch-hue-1))
      drop-shadow(3px -1px 0 rgb(255 0 0 / 0.1));
  }

  66.77%,
  71.57% {
    transform: translateX(var(--glitch-x-2));
    filter: hue-rotate(var(--glitch-hue-2))
      drop-shadow(-3px 2px 0 rgb(255 0 0 / 0.1));
  }
}

// ----- Debug ----- //

p {
  margin: 20px auto 0;
  position: relative;
  max-width: 400px;
  text-align: center;
  line-height: 1.3;
  font-size: 0.875rem;
}

a {
  color: #6be1e9;
}

a:focus,
a:hover,
a:visited {
  opacity: 0.8;
}

a:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.debug {
  margin: 40px auto 0;
  position: relative;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
}

.code {
  margin: 10px auto 0;

  @media (min-width: 600px) {
    display: flex;
    gap: 32px;
    justify-content: center;
    align-items: flex-start;
  }
}

.heading {
  margin: 0 0 10px;
  font-size: 1.5rem;
  font-weight: bold;
}

.column {
  border: 1px solid rgb(255 255 255 / 0.1);
  padding: 10px;
  border-radius: 4px;
  color: #e8c57d;
}

.column + .column {
  color: #aa95bd;
}

              
            
!

JS

              
                const random = (min: number, max: number): number => {
  return Math.round(Math.random() * (max - min)) + min;
};

const getKeyFrames = (
  name: string,
  glitchPercentageDuration: number,
  steps: number = 3,
  tick: number = 0.1
): string => {
  const percentageStep = 100 / steps;

  const keyframes: {
    keys: number[];
    css: Record<string, string | number>;
  }[] = [];

  // First keyframe
  const baseKeys = [0];

  for (let i = 1; i < steps; i++) {
    const p = i * percentageStep;
    baseKeys.push(p);
    baseKeys.push(p + glitchPercentageDuration);
  }

  // Last keyframe
  baseKeys.push(100);

  keyframes.push({
    keys: baseKeys,
    css: {
      transform: "none",
      filter: "hue-rotate(0) drop-shadow(0 0 0 transparent)" // Hack to force animation in Safari
    }
  });

  for (let i = 1; i < steps; i++) {
    const p = i * percentageStep;

    // Blue / red shadow
    const color =
      Math.random() > 0.5 ? "rgb(255 0 0 / 0.1)" : "rgb(0 0 255 / 0.1)";
    const shadowX = random(-4, 4);
    const shadowY = random(-4, 4);

    keyframes.push({
      keys: [p + tick, p + glitchPercentageDuration - tick],
      css: {
        transform: `translateX(var(--glitch-x-${i}))`,
        filter: `hue-rotate(var(--glitch-hue-${i})) drop-shadow(${shadowX}px ${shadowY}px 0 ${color})`
      }
    });
  }

  const css = keyframes
    .map((keyframe) => {
      const keys = keyframe.keys
        .map((key) => `${key.toFixed(2)}%`)
        .join(",\n  ");

      const content = Object.entries(keyframe.css)
        .map(([key, value]) => `  ${key}: ${value};`)
        .join("\n  ");

      return [keys, "{", content, "}"].join("\n  ");
    })
    .join("\n\n  ");

  return `@keyframes ${name} {\n  ${css}\n}`;
};

const getStripHTML = (top: number, stripHeight: number): string => {
  const duration = random(5, 10);
  const name = `glitch-${duration}`;

  return `<div 
  class="strip" 
  style="
    --glitch-x-1: ${random(-10, 10)}em;
    --glitch-hue-1: ${random(-50, 50)}deg;
    --glitch-x-2: ${random(-10, 10)}em;
    --glitch-hue-2: ${random(-50, 50)}deg;

    background-position: 0 -${top}em;
    height: ${stripHeight}em; 
    animation-name: ${name};
    animation-duration: ${duration * 1000}ms; 
    animation-delay: ${random(0, 2)}s;
  "
></div>`;
};

const getGlitchHTML = (height: number): string[] => {
  let i = 0;
  const html: string[] = [];

  while (1) {
    const stripHeight = random(1, 6);

    if (i + stripHeight < height) {
      const strip = getStripHTML(i, stripHeight);
      html.push(strip);
    } else {
      // Last strip
      const strip = getStripHTML(i, height - i);
      html.push(strip);
      break;
    }

    i = i + stripHeight;
  }

  return html;
};

/*

If you want to generate new CSS/HTML dinamically,
uncomment the code below.

*/

// const html = getGlitchHTML(62);

// // HTML
// const $glitch = document.querySelector(".bard") as HTMLElement;
// $glitch.innerHTML = html.join("\n");

// // CSS
// const css = [5,6,7,8,9,10].map((n) => {
//   const glitchDurationMS = 500;
//   const glitchPercentageDuration = (glitchDurationMS * 100) / (n * 1000);

//   return getKeyFrames(`glitch-${n}`, glitchPercentageDuration);
// });

// // Add generated CSS to the page
// const $style = document.createElement("style");
// $style.innerHTML = css.join("\n");
// document.head.appendChild($style);

// // ----- Debug -------------- //
// // Not used for the animation //

// const $code = document.querySelector(".code");

// const escape = (html) => {
//   return html
//     .replace(/&/g, "&amp;")
//     .replace(/</g, "&lt;")
//     .replace(/>/g, "&gt;")
//     .replace(/"/g, "&quot;")
//     .replace(/'/g, "&#039;");
// };

// $code.innerHTML = `
//   <div class="column">
//     <div class="heading">HTML</div>
//     <pre>${escape(html.join("\n\n"))}</pre>
//   </div>

//   <div class="column">
//     <div class="heading">CSS</div>
//     <pre>${css.join("\n\n")}</pre>
//   </div>
// `;

              
            
!
999px

Console