AI CSS Animations

Video Inside Text Effect

A sunset plays inside heavy letters: the sun sinks into the sea while ripples roll toward you. Layered gradients clipped to the text, moved by two registered properties, no video file needed.

Also known as: video inside text css, text mask video effect, image inside text animation, knockout text css.

SUNSET

HTML

<div class="txt-video-knockout-text">SUNSET</div>

CSS

@property --txt-video-knockout-text-sun {
  syntax: "<percentage>";
  inherits: false;
  initial-value: 30%;
}
@property --txt-video-knockout-text-o {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}
.txt-video-knockout-text {
  --c: var(--txt-color, #3b82f6);
  font-size: calc(var(--txt-size, 32px) * 2.6);
  font-family: system-ui, sans-serif;
  font-weight: 900;
  line-height: 1.2;
  display: inline-block;
  line-height: 1;
  letter-spacing: -0.03em;
  --o: var(--txt-video-knockout-text-o);
  background:
    repeating-linear-gradient(180deg,
      transparent var(--o),
      rgba(12, 10, 40, 0.45) calc(var(--o) + 0.025em),
      transparent calc(var(--o) + 0.06em),
      transparent calc(var(--o) + 0.13em)) bottom / 100% 40% no-repeat,
    radial-gradient(24% 90% at 50% 0%, #ffd79a, rgba(255, 140, 90, 0.5) 45%, transparent) bottom / 100% 40% no-repeat,
    linear-gradient(color-mix(in srgb, var(--c) 30%, #3a2466), #120d2c) bottom / 100% 40% no-repeat,
    radial-gradient(circle at 50% var(--txt-video-knockout-text-sun), #fff4c8 0, #ffc46b 0.2em, #ff7a59 0.36em, rgba(255, 122, 89, 0.35) 0.5em, transparent 0.95em),
    linear-gradient(180deg, color-mix(in srgb, var(--c) 55%, #1b1036) 0%, #c2507a 42%, #ff9a6a 60%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0.06em 0.2em rgba(255, 122, 89, 0.3));
  animation:
    txt-video-knockout-text-set 9s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate,
    txt-video-knockout-text-sea 1.4s linear infinite;}
@keyframes txt-video-knockout-text-set {
  from { --txt-video-knockout-text-sun: 26%; }
  to   { --txt-video-knockout-text-sun: 72%; }
}
@keyframes txt-video-knockout-text-sea {
  to { --txt-video-knockout-text-o: 0.13em; }
}
@media (prefers-reduced-motion: reduce) {
  .txt-video-knockout-text { animation: none; --txt-video-knockout-text-sun: 52%; }
}

@media (prefers-reduced-motion: reduce) {
  .txt-video-knockout-text, .txt-video-knockout-text *, .txt-video-knockout-text::before, .txt-video-knockout-text::after, .txt-video-knockout-text *::before, .txt-video-knockout-text *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --txt-color on the element or a parent. Currently previewing #3b82f6.
  • Font size: set --txt-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 40px.
  • 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 text animations