Web Design

How to Create a Glitch Text Effect With CSS

A glitch effect heading with cyan and magenta slices next to a snippet of CSS code

A glitch heading, with slices of color jumping out of line as if the screen is failing, is a striking effect for game sites, portfolios and event pages. You can build it with plain HTML and CSS, without images or JavaScript. This tutorial explains each step and the accessibility details that most examples miss. To skip ahead, the CSS glitch text effect tool builds the code for you.

Step 1: The HTML

Start with a normal heading. Repeat the text in a data-text attribute, so CSS can make copies of it:

<h1 class="glitch" data-text="GAME OVER">GAME OVER</h1>

The heading stays real text, so it is readable by screen readers, searchable and translatable. Never use Unicode Zalgo text for a web heading; create the look with CSS instead.

Step 2: Style the heading

.glitch {
  position: relative;
  display: inline-block;
  color: #ffffff;
  font: 800 72px/1.1 system-ui, sans-serif;
}

position: relative lets the copies be placed exactly on top of the heading. Heavy, wide fonts show the effect best.

Step 3: Make two copies

.glitch::before,
.glitch::after {
  content: attr(data-text);
  content: attr(data-text) / "";
  position: absolute;
  inset: 0;
}

The ::before and ::after pseudo-elements repeat the heading using attr(data-text), and inset: 0 lays them exactly over it.

The second content line matters. Generated content is read by screen readers, so without it many would read “GAME OVER GAME OVER GAME OVER.” The / "" part gives the copies an empty text alternative, so they are skipped. Browsers that do not support the syntax ignore that line and use the first one.

Step 4: Shift and color the copies

.glitch::before {
  left: 3px;
  text-shadow: -3px 0 #2de2e6;
  clip-path: inset(10% 0 60% 0);
}

.glitch::after {
  left: -3px;
  text-shadow: 3px 0 #ff3ea5;
  clip-path: inset(60% 0 5% 0);
}

Each copy moves a few pixels sideways and gets a colored shadow, like the red and blue channels of a badly tuned screen. clip-path: inset(top right bottom left) crops each copy to a horizontal strip, so only a slice of it shows.

Step 5: Animate the slices

.glitch::before {
  animation: glitch-top 2.5s 3 linear alternate-reverse;
}

@keyframes glitch-top {
  0%   { clip-path: inset(10% 0 60% 0); }
  20%  { clip-path: inset(45% 0 30% 0); }
  40%  { clip-path: inset(5% 0 80% 0); }
  60%  { clip-path: inset(70% 0 10% 0); }
  80%  { clip-path: inset(25% 0 55% 0); }
  100% { clip-path: inset(50% 0 35% 0); }
}

The animation moves the strip up and down so different parts of the text jump. Give ::after its own keyframes and a slightly different duration, and the two copies never line up the same way twice.

Step 6: Make the motion accessible

Movement can make some people feel sick, dizzy or distracted. Two rules help:

  • Respect reduced motion. Turn the animation off for visitors who have asked their device for less motion:
    @media (prefers-reduced-motion: reduce) {
      .glitch::before,
      .glitch::after {
        animation: none;
      }
    }
  • Let it stop. WCAG 2.2.2 (Pause, Stop, Hide) says motion that starts automatically, lasts more than five seconds and sits alongside other content needs a way to pause or hide it. The 3 in the animation above plays three cycles and stops. You can also run the animation only on :hover.

Also avoid fast, high-contrast flashing. Content that flashes more than three times a second can trigger seizures (WCAG 2.3.1).

Variations to try

  • Swap cyan and magenta for one brand color and white for a subtler effect.
  • Add transform: translateX() steps to the keyframes for a shakier glitch.
  • Use the effect on a hover state for buttons or links, so it only appears when someone points at it.

Want to play with settings first? The CSS glitch text effect tool previews every change live and writes the finished code, accessibility rules included. For glitch text you can paste into apps instead, use the glitch text generator, and read is glitch text accessible? before you do.

Share this

Text generators