Build a Login/Signup Page with React & TailwindCSS
Tags: javascript, tutorial, react, webdev
Published: 2022-04-02 14:19:45

A Login/Signup page is something you will find in every modern application whether it is an E-Commerce website or a Social Media application. In this beginner-friendly tutorial, we will build a simple Login/Signup page where you the user can toggle between Login and Signup with a single click.

**Prerequisites:**
- React Hooks (Basic)
- CSS (Basic)

![sign](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2cbtrvafwv27i9t1o06j.jpg)

<h3> App Setup </h3>
Follow this [doc](https://tailwindcss.com/docs/guides/create-react-app) to setup React app with TailwindCSS. This will take around 1-2 minutes. Once done, create a 'pages' folder in the 'src' directory and create a 'Login.jsx' page in the folder. For now, we will simply return the Login component and render it from our App.jsx as such:

![show](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vnd1cky6chxvj4q9cbhp.png)

Later, you can implement routing in your App and render it as such:

![route](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fzd8klzrv16ufzrmda6d.png)

<h3> Design Login Form </h3>
In our Login page, let's create state variables for our inputs and to toggle between Login & SignUp forms:

![states](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1tgn8ehrv3sq3aug7yzx.png)

When isLogin is true, we will display the Login form and when it is false, we will display the SignUp form. Let's go ahead and style the Login form!
 

![log](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oplcpfbl5c9svgpyf746.jpg)

Let's go ahead and style them as such:

Our Login form can be divided into 4 parts:
- Top (consisting App name and Sign In text)
- Social Icons container
- Inputs & Submit button
- Bottom info paragraph with toggle

![Top](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njdpno9yqwiooghkyu3h.png)

Let's add a custom style for our socialIcon in the 'index.css':

![social](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rxa6w90lblocx6uzc522.png)

![Icons](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kxf2ixa6i8hc7min21yl.png)

Let's finish up by styling our inputs and the bottom section where we will add an onClick handler so that we can switch from 'Login' to 'Signup' on clicking the 'Create Account' paragraph.

![button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lo3n199304krrvrsdt1o.png)

![toggler](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/upb3yycp5ba89krjwjbw.png)

Let's put it all together and create our LoginForm component:

![complete](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ppwmkh51optj69sdql5y.png)

Similarly, we can go ahead and create our SignUp form component and customize it as per our need. For now, we will add an Username and an Avatar URL input field and change the background color for our SignUp Form:

![register](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qwuvq2ezul3imrqlai2b.png)

To put it all together, we need to conditionally render the Login/Signup form based on the isLogin state as such:

![switch](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ubggegh3sv3709q054oq.png)

<img width="100%" style="width:100%" src="https://media.giphy.com/media/vafS3QxrgAgllKYSr7/giphy.gif">

And just like that, we have our Login page setup where the user can switch between Login & Signup with a single click!
Feel free to customize it as your own and add animations and your app logo!

<h4> Resources: </h4>
[TailwindCSS](https://tailwindcss.com/)
[React Hooks](https://reactjs.org/docs/hooks-state.html)
[Code Gist](https://gist.github.com/kishibe-rohan/0ff4a6c0d435f83998ee119f3687ed6b)