Stylish Login and Signup Form with Toggle Functionality

 


This code snippet showcases a visually appealing login and signup form with a toggle feature. It allows users to switch seamlessly between login and signup modes within the same interface. While not fully responsive, this design features a sleek layout, animated background, and a vibrant color palette to enhance the user experience.


Key Features:

  • Mode Toggle: Switch between login and signup modes with a single click.
  • Dynamic UI: The form title, subtitle, and input fields adjust automatically based on the selected mode.
  • Stylish Gradient Background: Eye-catching gradient animations create a modern and polished look.
  • Interactive Design: Includes Google login button and basic validation for user input.

This layout is perfect for practice or as a starting point for integrating user authentication into your projects.

Below is the complete code snippet:



<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>InfoSphere - Login/Signup</title>
    <link href="https://cdn.jsdelivr.net/npm/lucide-static@0.259.0/font/lucide.min.css" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: linear-gradient(135deg, #ffb3b3, #d1a3ff, #a3c4ff);
            background-size: 200% 200%;
            animation: bodyGradientAnimation 10s ease infinite;
            padding: 20px;
        }

        .container {
            display: flex;
            width: 800px;
            min-height: 500px;
            background: white;
            border-radius: 15px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            position: relative;
        }

        .form-section {
            flex: 1;
            padding: 20px;
            display: flex;
            flex-direction: column;
            transition: all 0.6s ease-in-out;
            overflow-y: auto;
        }

        .logo {
            display: flex;
            align-items: center;
            gap: 6px;
            margin-bottom: 16px;
        }

        .logo span {
            font-size: 20px;
            font-weight: bold;
            color: #4338ca;
        }

        h1 {
            font-size: 24px;
            margin-bottom: 8px;
        }

        .subtitle {
            color: #666;
            margin-bottom: 16px;
            font-size: 14px;
        }

        .form-group {
            margin-bottom: 15px;
        }

        label {
            display: block;
            margin-bottom: 6px;
            color: #333;
            font-weight: 500;
            font-size: 14px;
        }

        input {
            width: 100%;
            padding: 10px 12px;
            border: 2px solid #e2e8f0;
            border-radius: 6px;
            font-size: 14px;
            transition: border-color 0.2s;
        }

        input:focus {
            outline: none;
            border-color: #4338ca;
        }

        .forgot-password {
            text-align: right;
            margin-bottom: 15px;
        }

        .forgot-password a {
            color: #4338ca;
            text-decoration: none;
            font-size: 12px;
        }

        .submit-btn {
            background: #4338ca;
            color: white;
            border: none;
            padding: 12px;
            border-radius: 6px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            width: 100%;
            margin-bottom: 15px;
            transition: background-color 0.2s;
        }

        .submit-btn:hover {
            background: #3730a3;
        }

        .divider {
            display: flex;
            align-items: center;
            text-align: center;
            margin: 15px 0;
            color: #666;
            font-size: 12px;
        }

        .divider::before,
        .divider::after {
            content: "";
            flex: 1;
            border-bottom: 1px solid #e2e8f0;
        }

        .divider span {
            padding: 0 10px;
        }

        .google-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 6px;
            width: 100%;
            padding: 10px;
            border: 2px solid #e2e8f0;
            border-radius: 6px;
            background: white;
            cursor: pointer;
            font-weight: 500;
            font-size: 14px;
        }

        .google-btn:hover {
            background: #f8fafc;
        }

        .toggle-form {
            text-align: center;
            margin-top: 15px;
            color: #666;
            font-size: 12px;
        }

        .toggle-form a {
            color: #4338ca;
            text-decoration: none;
            font-weight: 500;
            cursor: pointer;
        }

        .illustration-section {
            flex: 1;
            background: linear-gradient(135deg, #ff006e, #ff5f6d, #ffc371, #0077b6, #7209b7);
            background-size: 200% 200%;
            animation: gradientAnimation 8s ease infinite;
            padding: 30px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            color: white;
            text-align: center;
            transition: all 0.6s ease-in-out;
            border-radius: 15px;
        }

        @keyframes gradientAnimation {
            0% { background-position: 0% 0%; }
            50% { background-position: 100% 100%; }
            100% { background-position: 0% 0%; }
        }

        .illustration {
            max-width: 300px;
            margin-bottom: 16px;
        }

        .container.sign-up-mode .form-section {
            transform: translateX(100%);
        }

        .container.sign-up-mode .illustration-section {
            transform: translateX(-100%);
        }

        @media (max-width: 1024px) {
            .container {
                flex-direction: column;
                height: auto;
                width: 100%;
                max-width: 500px;
            }

            .illustration-section {
                display: none;
            }

            .form-section {
                padding: 20px;
            }
        }
    </style>
</head>
<body>
    <div class="container" id="container">
        <div class="form-section">
            <div class="logo">
                <i class="lucide-globe" style="color: #4338ca;"></i>
                <span>Hello Friend</span>
            </div>
            <h1 id="formTitle">Welcome Back!</h1>
            <p class="subtitle" id="formSubtitle">Please enter login details below</p>
            <form id="authForm">
                <div class="form-group">
                    <label for="email">Email</label>
                    <input type="email" id="email" placeholder="Enter your email" required>
                </div>
                <div class="form-group">
                    <label for="password">Password</label>
                    <input type="password" id="password" placeholder="Enter your password" required>
                </div>
                <div class="form-group" id="confirmPasswordGroup" style="display: none;">
                    <label for="confirmPassword">Confirm Password</label>
                    <input type="password" id="confirmPassword" placeholder="Confirm your password">
                </div>
                <div class="forgot-password" id="forgotPasswordLink">
                    <a href="#">Forgot password?</a>
                </div>
                <button type="submit" class="submit-btn" id="submitBtn">Sign in</button>
                <div class="divider">
                    <span>Or continue with</span>
                </div>
                <button type="button" class="google-btn">
                    <i class="lucide-google" style="color: #4338ca;"></i>
                    Log in with Google
                </button>
                <p class="toggle-form">
                    <span id="toggleText">Don't have an account</span> 
                    <a id="toggleLink">Sign Up</a>
                </p>
            </form>
        </div>
        <div class="illustration-section">
            <img src="InfoSphere-logo.png" alt="InfoSphere Logo" class="illustration">
            <p>Your trusted professional space.</p>
        </div>
    </div>

    <script>
        const container = document.getElementById('container');
        const toggleLink = document.getElementById('toggleLink');
        const toggleText = document.getElementById('toggleText');
        const formTitle = document.getElementById('formTitle');
        const formSubtitle = document.getElementById('formSubtitle');
        const submitBtn = document.getElementById('submitBtn');
        const confirmPasswordGroup = document.getElementById('confirmPasswordGroup');
        const forgotPasswordLink = document.getElementById('forgotPasswordLink');
        
        toggleLink.addEventListener('click', () => {
            container.classList.toggle('sign-up-mode');
            if (container.classList.contains('sign-up-mode')) {
                formTitle.textContent = 'Create Account';
                formSubtitle.textContent = 'Please enter your details below';
                submitBtn.textContent = 'Sign Up';
                toggleText.textContent = "Already have an account?";
                toggleLink.textContent = 'Sign In';
                confirmPasswordGroup.style.display = 'block';
                forgotPasswordLink.style.display = 'none';
            } else {
                formTitle.textContent = 'Welcome Back!';
                formSubtitle.textContent = 'Please enter login details below';
                submitBtn.textContent = 'Sign In';
                toggleText.textContent = "Don't have an account?";
                toggleLink.textContent = 'Sign Up';
                confirmPasswordGroup.style.display = 'none';
                forgotPasswordLink.style.display = 'block';
            }
        });
        
        document.getElementById('authForm').addEventListener('submit', function(e) {
            e.preventDefault();
            const email = document.getElementById('email').value;
            const password = document.getElementById('password').value;
            if (container.classList.contains('sign-up-mode')) {
                const confirmPassword = document.getElementById('confirmPassword').value;
                if (password !== confirmPassword) {
                    alert('Passwords do not match!');
                    return;
                }
            }
            console.log('Email:', email);
            console.log('Password:', password);
        });
    </script>
</body>
</html>
  

Post a Comment

Previous Post Next Post