AI CSS Animations

Rack Focus Text Effect

Two words at different depths trade focus like a camera pulling focus: one sharpens while the other goes soft, then back. Blur, opacity and a hint of lens breathing on a slow ease.

Also known as: focus pull text, depth of field text css, blur focus shift text.

Here and there

HTML

<div class="txt-rack-focus-text"><span class="txt-rack-focus-text-near">Here</span> <span class="txt-rack-focus-text-far">and there</span></div>

CSS

.txt-rack-focus-text {
  --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.35em;
  color: var(--c);}
.txt-rack-focus-text-near,
.txt-rack-focus-text-far {
  display: inline-block;
  animation: 6s cubic-bezier(0.65, 0, 0.35, 1) infinite;
}
.txt-rack-focus-text-near {
  font-size: 1.7em;
  font-weight: 800;
  animation-name: txt-rack-focus-text-near;
}
.txt-rack-focus-text-far {
  font-size: 0.9em;
  font-weight: 600;
  transform: translateY(-0.9em);
  animation-name: txt-rack-focus-text-far;
}
@keyframes txt-rack-focus-text-near {
  0%, 38%, 96%, 100% { filter: blur(0); opacity: 1; transform: scale(1); }
  50%, 84%           { filter: blur(0.07em); opacity: 0.45; transform: scale(1.03); }
}
@keyframes txt-rack-focus-text-far {
  0%, 38%, 96%, 100% { filter: blur(0.09em); opacity: 0.5; transform: translateY(-0.9em) scale(0.97); }
  50%, 84%           { filter: blur(0); opacity: 1; transform: translateY(-0.9em) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .txt-rack-focus-text, .txt-rack-focus-text *, .txt-rack-focus-text::before, .txt-rack-focus-text::after, .txt-rack-focus-text *::before, .txt-rack-focus-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