AI CSS Animations

Rotating Square Fill Button

A square spins a three-eighths turn while it grows from the center, landing square-on to cover the button. One transform on one pseudo-element, with a fast-out easing so it lands softly.

Also known as: spin fill button, rotate in fill hover, twist fill button.

HTML

<button class="hfx-rotating-square-fill">Create account</button>

CSS

.hfx-rotating-square-fill {
  --c: var(--hfx-color, #3b82f6);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.75em 1.75em;
  border-radius: 0.5em;
  font: 600 var(--hfx-size, 16px)/1.2 system-ui, sans-serif;
  white-space: nowrap;
  cursor: pointer;
  border: 2px solid var(--c);
  background: transparent;
  color: var(--c);
  transition: color 0.3s ease 0.1s;
}
.hfx-rotating-square-fill::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: -1;
  width: 110%;
  aspect-ratio: 1;
  background: var(--c);
  transform: translate(-50%, -50%) rotate(-135deg) scale(0);
  transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.hfx-rotating-square-fill:is(:hover, :focus-visible) {
  background-color: var(--c); /* hides the hairline where the fill meets the border */
  color: #fff;
  transition: color 0.3s ease 0.1s, background-color 0s 0.6s;
}
.hfx-rotating-square-fill:is(:hover, :focus-visible)::before {
  transform: translate(-50%, -50%) rotate(0) scale(1);
}

@media (prefers-reduced-motion: reduce) {
  .hfx-rotating-square-fill, .hfx-rotating-square-fill *, .hfx-rotating-square-fill::before, .hfx-rotating-square-fill::after, .hfx-rotating-square-fill *::before, .hfx-rotating-square-fill *::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