AI CSS Animations

Disabled Button Style

A hatched, locked 'Continue' button that stays disabled until the terms box is ticked, then the stripes slide away. Pressing it early pulses the checkbox to show what is missing. Uses :has().

Also known as: css button disabled style, disabled button css, enable button on checkbox.

HTML

<div class="btn-disabled-state">
  <label class="btn-disabled-state-terms"><input class="btn-disabled-state-input" type="checkbox"><span class="btn-disabled-state-box"></span>I agree to the terms</label>
  <button class="btn-disabled-state-btn" type="button">
    <svg viewBox="0 0 24 24" aria-hidden="true"><rect class="btn-disabled-state-lock" x="5.5" y="11" width="13" height="9" rx="2"/><path class="btn-disabled-state-lock" d="M8.5 11V8a3.5 3.5 0 0 1 7 0v3"/><path class="btn-disabled-state-arrow" d="M5 12h13M13 6.5l5.5 5.5-5.5 5.5"/></svg>
    Continue
  </button>
</div>

CSS

.btn-disabled-state {
  --c: var(--btn-color, #3b82f6);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9em;
  font: 500 var(--btn-size, 18px)/1.2 system-ui, sans-serif;
}
.btn-disabled-state-terms {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  font-size: 0.9em;
  cursor: pointer;
}
.btn-disabled-state-input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.btn-disabled-state-box {
  position: relative;
  width: 1.15em;
  height: 1.15em;
  border-radius: 0.3em;
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--c) 55%, transparent);
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}
.btn-disabled-state-box::after {
  content: "";
  position: absolute;
  left: 0.38em;
  top: 0.16em;
  width: 0.3em;
  height: 0.58em;
  border: solid #fff;
  border-width: 0 0.13em 0.13em 0;
  transform: rotate(45deg) scale(0);
  transition: transform 0.25s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.btn-disabled-state-btn {
  --c: var(--btn-color, #3b82f6);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.75em 1.6em;
  border: 0;
  border-radius: 0.6em;
  font: 600 var(--btn-size, 18px)/1.1 system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  width: 9.5em;
  font-size: 1em;
  background-color: color-mix(in srgb, var(--c) 10%, #e5e7eb);
  color: color-mix(in srgb, var(--c) 25%, #6b7280);
  cursor: not-allowed;
  transition: background-color 0.35s ease, color 0.35s ease, box-shadow 0.35s ease, transform 0.2s ease;}
.btn-disabled-state-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: repeating-linear-gradient(-45deg, transparent 0 0.45em, color-mix(in srgb, var(--c) 10%, rgba(107, 114, 128, 0.18)) 0.45em 0.9em);
  transition: transform 0.5s cubic-bezier(0.65, 0, 0.35, 1), opacity 0.5s ease;
}
.btn-disabled-state-btn svg {
  width: 1.15em;
  height: 1.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.btn-disabled-state-arrow {
  opacity: 0;
  transform: translateX(-30%);
  transform-box: fill-box;
  transition: opacity 0.3s ease, transform 0.35s cubic-bezier(0.3, 1.5, 0.5, 1);
}
.btn-disabled-state-lock { transition: opacity 0.2s ease; }
.btn-disabled-state-input:focus-visible + .btn-disabled-state-box,
.btn-disabled-state-btn:focus-visible {
  outline: 2px solid var(--c);
  outline-offset: 0.2em;
}
.btn-disabled-state:has(.btn-disabled-state-btn:active) .btn-disabled-state-input:not(:checked) + .btn-disabled-state-box {
  animation: btn-disabled-state-nudge 0.6s ease-out;
}
.btn-disabled-state-input:checked + .btn-disabled-state-box {
  background-color: var(--c);
  box-shadow: inset 0 0 0 2px var(--c);
}
.btn-disabled-state-input:checked + .btn-disabled-state-box::after { transform: rotate(45deg) scale(1); }
.btn-disabled-state:has(.btn-disabled-state-input:checked) .btn-disabled-state-btn {
  background-color: var(--c);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 0.4em 1em -0.4em var(--c);
}
.btn-disabled-state:has(.btn-disabled-state-input:checked) .btn-disabled-state-btn::before {
  transform: translateX(100%);
  opacity: 0;
}
.btn-disabled-state:has(.btn-disabled-state-input:checked) .btn-disabled-state-lock { opacity: 0; }
.btn-disabled-state:has(.btn-disabled-state-input:checked) .btn-disabled-state-arrow {
  opacity: 1;
  transform: none;
  transition-delay: 0.1s;
}
.btn-disabled-state:has(.btn-disabled-state-input:checked) .btn-disabled-state-btn:active { transform: scale(0.96); }
@keyframes btn-disabled-state-nudge {
  0% { box-shadow: inset 0 0 0 2px var(--c), 0 0 0 0 color-mix(in srgb, var(--c) 60%, transparent); }
  100% { box-shadow: inset 0 0 0 2px var(--c), 0 0 0 0.6em transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .btn-disabled-state, .btn-disabled-state *, .btn-disabled-state::before, .btn-disabled-state::after, .btn-disabled-state *::before, .btn-disabled-state *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --btn-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --btn-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 18px.
  • 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 buttons