Clear, practical technology insights BSOD Code Lookup · Windows Error Code Lookup · Wi-Fi Troubleshooting · PC Troubleshooting Checklist

How to Build a Login Screen with React and Bootstrap

Learn how to build a login screen with React and Bootstrap with practical instructions, useful tips, and troubleshooting guidance for common issues.

Table of Contents

Learn how to build a login screen with React and Bootstrap with practical instructions, useful tips, and troubleshooting guidance for common issues.

Most websites today require users to register to access certain features or special pages, but building a login screen is one of the most tedious tasks.

This guide explains how to build a simple yet beautiful login screen using React and Bootstrap 5 !

Required

  • Basic knowledge of HTML, CSS, and Javascript.
  • Basic understanding of React.
  • Set up NodeJS on your computer.

Setting up a React App

Run the following command to create a new React project:

npx create-react-app react-login

Open the project and launch the application:

cd react-login npm start

Once the build process is complete, the application will look like this:

Setting up a React App screenshot for Build a Login Screen with React and Bootstrap

Install Bootstrap

Install Bootstrap using npm:

npm install –save bootstrap

Edit App.js and add an import command for Bootstrap:

import "bootstrap/dist/css/bootstrap.min.css"

Go ahead and delete the boilerplate code that your React app adds by default App.js. This file will look like this:

import "bootstrap/dist/css/bootstrap.min.css" import "./App.css" function App() { return } export default App

Establish a Roadmap

First, you need to create a new Auth element in Auth.js. We will be working on the Auth element needed to set up the route.

import React from "react" export default function (props) { return Auth Screen }

In a real-world application, you would navigate the user to the login screen if they haven't already. This is where the navigation comes in; run the following command to install it react-router-dom, and restart the React app after the installation is complete.

npm install --save react-router-dom

Edit the file App.jsto set up the login route and default settings. Below is the login interface on the route /auth.

import "bootstrap/dist/css/bootstrap.min.css" import "./App.css" import { BrowserRouter, Routes, Route } from "react-router-dom" import Auth from "./Auth" function App() { return ( } /> ) } export default App

Create a Login Form

Edit Auth.jsthe initial creation:

import React from "react" export default function (props) { return (

Sign In

   

Forgot password?

 ) }

Edit App.cssto include:

.App { background-color: white; } .Auth-form-container { display: flex; justify-content: center; align-items: center; width: 100vw; height: 100vh; } .Auth-form { width: 420px; box-shadow: rgb(0 0 0 / 16%) 1px 1px 10px; padding-top: 30px; padding-bottom: 20px; border-radius: 8px; background-color: white; } .Auth-form-content { padding-left: 12%; padding-right: 12%; } .Auth-form-title { text-align: center; margin-bottom: 1em; font-size: 24px; color: rgb(34, 34, 34); font-weight: 800; } label { font-size: 14px; font-weight: 600; color: rgb(34, 34, 34); }

If you open the route /auth, you will see the following form:

Sign In screenshot for Build a Login Screen with React and Bootstrap (2)

Add a Registration Form

Typically, programmers want users to register if they don't already have an account. (Edit element Auth.js:)

import React, { useState } from "react" export default function (props) { let [authMode, setAuthMode] = useState("signin") const changeAuthMode = () => { setAuthMode(authMode === "signin" ? "signup" : "signin") } if (authMode === "signin") { return (

Sign In

 Not registered yet?{" "} Sign Up   

Forgot password?

 ) } return (

Sign In

 Already registered?{" "} Sign In    

Forgot password?

 ) }

Used useStateto switch between login and registration. Now when you access [website] /auth, you can switch between login and registration.

Above is how to create a login/registration UI using React with Bootstrap . I hope this article is helpful to you.

FAQ

What is the best way to build a login screen with react and bootstrap?

Learn how to build a login screen with React and Bootstrap with practical instructions, useful tips, and troubleshooting guidance for common issues.

What should you prepare before you build a login screen with react and bootstrap?

Key takeaway: Learn how to build a login screen with React and Bootstrap with practical instructions, useful tips, and troubleshooting guidance for common issues.

What common mistakes should you avoid?

Most websites today require users to register to access certain features or special pages, but building a login screen is one of the most tedious tasks.

Discussion

Reader Comments 0

Sign in with email or Google to join the discussion.