AI CSS Animations

Hanging Sign Swing Text

An OPEN sign hangs from a nail on two strings and swings toward you and away in 3D. A rotateX pendulum pivoting on the nail, with perspective so the bottom edge grows as it comes near.

Also known as: swinging sign animation, hanging text css, pendulum swing text.

OPEN

HTML

<div class="txt-hanging-sign-text"><span class="txt-hanging-sign-text-sign">OPEN</span></div>

CSS

.txt-hanging-sign-text {
  --c: var(--txt-color, #3b82f6);
  font-size: calc(var(--txt-size, 32px) * 1.3);
  font-family: system-ui, sans-serif;
  font-weight: 800;
  line-height: 1.2;
  position: relative;
  display: inline-block;
  padding-top: 0.95em; /* room for the strings */
  perspective: 6em;}
/* the nail */
.txt-hanging-sign-text::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 0.18em;
  height: 0.18em;
  margin-left: -0.09em;
  border-radius: 50%;
  background: var(--c);
}
.txt-hanging-sign-text-sign {
  position: relative;
  display: inline-block;
  padding: 0.25em 0.7em;
  border: 0.08em solid var(--c);
  border-radius: 0.14em;
  color: var(--c);
  letter-spacing: 0.1em;
  background: color-mix(in srgb, var(--c) 12%, transparent);
  transform-origin: 50% -0.86em; /* swings from the nail */
  animation: txt-hanging-sign-text-swing 1.5s cubic-bezier(0.45, 0, 0.55, 1) infinite alternate;
}
/* the strings: two borders of a square turned 45deg, apex at the nail */
.txt-hanging-sign-text-sign::before {
  content: "";
  position: absolute;
  top: -0.68em;
  left: 50%;
  width: 1.2em;
  height: 1.2em;
  margin-left: -0.6em;
  border-top: 0.05em solid color-mix(in srgb, var(--c) 70%, transparent);
  border-left: 0.05em solid color-mix(in srgb, var(--c) 70%, transparent);
  transform: rotate(45deg);
}
@keyframes txt-hanging-sign-text-swing {
  from { transform: rotateX(28deg); }
  to   { transform: rotateX(-28deg); }
}

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