Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-opus-4-20250514-thinking-16k· AnthropicHugging Face LMArena Human Preference 140K

Create a login and registration page using React+vite, TailwindCSS, with animation

  1. User

    Create a login and registration page using React+vite, TailwindCSS, with animation

  2. Claude Assistant

    I'll help you create a modern login and registration page with React, Vite, TailwindCSS, and smooth animations. Here's a complete implementation:

    First, let me set up the basic structure. Make sure you have TailwindCSS installed in your Vite project.

    AuthPage.jsx

    import React, { useState } from 'react';
    import { motion, AnimatePresence } from 'framer-motion';
    
    const AuthPage = () => {
      const [isLogin, setIsLogin] = useState(true);
      const [formData, setFormData] = useState({
        email: '',
        password: '',
        confirmPassword: '',
        name: ''
      });
    
      const handleInputChange = (e) => {
        setFormData({
          ...formData,
          [e.target.name]: e.target.value
        });
      };
    
      const handleSubmit = (e) => {
        e.preventDefault();
        console.log(isLogin ? 'Login' : 'Register', formData);
      };
    
      const containerVariants = {
        hidden: { opacity: 0 },
        visible: { 
          opacity: 1,
          transition: { duration: 0.5 }
        }
      };
    
      const formVariants = {
        hidden: { x: isLogin ? -50 : 50, opacity: 0 },
        visible: { 
          x: 0, 
          opacity: 1,
          transition: { 
            duration: 0.5,
            ease: "easeInOut"
          }
        },
        exit: { 
          x: isLogin ? 50 : -50, 
          opacity: 0,
          transition: { duration: 0.3 }
        }
      };
    
      return (
        <motion.div 
          className="min-h-screen bg-gradient-to-br from-purple-400 via-pink-500 to-red-500 flex items-center justify-center p-4"
          variants={containerVariants}
          initial="hidden"
          animate="visible"
        >
          <div className="bg-white bg-opacity-10 backdrop-blur-lg rounded-2xl shadow-2xl p-8 w-full max-w-md border border-white border-opacity-20">
            {/* Toggle Buttons */}
            <div className="flex mb-8 bg-white bg-opacity-20 rounded-lg p-1">
              <button
                onClick={() => setIsLogin(true)}
                className={`flex-1 py-2 px-4 rounded-md transition-all duration-300 font-semibold ${
                  isLogin 
                    ? 'bg-white text-purple-600 shadow-md transform scale-105' 
                    : 'text-white hover:text-gray-200'
                }`}
              >
                Login
              </button>
              <button
                onClick={() => setIsLogin(false)}
                className={`flex-1 py-2 px-4 rounded-md transition-all duration-300 font-semibold ${
                  !isLogin 
                    ? 'bg-white text-purple-600 shadow-md transform scale-105' 
                    : 'text-white hover:text-gray-200'
                }`}
              >
                Register
              </button>
            </div>
    
            {/* Form Content */}
            <AnimatePresence mode="wait">
              <motion.form
                key={isLogin ? 'login' : 'register'}
                variants={formVariants}
                initial="hidden"
                animate="visible"
                exit="exit"
                onSubmit={handleSubmit}
                className="space-y-6"
              >
                <h2 className="text-3xl font-bold text-white text-center mb-6">
                  {isLogin ? 'Welcome Back!' : 'Create Account'}
                </h2>
    
                {!isLogin && (
                  <motion.div
                    initial={{ height: 0, opacity: 0 }}
                    animate={{ height: 'auto', opacity: 1 }}
                    exit={{ height: 0, opacity: 0 }}
                    transition={{ duration: 0.3 }}
                  >
                    <input
                      type="text"
                      name="name"
                      placeholder="Full Name"
                      value={formData.name}
                      onChange={handleInputChange}
                      className="w-full px-4 py-3 bg-white bg-opacity-20 border border-white border-opacity-30 rounded-lg text-white placeholder-gray-200 focus:outline-none focus:ring-2 focus:ring-white focus:bg-opacity-30 transition-all duration-300"
                      required={!isLogin}
                    />
                  </motion.div>
                )}
    
                <div>
                  <input
                    type="email"
                    name="email"
                    placeholder="Email Address"
                    value={formData.email}
                    onChange={handleInputChange}
                    className="w-full px-4 py-3 bg-white bg-opacity-20 border border-white border-opacity-30 rounded-lg text-white placeholder-gray-200 focus:outline-none focus:ring-2 focus:ring-white focus:bg-opacity-30 transition-all duration-300"
                    required
                  />
                </div>
    
                <div>
                  <input
                    type="password"
                    name="password"
                    placeholder="Password"
                    value={formData.password}
                    onChange={handleInputChange}
                    className="w-full px-4 py-3 bg-white bg-opacity-20 border border-white border-opacity-30 rounded-lg text-white placeholder-gray-200 focus:outline-none focus:ring-2 focus:ring-white focus:bg-opacity-30 transition-all duration-300"
                    required
                  />
                </div>
    
                {!isLogin && (
                  <motion.div
                    initial={{ height: 0, opacity: 0 }}
                    animate={{ height: 'auto', opacity: 1 }}
                    exit={{ height: 0, opacity: 0 }}
                    transition={{ duration: 0.3 }}
                  >
                    <input
                      type="password"
                      name="confirmPassword"
                      placeholder="Confirm Password"
                      value={formData.confirmPassword}
                      onChange={handleInputChange}
                      className="w-full px-4 py-3 bg-white bg-opacity-20 border border-white border-opacity-30 rounded-lg text-white placeholder-gray-200 focus:outline-none focus:ring-2 focus:ring-white focus:bg-opacity-30 transition-all duration-300"
                      required={!isLogin}
                    />
                  </motion.div>
                )}
    
                {isLogin && (
                  <div className="flex items-center justify-between text-sm">
                    <label className="flex items-center text-white">
                      <input type="checkbox" className="mr-2 rounded" />
                      Remember me
                    </label>
                    <a href="#" className="text-white hover:underline">
                      Forgot password?
                    </a>
                  </div>
                )}
    
                <motion.button
                  type="submit"
                  whileHover={{ scale: 1.02 }}
                  whileTap={{ scale: 0.98 }}
                  className="w-full py-3 px-4 bg-white text-purple-600 rounded-lg font-bold shadow-lg hover:shadow-xl transition-all duration-300 transform"
                >
                  {isLogin ? 'Sign In' : 'Create Account'}
                </motion.button>
    
                <div className="relative my-6">
                  <div className="absolute inset-0 flex items-center">
                    <div className="w-full border-t border-gray-300"></div>
                  </div>
                  <div className="relative flex justify-center text-sm">
                    <span className="px-2 bg-transparent text-white">Or continue with</span>
                  </div>
                </div>
    
                <div className="grid grid-cols-2 gap-4">
                  <motion.button
                    type="button"
                    whileHover={{ scale: 1.05 }}
                    whileTap={{ scale: 0.95 }}
                    className="flex items-center justify-center px-4 py-2 bg-white bg-opacity-20 border border-white border-opacity-30 rounded-lg text-white hover:bg-opacity-30 transition-all duration-300"
                  >
                    <svg className="w-5 h-5 mr-2" viewBox="0 0 24 24" fill="currentColor">
                      <path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
                      <path d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
                      <path d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"/>
                      <path d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"/>
                    </svg>
                    Google
                  </motion.button>
                  
                  <motion.button
                    type="button"
                    whileHover={{ scale: 1.05 }}
                    whileTap={{ scale: 0.95 }}
                    className="flex items-center justify-center px-4 py-2 bg-white bg-opacity-20 border border-white border-opacity-30 rounded-lg text-white hover:bg-opacity-30 transition-all duration-300"
                  >
                    <svg className="w-5 h-5 mr-2" viewBox="0 0 24 24" fill="currentColor">
                      <path d="M12 2C6.477 2 2 6.477 2 12c0 4.991 3.657 9.128 8.438 9.879V14.89h-2.54V12h2.54V9.797c0-2.506 1.492-3.89 3.777-3.89 1.094 0 2.238.195 2.238.195v2.46h-1.26c-1.243 0-1.63.771-1.63 1.562V12h2.773l-.443 2.89h-2.33v6.989C18.343 21.129 22 16.99 22 12c0-5.523-4.477-10-10-10z"/>
                    </svg>
                    Facebook
                  </motion.button>
                </div>
    
                <p className="text-center text-white text-sm mt-6">
                  {isLogin ? "Don't have an account? " : "Already have an account? "}
                  <button
                    type="button"
                    onClick={() => setIsLogin(!isLogin)}
                    className="font-semibold hover:underline"
                  >
                    {isLogin ? 'Sign up' : 'Sign in'}
                  </button>
                </p>
              </motion.form>
            </AnimatePresence>
          </div>
        </motion.div>
      );
    };
    
    export default AuthPage;
    

    To use this component, you'll need to install the required dependencies:

    npm install framer-motion
    

    And make sure your App.jsx imports and uses the component:

    import AuthPage from './components/AuthPage'
    
    function App() {
      return <AuthPage />
    }
    
    export default App
    

    This implementation includes:

    1. Smooth Animations: Using Framer Motion for page transitions, form switches, and button interactions
    2. Glassmorphism Design: Modern translucent design with backdrop blur
    3. Gradient Background: Eye-catching purple to red gradient
    4. Form Toggle: Animated switch between login and registration
    5. Social Login Buttons: Google and Facebook login options
    6. Responsive Design: Works well on all screen sizes
    7. Interactive Elements: Hover and tap animations on buttons
    8. Clean Form Layout: Well-spaced inputs with consistent styling

    The animations include:

    • Fade-in effect on page load
    • Slide transitions when switching between login/register
    • Scale effects on button hover/tap
    • Height animations for conditional fields
    • Smooth color transitions on focus states

    You can customize the colors, animations, and styling to match your brand requirements. The form currently logs data to console - you'll need to implement actual authentication logic based on your backend API.