Sample code for simple registration and login form using HTML, CSS, and JavaScript


Creating a full-fledged social media application involves both front-end (JavaScript) and back-end (server-side language and database) development.


Below is a basic example of a front-end code snippet using HTML, CSS, and JavaScript for a simple registration and login form. Please note that this example does not include server-side logic or database interactions, as a complete social media app would require a server to handle these tasks.


<!DOCTYPE html>

<html lang="en">


    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Simple Social Media App</title>


        body {

            font-family: Arial, sans-serif;


        form {

            max-width: 300px;

            margin: 0 auto;






<form id="registrationForm">


    <label for="regUsername">Username:</label>

    <input type="text" id="regUsername" required>


    <label for="regPassword">Password:</label>

    <input type="password" id="regPassword" required>


    <button type="button" onclick="registerUser()">Register</button>



<form id="loginForm">


    <label for="loginUsername">Username:</label>

    <input type="text" id="loginUsername" required>


    <label for="loginPassword">Password:</label>

    <input type="password" id="loginPassword" required>


    <button type="button" onclick="loginUser()">Login</button>




    function registerUser() {

        // Placeholder function for user registration

        var username = document.getElementById('regUsername').value;

        var password = document.getElementById('regPassword').value;


        // Add logic to send registration data to the server

        console.log('Registering user:', username);



    function loginUser() {

        // Placeholder function for user login

        var username = document.getElementById('loginUsername').value;

        var password = document.getElementById('loginPassword').value;


        // Add logic to send login data to the server

        console.log('Logging in user:', username);







In a real-world scenario, you would need to implement server-side logic to handle user registration and login, and you should also use secure practices, such as HTTPS, and store user passwords securely (e.g., using bcrypt).


This example focuses on the front-end aspect of user registration and login forms using basic HTML, CSS, and JavaScript.

Post a Comment


Post a Comment (0)