Retro Switch - MeggiTools
Run
Toggle Theme
Share Link
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Retro Switch</title> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; background: #ffeb3b; font-family: 'Courier New', Courier, monospace; } .toggle-container { position: relative; width: 100px; height: 50px; } .toggle-switch { position: absolute; cursor: pointer; width: 100%; height: 100%; background: #777; border-radius: 50px; transition: background 0.3s; } .toggle-switch::before { content: ''; position: absolute; left: 15px; top: 50%; transform: translateY(-50%); font-size: 20px; transition: left 0.3s, transform 0.3s; } .toggle-switch::after { content: ''; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-size: 20px; transition: right 0.3s, transform 0.3s; } .toggle-switch input[type="checkbox"] { display: none; } .toggle-switch input[type="checkbox"]:checked + .toggle-slider { background: #8bc34a; } .toggle-switch input[type="checkbox"]:checked + .toggle-slider::before { left: calc(100% - 55px); } .toggle-slider { position: absolute; width: 100%; height: 100%; background: #eee; border-radius: 50px; transition: background 0.3s; } .toggle-slider::before { content: ''; position: absolute; width: 50px; height: 50px; top: 0; left: 0; background: #fff; border-radius: 50%; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transition: left 0.3s; } .toggle-switch input[type="checkbox"]:checked + .toggle-slider::before { left: calc(100% - 50px); } .toggle-slider::after { content: ''; position: absolute; width: 100%; height: 100%; top: 0; left: 0; border-radius: 50px; box-shadow: 0 0 20px rgba(0, 0, 0, 0.5); opacity: 0; transition: opacity 0.3s; } .toggle-switch input[type="checkbox"]:checked + .toggle-slider::after { opacity: 1; } </style> </head> <body> <div class="toggle-container"> <label class="toggle-switch"> <input type="checkbox" id="toggle-retro"> <div class="toggle-slider"></div> </label> </div> <script> document.querySelector('#toggle-retro').addEventListener('change', function () { if (this.checked) { alert('Retro Switch is ON'); } else { alert('Retro Switch is OFF'); } }); </script> </body> </html>