CSS Animation Example: Strikethrough Draw
The "Strikethrough Draw" adds an aggressive but playful visual feedback when a user finishes a to-do list item or when updating old prices.
This is extremely straightforward. You cannot easily animate the native CSS text-decoration: line-through. Therefore, the trick leans on an empty pseudo-element (like ::after). We use position: absolute and set its top to 50% over the parent string (adjusting slightly with transform: translateY(-50%) if the line thickness throws it off-center).
The "drawing" mechanic comes from stretching. We fix the left edge just past the string (-5%), but pin the right edge way back at 105%. When hovered (or activated via a class), we animate the right value back to -5%, causing the line to stretch over the letters.
Here is the code to create the Strikethrough Draw animation.
Accessibility Considerations
Because it acts as a visual change of state over a tiny area rather than a broad layout motion, it is generally benign. However, prefers-reduced-motion is a CSS media feature used to detect if a user has enabled a setting on their device to minimize the amount of non-essential animation or motion.
To respect this, disable the draw transition and simply toggle the line instantly on or off.
Here's what we used in our example:
@media (prefers-reduced-motion: reduce) {
.strikethrough::after {
/* Line instantly appears fully drawn instead of wiping smoothly */
transition: none;
}
}