Toggle navigation
☰
Home
HTML
CSS
Scripting
Database
<!DOCTYPE html> <title>My Example</title> <style> .registration-form-container { max-width: 420px; margin: 40px auto; padding: 30px; background: #fff; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; } .registration-form-header { text-align: center; margin-bottom: 30px; } .registration-form-header h2 { margin: 0 0 10px; } .registration-form-header p { font-size: 0.95rem; color: #666; } .form-group { margin-bottom: 15px; } .form-group label { display: block; margin-bottom: 5px; font-weight: 600; } .form-group input { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 5px; font-size: 1rem; box-sizing: border-box; } .password-requirements { font-size: 0.8rem; color: #777; margin-top: 5px; padding-left: 2px; } .form-group-terms { display: flex; align-items: start; gap: 10px; margin-bottom: 20px; font-size: 0.9rem; color: #555; } .form-group-terms input { margin-top: 4px; width: auto; } .form-group-terms a { color: #007bff; text-decoration: none; } .form-group-terms a:hover { text-decoration: underline; } .submit-btn { width: 100%; padding: 12px; background-color: #28a745; border: none; border-radius: 5px; color: white; font-size: 1.1rem; font-weight: bold; cursor: pointer; transition: background-color 0.2s; } .submit-btn:hover { background-color: #218838; } .login-link { text-align: center; margin-top: 20px; font-size: 0.9rem; } .login-link a { color: #007bff; font-weight: 600; } </style> <div class="registration-form-container"> <div class="registration-form-header"> <h2>Create an Account</h2> <p>Join us and get started today!</p> </div> <form id="registrationForm" action="#" method="post"> <div class="form-group"> <label for="reg-email">Email</label> <input type="email" id="reg-email" name="email" required autocomplete="email"> </div> <div class="form-group"> <label for="reg-username">Username</label> <input type="text" id="reg-username" name="username" required autocomplete="username"> </div> <div class="form-group"> <label for="reg-password">Password</label> <input type="password" id="reg-password" name="password" required autocomplete="new-password" pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}" title="Must contain at least one number, one uppercase and lowercase letter, and at least 8 or more characters"> <p class="password-requirements">8+ characters, with uppercase, lowercase, and numbers.</p> </div> <div class="form-group"> <label for="reg-password-confirm">Confirm Password</label> <input type="password" id="reg-password-confirm" name="password_confirm" required autocomplete="new-password"> </div> <div class="form-group-terms"> <input type="checkbox" id="terms" name="terms" required> <label for="terms">I agree to the <a href="#">Terms of Service</a> and <a href="#">Privacy Policy</a>.</label> </div> <button type="submit" class="submit-btn">Sign Up</button> <p class="login-link"> Already have an account? <a href="#">Log in</a> </p> </form> </div> <!-- START: JavaScript for password confirmation --> <script> const registrationForm = document.getElementById('registrationForm'); const passwordInput = document.getElementById('reg-password'); const confirmPasswordInput = document.getElementById('reg-password-confirm'); registrationForm.addEventListener('submit', function(event) { if (passwordInput.value !== confirmPasswordInput.value) { // Passwords do not match confirmPasswordInput.setCustomValidity('Passwords do not match.'); // Prevent form submission event.preventDefault(); } else { // Passwords match, clear any previous validation message confirmPasswordInput.setCustomValidity(''); } }); // Also, clear the custom validity message when the user starts typing again confirmPasswordInput.addEventListener('input', function() { confirmPasswordInput.setCustomValidity(''); }); </script> <!-- END: JavaScript -->