The old price gets a slanted strike and fades back, then the new price springs up beside it. Made for pricing cards and sale banners; the strike is a pseudo-element scaled from the left.
Also known as: sale price animation css, crossed out price, discount price strike.
<div class="txt-strikethrough-price"> <s class="txt-strikethrough-price-old">$49</s> <span class="txt-strikethrough-price-new">$29<small>/mo</small></span> </div>
.txt-strikethrough-price {
--c: var(--txt-color, #3b82f6);
font-size: var(--txt-size, 32px);
font-family: system-ui, sans-serif;
font-weight: 700;
line-height: 1.2;
display: inline-flex;
align-items: baseline;
gap: 0.4em;
white-space: nowrap;}
.txt-strikethrough-price-old {
position: relative;
font-size: 0.85em;
font-weight: 600;
text-decoration: none;
animation: txt-strikethrough-price-dim 0.35s ease-out 0.7s forwards;
}
.txt-strikethrough-price-old::after {
content: "";
position: absolute;
left: -0.14em;
right: -0.14em;
top: 50%;
height: 0.09em;
margin-top: -0.02em;
border-radius: 0.05em;
background: var(--c);
transform: rotate(-14deg) scaleX(0);
transform-origin: 0 50%;
animation: txt-strikethrough-price-strike 0.4s cubic-bezier(0.6, 0, 0.3, 1) 0.35s forwards;
}
.txt-strikethrough-price-new {
display: inline-block;
font-size: 1.5em;
font-weight: 800;
color: var(--c);
opacity: 0;
transform: translateY(0.35em) scale(0.7);
animation: txt-strikethrough-price-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) 0.8s forwards;
}
.txt-strikethrough-price-new small {
margin-left: 0.05em;
font-size: 0.42em;
font-weight: 600;
opacity: 0.75;
}
@keyframes txt-strikethrough-price-strike {
to { transform: rotate(-14deg) scaleX(1); }
}
@keyframes txt-strikethrough-price-dim {
to { color: color-mix(in srgb, currentColor 45%, transparent); }
}
@keyframes txt-strikethrough-price-pop {
to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
.txt-strikethrough-price, .txt-strikethrough-price *, .txt-strikethrough-price::before, .txt-strikethrough-price::after, .txt-strikethrough-price *::before, .txt-strikethrough-price *::after {
animation-duration: 0.01ms !important;
animation-iteration-count: 1 !important;
transition-duration: 0.01ms !important;
}
}--txt-color on the element or a parent.
Currently previewing #3b82f6.--txt-size. Every other dimension is in
em, so the whole thing scales together. Currently previewing 40px.transition or animation
shorthand. Staggered delays are relative, so they keep their rhythm.