AI CSS Animations

Dot Grid Card Hover

A faint dot grid in the card's corner spreads across it and starts drifting diagonally on hover. The dots are one radial-gradient tile and the drift moves exactly one tile, so the loop is invisible.

Also known as: dot pattern background css, grid pattern card hover, animated background pattern.

Components

Forty building blocks, all themeable.

HTML

<article class="hfx-card-dot-pattern">
  <span class="hfx-card-dot-pattern-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="3" width="7.5" height="7.5" rx="1.5"/><rect x="13.5" y="3" width="7.5" height="7.5" rx="3.75"/><rect x="3" y="13.5" width="7.5" height="7.5" rx="3.75"/><rect x="13.5" y="13.5" width="7.5" height="7.5" rx="1.5"/></svg></span>
  <h3>Components</h3>
  <p>Forty building blocks, all themeable.</p>
</article>

CSS

.hfx-card-dot-pattern {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  width: 15em;
  border-radius: 0.75em;
  overflow: hidden;
  background: #fff;
  border: 1px solid color-mix(in srgb, #000 10%, transparent);
  color: #1f2937;
  font-family: system-ui, sans-serif;
  position: relative;
  isolation: isolate;
  box-sizing: border-box;
  width: 14em;
  padding: 1.2em 1.2em 1.25em;
  transition: border-color 0.35s ease;}
.hfx-card-dot-pattern:hover { border-color: color-mix(in srgb, var(--c) 40%, transparent); }
.hfx-card-dot-pattern::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: radial-gradient(circle, color-mix(in srgb, var(--c) 55%, transparent) 0.08em, transparent 0.1em) 0 0 / 0.9em 0.9em;
  -webkit-mask: radial-gradient(circle at 100% 0, #000, transparent 70%) 100% 0 / 60% 80% no-repeat;
  mask: radial-gradient(circle at 100% 0, #000, transparent 70%) 100% 0 / 60% 80% no-repeat;
  opacity: 0.6;
  transition: -webkit-mask-size 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), mask-size 0.6s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.4s ease;
}
.hfx-card-dot-pattern:hover::before {
  -webkit-mask-size: 160% 190%;
  mask-size: 160% 190%;
  opacity: 1;
  animation: hfx-card-dot-pattern-drift 1.8s linear infinite;
}
.hfx-card-dot-pattern-icon {
  display: grid;
  place-items: center;
  width: 2.4em;
  height: 2.4em;
  margin-bottom: 0.8em;
  border-radius: 0.6em;
  background: #fff;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 25%, transparent), 0 0.3em 0.6em -0.3em color-mix(in srgb, var(--c) 50%, transparent);
  color: var(--c);
}
.hfx-card-dot-pattern-icon svg {
  width: 1.2em;
  height: 1.2em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
}
.hfx-card-dot-pattern h3 {
  margin: 0 0 0.25em;
  font-size: 1em;
  font-weight: 600;
}
.hfx-card-dot-pattern p {
  margin: 0;
  font-size: 0.8em;
  line-height: 1.45;
  color: #6b7280;
}
@keyframes hfx-card-dot-pattern-drift {
  to { background-position: 0.9em -0.9em; }
}

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