AI CSS Animations

Marker Highlight Text

A felt marker swipes across one word, then comes back lower in the other direction, and the overlap goes darker like real ink. Two skewed pseudo-elements with ragged rounded ends.

Also known as: hand drawn highlight css, highlighter pen effect, marker pen text animation.

Ship it today

HTML

<div class="txt-marker-highlight-text">Ship it <span class="txt-marker-highlight-text-mark">today</span></div>

CSS

.txt-marker-highlight-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;
  white-space: nowrap;}
.txt-marker-highlight-text-mark {
  position: relative;
  isolation: isolate;
}
.txt-marker-highlight-text-mark::before,
.txt-marker-highlight-text-mark::after {
  content: "";
  position: absolute;
  z-index: -1;
  background: color-mix(in srgb, var(--c) 40%, transparent);
  border-radius: 0.6em 0.25em 0.5em 0.2em / 0.5em 0.35em 0.6em 0.3em;
}
/* first pass, left to right */
.txt-marker-highlight-text-mark::before {
  inset: 0.14em -0.16em 0.34em -0.12em;
  transform: rotate(-2deg) skewX(-14deg) scaleX(0);
  transform-origin: 0 50%;
  animation: txt-marker-highlight-text-there 0.45s cubic-bezier(0.5, 0, 0.25, 1) 0.3s forwards;
}
/* return pass, lower and shorter, right to left */
.txt-marker-highlight-text-mark::after {
  inset: 0.5em -0.2em 0.02em 0.06em;
  transform: rotate(1deg) skewX(-14deg) scaleX(0);
  transform-origin: 100% 50%;
  animation: txt-marker-highlight-text-back 0.4s cubic-bezier(0.5, 0, 0.25, 1) 0.72s forwards;
}
@keyframes txt-marker-highlight-text-there {
  to { transform: rotate(-2deg) skewX(-14deg) scaleX(1); }
}
@keyframes txt-marker-highlight-text-back {
  to { transform: rotate(1deg) skewX(-14deg) scaleX(1); }
}

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