Skip to content

Lock Unlock

Click to shake the lock with a struggle animation, then pop it open with a satisfying shackle snap

ButtonsStatefulLock MechanismIntermediateHTML/CSSTailwindReactVueAngularSvelteLWC
Lock Unlock

by FreeCsStyles Dev's

StatefulLock Mechanism
🌐🎨⚛️💚🅰️🔥☁️
#lock#unlock#security#shackle#verify#access#granted

Embed this component

Paste this snippet into any site — the design renders in a sandboxed iframe served from /embed/lock-unlock-button.

<iframe src="/embed/lock-unlock-button" sandbox="allow-scripts" loading="lazy" title="Lock Unlock" style="border:0;width:100%;height:480px;overflow:hidden"></iframe>

Implementation code

Copy the HTML and CSS for Lock Unlock, or grab a framework-specific implementation. The HTML and CSS variants are self-contained; framework variants assume that framework's project setup.

HTML
<button class="btn-lock" id="lockBtn" onclick="triggerLock()">
  <span class="text">🔒 Unlock</span>
</button>
<script>
function triggerLock() {
  const btn=document.getElementById('lockBtn');
  if(btn.classList.contains('is-unlocking')) return;
  btn.classList.add('is-unlocking'); btn.querySelector('.text').innerText='⏳ Verifying...';
  setTimeout(()=>{btn.classList.remove('is-unlocking');btn.classList.add('is-unlocked');btn.querySelector('.text').innerText='✅ Granted';},1200);
  setTimeout(()=>{btn.classList.remove('is-unlocked');btn.querySelector('.text').innerText='🔒 Unlock';},4800);
}
</script>
CSS
.btn-lock{width:160px;height:50px;border-radius:12px;border:2px solid transparent;background:#334155;color:#fff;font-size:16px;font-weight:700;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all .4s cubic-bezier(.4,0,.2,1);font-family:system-ui,sans-serif}.btn-lock.is-unlocking{animation:lock-struggle .3s infinite}.btn-lock.is-unlocked{background:#10b981;border-color:#34d399;box-shadow:0 0 30px rgba(16,185,129,.6)}@keyframes lock-struggle{0%,100%{transform:translate(0,0) rotate(0deg)}25%{transform:translate(-5px,2px) rotate(-6deg)}75%{transform:translate(4px,-2px) rotate(5deg)}}
Tailwind CSS
<button class="w-[160px] h-[50px] rounded-xl border-2 border-transparent bg-slate-700 text-white text-base font-bold cursor-pointer flex items-center justify-center transition-all duration-400 [&.is-unlocking]:animate-[lock-struggle-tw_0.3s_infinite] [&.is-unlocked]:bg-emerald-500 [&.is-unlocked]:border-emerald-400 [&.is-unlocked]:shadow-[0_0_30px_rgba(16,185,129,0.6)]" id="tw-lock">
  <span class="text">🔒 Unlock</span>
</button>
React
import React from 'react';
import { motion } from 'framer-motion';

function LockUnlockButton() {
  const [state, setState] = React.useState('idle');
  const handleClick = () => {
    if (state !== 'idle') return;
    setState('unlocking');
    setTimeout(() => setState('unlocked'), 1200);
    setTimeout(() => setState('idle'), 4800);
  };
  const str = state === 'unlocking';
  const op = state === 'unlocked';
  return (
    <motion.button onClick={handleClick}
      style={{ width: 160, height: 50, borderRadius: 12, border: '2px solid transparent', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', gap: 10, fontSize: 16, fontWeight: 700, color: '#fff', background: op ? '#10b981' : '#334155', borderColor: op ? '#34d399' : 'transparent', boxShadow: op ? '0 0 20px rgba(16,185,129,0.4)' : 'none', transition: 'all 0.4s cubic-bezier(0.4,0,0.2,1)', fontFamily: 'system-ui, sans-serif' }}
      animate={str ? { rotate: [0,-4,4,-3,3,0], transition: { duration: 0.2, repeat: Infinity } } : { rotate: 0 }}
      whileTap={state === 'idle' ? { scale: 0.95 } : {}} disabled={state !== 'idle'}>
      <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="white" strokeWidth="2" style={{ overflow: 'visible' }}>
        <motion.path d="M7 11V7a5 5 0 0 1 10 0v4"
          animate={op ? { translateY: -4 } : { translateY: 0 }}
          transition={{ duration: 0.4, ease: [0.5,0,0.2,1] }} />
        <rect x="3" y="11" width="18" height="11" rx="2" ry="2" />
      </svg>
      <span>{op ? 'Granted' : str ? 'Verifying...' : 'Unlock'}</span>
    </motion.button>
  );
}
Vue
<template>
  <button class="btn-lock" :class="{'is-unlocking':state==='unlocking','is-unlocked':state==='unlocked'}" @click="handleClick" :disabled="state!=='idle'">
    <svg class="svg-lock" viewBox="0 0 24 24"><path class="shackle" d="M7 11V7a5 5 0 0 1 10 0v4"/><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/></svg>
    <span class="text">{{ state==='unlocked' ? 'Granted' : state==='unlocking' ? 'Verifying...' : 'Unlock' }}</span>
  </button>
</template>
<script setup>
import { ref } from 'vue';
const state = ref('idle');
function handleClick() {
  if (state.value !== 'idle') return;
  state.value = 'unlocking';
  setTimeout(() => state.value = 'unlocked', 1200);
  setTimeout(() => state.value = 'idle', 4800);
}
</script>
<style scoped>
.btn-lock{width:160px;height:50px;border-radius:12px;border:2px solid transparent;background:#334155;color:#fff;font-size:16px;font-weight:700;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;gap:10px;transition:all .4s cubic-bezier(.4,0,.2,1)}.btn-lock .svg-lock{width:20px;height:20px;fill:none;stroke:white;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.btn-lock .shackle{transition:transform .4s cubic-bezier(.5,0,.2,1);transform-origin:center}.btn-lock.is-unlocking{animation:lock-struggle .2s infinite}.btn-lock.is-unlocked{background:#10b981;border-color:#34d399;box-shadow:0 0 20px rgba(16,185,129,.4)}.btn-lock.is-unlocked .shackle{transform:translateY(-6px)}@keyframes lock-struggle{0%,100%{transform:rotate(0deg)}25%{transform:rotate(-4deg)}75%{transform:rotate(4deg)}}
</style>
Svelte
<script>
  let state = 'idle';
  function handleClick() {
    if (state !== 'idle') return;
    state = 'unlocking';
    setTimeout(() => state = 'unlocked', 1200);
    setTimeout(() => state = 'idle', 4800);
  }
</script>
<button class="btn-lock" class:is-unlocking={state==='unlocking'} class:is-unlocked={state==='unlocked'} on:click={handleClick} disabled={state!=='idle'}>
  <svg class="svg-lock" viewBox="0 0 24 24"><path class="shackle" d="M7 11V7a5 5 0 0 1 10 0v4"/><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/></svg>
  <span>{state==='unlocked'?'Granted':state==='unlocking'?'Verifying...':'Unlock'}</span>
</button>
<style>
.btn-lock{width:160px;height:50px;border-radius:12px;border:2px solid transparent;background:#334155;color:#fff;font-size:16px;font-weight:700;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;gap:10px;transition:all .4s cubic-bezier(.4,0,.2,1)}.btn-lock .svg-lock{width:20px;height:20px;fill:none;stroke:white;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.btn-lock .shackle{transition:transform .4s cubic-bezier(.5,0,.2,1);transform-origin:center}.btn-lock.is-unlocking{animation:lock-struggle .2s infinite}.btn-lock.is-unlocked{background:#10b981;border-color:#34d399;box-shadow:0 0 20px rgba(16,185,129,.4)}.btn-lock.is-unlocked .shackle{transform:translateY(-6px)}@keyframes lock-struggle{0%,100%{transform:rotate(0deg)}25%{transform:rotate(-4deg)}75%{transform:rotate(4deg)}}
</style>
Angular
import { Component } from '@angular/core';
@Component({
  selector: 'app-lock-unlock-button',
  template: `<button class="btn-lock" [class.is-unlocking]="state==='unlocking'" [class.is-unlocked]="state==='unlocked'" (click)="handleClick()" [disabled]="state!=='idle'">
    <svg class="svg-lock" viewBox="0 0 24 24"><path class="shackle" d="M7 11V7a5 5 0 0 1 10 0v4"/><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/></svg>
    <span class="text">{{ state==='unlocked' ? 'Granted' : state==='unlocking' ? 'Verifying...' : 'Unlock' }}</span>
  </button>`,
  styles: [`.btn-lock{width:160px;height:50px;border-radius:12px;border:2px solid transparent;background:#334155;color:#fff;font-size:16px;font-weight:700;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;gap:10px;transition:all .4s cubic-bezier(.4,0,.2,1)}.btn-lock .svg-lock{width:20px;height:20px;fill:none;stroke:white;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.btn-lock .shackle{transition:transform .4s cubic-bezier(.5,0,.2,1);transform-origin:center}.btn-lock.is-unlocking{animation:lock-struggle .2s infinite}.btn-lock.is-unlocked{background:#10b981;border-color:#34d399;box-shadow:0 0 20px rgba(16,185,129,.4)}.btn-lock.is-unlocked .shackle{transform:translateY(-6px)}@keyframes lock-struggle{0%,100%{transform:rotate(0deg)}25%{transform:rotate(-4deg)}75%{transform:rotate(4deg)}}`]
})
export class LockUnlockButtonComponent { state='idle'; handleClick() { if (this.state !== 'idle') return; this.state = 'unlocking'; setTimeout(() => this.state = 'unlocked', 1200); setTimeout(() => this.state = 'idle', 4800); } }
LWC — HTML template
<template><button class="btn-lock" onclick={handleClick} disabled={disabled}>
  <svg class="svg-lock" viewBox="0 0 24 24"><path class="shackle" d="M7 11V7a5 5 0 0 1 10 0v4"/><rect x="3" y="11" width="18" height="11" rx="2" ry="2"/></svg>
  <span>{label}</span>
</button></template>
LWC — JavaScript
import { LightningElement } from 'lwc';
export default class LockUnlockButton extends LightningElement {
  state = 'idle';
  get disabled() { return this.state !== 'idle'; }
  get label() { return this.state==='unlocked'?'Granted':this.state==='unlocking'?'Verifying...':'Unlock'; }
  handleClick() {
    if (this.state !== 'idle') return;
    this.state = 'unlocking';
    const btn = this.template.querySelector('button');
    btn.classList.add('is-unlocking');
    setTimeout(() => { btn.classList.remove('is-unlocking'); btn.classList.add('is-unlocked'); this.state = 'unlocked'; }, 1200);
    setTimeout(() => { btn.classList.remove('is-unlocked'); this.state = 'idle'; }, 4800);
  }
}
LWC — CSS
.btn-lock{width:160px;height:50px;border-radius:12px;border:2px solid transparent;background:#334155;color:#fff;font-size:16px;font-weight:700;cursor:pointer;position:relative;display:flex;align-items:center;justify-content:center;gap:10px;transition:all .4s cubic-bezier(.4,0,.2,1)}.btn-lock .svg-lock{width:20px;height:20px;fill:none;stroke:white;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}.btn-lock .shackle{transition:transform .4s cubic-bezier(.5,0,.2,1);transform-origin:center}.btn-lock.is-unlocking{animation:lock-struggle .2s infinite}.btn-lock.is-unlocked{background:#10b981;border-color:#34d399;box-shadow:0 0 20px rgba(16,185,129,.4)}.btn-lock.is-unlocked .shackle{transform:translateY(-6px)}@keyframes lock-struggle{0%,100%{transform:rotate(0deg)}25%{transform:rotate(-4deg)}75%{transform:rotate(4deg)}}
LWC — Configuration
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  <apiVersion>59.0</apiVersion>
  <isExposed>true</isExposed>
  <targets><target>lightning__AppPage</target><target>lightning__RecordPage</target><target>lightning__HomePage</target></targets>
</LightningComponentBundle>

Where Lock Unlock fits

  • Unlock
  • Security
  • Access Granted
  • Verify
  • Authenticate

Interaction states & animations

  • Shake Struggle
  • Shackle Pop
  • Verify Pulse
  • Unlock Reveal

Topics

  • #lock
  • #unlock
  • #security
  • #shackle
  • #verify
  • #access
  • #granted

Accessibility notes

Lock struggle animation is decorative. Announce "Granted" state via aria-live.

Browser support

  • All modern browsers