AI CSS Animations

Corner Ribbon Card Hover

A diagonal Sale ribbon slides into the card's top corner with a little overshoot as the card lifts. The ribbon waits just outside the corner and the card's overflow hides it until then.

Also known as: corner ribbon css, sale ribbon on hover, diagonal badge card.

Sale

Motion basics course

$89 $59

HTML

<article class="hfx-card-corner-ribbon">
  <span class="hfx-card-corner-ribbon-ribbon">Sale</span>
  <div class="hfx-card-corner-ribbon-image"></div>
  <div class="hfx-card-corner-ribbon-body">
    <h3>Motion basics course</h3>
    <p><s>$89</s> <strong>$59</strong></p>
  </div>
</article>

CSS

.hfx-card-corner-ribbon {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  width: 15em;
  border-radius: 0.75em;
  overflow: hidden;
  background: #fff;
  border: 1px solid color-mix(in srgb, #000 10%, transparent);
  color: #1f2937;
  font-family: system-ui, sans-serif;
  position: relative;
  width: 13em;
  transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.35s ease;}
.hfx-card-corner-ribbon:hover {
  transform: translateY(-0.25em);
  box-shadow: 0 0.9em 1.4em -0.9em color-mix(in srgb, #000 35%, transparent);
}
.hfx-card-corner-ribbon-image {
  height: 5.6em;
  background: radial-gradient(120% 70% at 18% 100%, color-mix(in srgb, var(--c) 75%, #000) 0 50%, transparent 51%),
    radial-gradient(140% 80% at 88% 100%, color-mix(in srgb, var(--c) 50%, #fff) 0 50%, transparent 51%),
    radial-gradient(circle at 70% 38%, #fff7d6 0 12%, transparent 13%),
    linear-gradient(to bottom, color-mix(in srgb, var(--c) 30%, #fff), color-mix(in srgb, var(--c) 55%, #fff));
}
.hfx-card-corner-ribbon-body { padding: 0.75em 0.95em 0.85em; }
.hfx-card-corner-ribbon h3 {
  font-weight: 600;
  margin: 0 0 0.25em;
  font-size: 0.95em;
}
.hfx-card-corner-ribbon p {
  margin: 0;
  font-size: 0.85em;
  color: #9ca3af;
}
.hfx-card-corner-ribbon strong {
  margin-left: 0.2em;
  color: var(--c);
}
.hfx-card-corner-ribbon-ribbon {
  position: absolute;
  z-index: 1;
  top: 1.05em;
  right: -2.35em;
  width: 8em;
  padding: 0.35em 0;
  background: var(--c);
  box-shadow: 0 0.2em 0.5em color-mix(in srgb, #000 25%, transparent);
  color: #fff;
  font-size: 0.7em;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-align: center;
  text-transform: uppercase;
  transform: translate(3em, -3em) rotate(45deg);
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.hfx-card-corner-ribbon:hover .hfx-card-corner-ribbon-ribbon { transform: rotate(45deg); }

@media (prefers-reduced-motion: reduce) {
  .hfx-card-corner-ribbon, .hfx-card-corner-ribbon *, .hfx-card-corner-ribbon::before, .hfx-card-corner-ribbon::after, .hfx-card-corner-ribbon *::before, .hfx-card-corner-ribbon *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar hover effects