-
CSS login form lamp animation
HTML
CSS
JavaScript
Welcome
Username
Password
Sign In
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; } body { background: #121212; display: flex; justify-content: center; align-items: center; min-height: 100vh; overflow: hidden; transition: background 0.5s ease; } /* --- THE INVISIBLE SWITCH --- */ #lamp-switch { display: none; } /* --- LAMP FIXTURE --- */ .lamp-wrapper { position: absolute; top: 0; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; z-index: 10; } .wire { width: 4px; height: 80px; background: #2a2a2a; } .fixture { width: 70px; height: 25px; background: #333; border-radius: 10px 10px 0 0; z-index: 2; } .bulb { width: 45px; height: 45px; background: #222; border-radius: 50%; position: relative; top: -15px; z-index: 1; transition: all 0.4s ease; } /* --- UPDATED PULL CORD (Larger Click Area) --- */ .cord { position: absolute; top: 90px; right: 0px; width: 40px; /* Much wider invisible hit-area for easy clicking */ height: 70px; cursor: pointer; z-index: 20; transition: transform 0.15s ease-out; } /* The visual string of the cord */ .cord::before { content: ''; position: absolute; top: 0; left: 18px; /* Centered in the 40px hit area */ width: 3px; height: 100%; background: #444; transition: background 0.3s ease; } /* The visual knob of the cord */ .cord::after { content: ''; position: absolute; bottom: -8px; left: 14px; /* Centered in the 40px hit area */ width: 11px; height: 11px; background: #666; border-radius: 50%; transition: background 0.3s ease; } /* Pull animation when clicking anywhere in the 40px hit area */ .cord:active { transform: translateY(15px); } /* --- LIGHT BEAM --- */ .light-beam { position: absolute; top: 110px; left: 50%; transform: translateX(-50%); width: 700px; height: 800px; clip-path: polygon(50% 0, 100% 100%, 0 100%); background: linear-gradient(to bottom, rgba(255, 235, 59, 0.4), transparent); opacity: 0; pointer-events: none; /* Let clicks pass through to the form */ z-index: 1; transition: opacity 0.5s ease; } /* --- LOGIN FORM --- */ .form-container { position: relative; z-index: 2; background: rgba(20, 20, 20, 0.95); padding: 50px 40px; border-radius: 15px; width: 380px; margin-top: 120px; text-align: center; border: 1px solid #222; /* Dark/Disabled state by default */ opacity: 0.2; pointer-events: none; transition: all 0.5s ease; } .form-container h2 { color: #444; margin-bottom: 40px; font-weight: 600; transition: color 0.5s ease; letter-spacing: 1px; } .input-box { position: relative; margin-bottom: 35px; text-align: left; } .input-box input { width: 100%; padding: 10px 0; font-size: 16px; color: #fff; background: transparent; border: none; border-bottom: 2px solid #444; outline: none; transition: border-color 0.5s ease; } .input-box label { position: absolute; top: 10px; left: 0; font-size: 16px; color: #555; pointer-events: none; transition: all 0.3s ease; } /* Floating label effect */ .input-box input:focus ~ label, .input-box input:valid ~ label { top: -20px; font-size: 13px; } button { width: 100%; background: #333; color: #666; border: none; padding: 15px; border-radius: 8px; font-size: 16px; font-weight: bold; cursor: pointer; transition: all 0.4s ease; } /* ========================================= STATES WHEN THE LAMP IS TURNED ON ========================================= */ /* 1. Light up the bulb */ #lamp-switch:checked ~ .lamp-wrapper .bulb { background: #ffeb3b; box-shadow: 0 0 30px #ffeb3b, 0 0 80px #ffeb3b; } /* 2. Fade in the light beam */ #lamp-switch:checked ~ .light-beam { opacity: 1; } /* 3. Wake up the form (enable clicks & typing) */ #lamp-switch:checked ~ .form-container { opacity: 1; pointer-events: auto; box-shadow: 0 15px 35px rgba(0,0,0,0.8), 0 0 40px rgba(255, 235, 59, 0.1); border-color: rgba(255, 235, 59, 0.3); } /* 4. Brighten form text and inputs */ #lamp-switch:checked ~ .form-container h2 { color: #ffeb3b; } #lamp-switch:checked ~ .form-container .input-box input { border-bottom-color: #ddd; } #lamp-switch:checked ~ .form-container .input-box label { color: #aaa; } /* 5. Highlight active input fields in yellow */ #lamp-switch:checked ~ .form-container .input-box input:focus ~ label, #lamp-switch:checked ~ .form-container .input-box input:valid ~ label { color: #ffeb3b; } /* 6. Brighten and activate the login button */ #lamp-switch:checked ~ .form-container button { background: #ffeb3b; color: #121212; box-shadow: 0 0 15px rgba(255, 235, 59, 0.4); } #lamp-switch:checked ~ .form-container button:hover { background: #fff; box-shadow: 0 0 25px rgba(255, 255, 255, 0.8); }
Live Preview