Problem: Glitch Text Animation
Problem description
Given an HTML page containing a single <h1 class="glitch">Glitch Text</h1> element, write CSS to:
Position
.glitchasrelativeand set a fallback font style.Use
::beforeand::afterpseudo-elements to duplicate the text content (viacontent: attr(data-text)), absolutely positioned over the original.Style the pseudo-elements with
text-shadowoffsets in red and cyan to simulate color channel separation.Define a
@keyframes glitchShiftanimation that at multiple percentages:Applies small horizontal
transform: translateX(...)shifts.Adjusts
clip-path: inset(...)to show random slices of text.
Apply
glitchShiftto::beforewith2s steps(2, end) infiniteand to::afterwith2s steps(3, end) infinite, offset by differentanimation-delayvalues.
Goal
Animate the <h1> so it flickers with intermittent horizontal shifts, colored channel offsets, and random text slices, creating a convincing glitch effect without JavaScript.
Constraints
Use only CSS (no JavaScript).
Base element should be
<h1 class="glitch" data-text="Glitch Text">Glitch Text</h1>.Pseudo-elements must use
content: attr(data-text).Text-shadowcolors should be#f00for::beforeand#0fffor::after.Keyframes
glitchShiftmust include at least five distinct stops (e.g.,0%,20%,40%,60%,80%, and100%), each with differenttransformandclip-pathvalues.Animation durations should be
2s; timing functions should besteps(2)for::beforeandsteps(3)for::after; infinite iteration.Use different
animation-delayfor each pseudo-element to desynchronize effects (e.g.,0s,-1s).
Sample visual output
Here’s what the output would look like:
Good luck trying the problem! If you’re unsure how to proceed, check the Solution.
Problem: Glitch Text Animation
Problem description
Given an HTML page containing a single <h1 class="glitch">Glitch Text</h1> element, write CSS to:
Position
.glitchasrelativeand set a fallback font style.Use
::beforeand::afterpseudo-elements to duplicate the text content (viacontent: attr(data-text)), absolutely positioned over the original.Style the pseudo-elements with
text-shadowoffsets in red and cyan to simulate color channel separation.Define a
@keyframes glitchShiftanimation that at multiple percentages:Applies small horizontal
transform: translateX(...)shifts.Adjusts
clip-path: inset(...)to show random slices of text.
Apply
glitchShiftto::beforewith2s steps(2, end) infiniteand to::afterwith2s steps(3, end) infinite, offset by differentanimation-delayvalues.
Goal
Animate the <h1> so it flickers with intermittent horizontal shifts, colored channel offsets, and random text slices, creating a convincing glitch effect without JavaScript.
Constraints
Use only CSS (no JavaScript).
Base element should be
<h1 class="glitch" data-text="Glitch Text">Glitch Text</h1>.Pseudo-elements must use
content: attr(data-text).Text-shadowcolors should be#f00for::beforeand#0fffor::after.Keyframes
glitchShiftmust include at least five distinct stops (e.g.,0%,20%,40%,60%,80%, and100%), each with differenttransformandclip-pathvalues.Animation durations should be
2s; timing functions should besteps(2)for::beforeandsteps(3)for::after; infinite iteration.Use different
animation-delayfor each pseudo-element to desynchronize effects (e.g.,0s,-1s).
Sample visual output
Here’s what the output would look like:
Good luck trying the problem! If you’re unsure how to proceed, check the Solution.