-
Animated embossed login animation
HTML
CSS
JavaScript
✓
Welcome Back!
Login Successful
SIGN IN
(Use admin / 1234 to test success)
Login
:root { --bg-color: #e0e5ec; --text-color: #4a5568; --light-shadow: #ffffff; --dark-shadow: #a3b1c6; --accent-color: #4299e1; /* Error colors */ --error-color: #e53e3e; --error-dark: #d09a9a; --error-light: #fff5f5; } * { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background-color: var(--bg-color); } .login-circle { position: relative; width: 380px; height: 380px; border-radius: 50%; background-color: var(--bg-color); box-shadow: 15px 15px 30px var(--dark-shadow), -15px -15px 30px var(--light-shadow); display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 40px; transition: all 0.3s ease; overflow: hidden; /* Keeps animations inside */ } h2 { color: var(--text-color); margin-bottom: 5px; font-size: 1.5rem; font-weight: 600; letter-spacing: 1px; text-align: center; } .hint { font-size: 0.75rem; color: #8fa0b5; margin-bottom: 20px; text-align: center; } .input-group { position: relative; margin-bottom: 20px; width: 80%; perspective: 1000px; } .input-group input { width: 100%; padding: 12px 20px; border: none; outline: none; background: var(--bg-color); border-radius: 25px; color: var(--text-color); font-size: 0.9rem; box-shadow: inset 5px 5px 10px var(--dark-shadow), inset -5px -5px 10px var(--light-shadow); transition: box-shadow 0.3s ease, color 0.3s ease; } .input-group input:focus { box-shadow: inset 7px 7px 14px var(--dark-shadow), inset -7px -7px 14px var(--light-shadow); } /* --- ERROR ANIMATION STYLES --- */ .input-group input.error { color: var(--error-color); box-shadow: inset 5px 5px 10px var(--error-dark), inset -5px -5px 10px var(--error-light); animation: rotate-error 0.5s ease-in-out; } @keyframes rotate-error { 0% { transform: rotate(0deg); } 20% { transform: rotate(-8deg); } 40% { transform: rotate(8deg); } 60% { transform: rotate(-8deg); } 80% { transform: rotate(8deg); } 100% { transform: rotate(0deg); } } /* --- SUCCESS ANIMATION STYLES --- */ .input-group input.success { animation: rotate-success 0.6s ease-in-out forwards; } @keyframes rotate-success { 0% { transform: rotate(0deg) scale(1); opacity: 1; } 100% { transform: rotate(360deg) scale(0); opacity: 0; } } .btn-submit { width: 80%; padding: 12px; border: none; outline: none; border-radius: 25px; background: var(--bg-color); color: var(--accent-color); font-weight: bold; font-size: 1rem; cursor: pointer; margin-top: 10px; box-shadow: 5px 5px 10px var(--dark-shadow), -5px -5px 10px var(--light-shadow); transition: all 0.2s ease; } .btn-submit:active { box-shadow: inset 5px 5px 10px var(--dark-shadow), inset -5px -5px 10px var(--light-shadow); transform: scale(0.98); } .form-content { display: flex; flex-direction: column; align-items: center; width: 100%; transition: opacity 0.4s ease; } .form-content.hide { opacity: 0; pointer-events: none; } /* SUCCESS MESSAGE STYLES */ .success-msg { position: absolute; opacity: 0; transform: scale(0.5); /* Start small for bounce effect */ color: #48bb78; font-weight: bold; text-align: center; pointer-events: none; display: flex; flex-direction: column; align-items: center; } .success-msg.show { opacity: 1; /* Bouncy pop-in animation */ animation: pop-in 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; } .success-msg .check-circle { width: 60px; height: 60px; border-radius: 50%; background: var(--bg-color); box-shadow: 5px 5px 10px var(--dark-shadow), -5px -5px 10px var(--light-shadow); display: flex; justify-content: center; align-items: center; font-size: 2rem; margin-bottom: 15px; color: #48bb78; } @keyframes pop-in { 0% { transform: scale(0.5); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
function handleLogin() { const userInp = document.getElementById('username'); const passInp = document.getElementById('password'); const formContent = document.getElementById('formContent'); const successMsg = document.getElementById('successMsg'); // Mock credentials for testing const correctUser = "admin"; const correctPass = "1234"; // Remove previous animation classes if they exist userInp.classList.remove('error', 'success'); passInp.classList.remove('error', 'success'); // Trigger reflow so animations can restart if clicked multiple times void userInp.offsetWidth; void passInp.offsetWidth; if (userInp.value === correctUser && passInp.value === correctPass) { // --- SUCCESS STATE --- // Add rotate-out success animation to inputs userInp.classList.add('success'); passInp.classList.add('success'); // Wait for input rotation to finish (600ms), then fade out form & pop in success message setTimeout(() => { formContent.classList.add('hide'); successMsg.classList.add('show'); }, 600); // Optional: Reset form automatically after 4 seconds to test again setTimeout(() => { successMsg.classList.remove('show'); setTimeout(() => { formContent.classList.remove('hide'); userInp.value = ''; passInp.value = ''; userInp.classList.remove('success'); passInp.classList.remove('success'); }, 400); }, 4000); } else { // --- ERROR STATE --- // Add rotation wobble and red colors userInp.classList.add('error'); passInp.classList.add('error'); // Automatically remove the error class after the animation ends (500ms) // so it returns back to the original design setTimeout(() => { userInp.classList.remove('error'); passInp.classList.remove('error'); }, 500); } }
Live Preview