ūü•≥
WindFrame is here: Design, prototype and code
sale icon End of Summer Sale ūüéĀ Get Contrast PRO UI library + admin template with 5 admin dahsboards, 23 pages and 10000+ components at 60% off ūüéČ
postImage

How to create and style a Responsive Form using Tailwind CSS

blogImage

By Emmanuel Chinonso

Technical Writer

If you are one of those keeping in the trend of CSS framework, you will notice that tailwind CSS is fast growing in popularity among developers around the world.

It’s different from the other CSS framework in that it makes use of utility-first classes. In today’s tailwind CSS tutorial, we will be creating a responsible form using Tailwind CSS. The tailwind CSS form will look like the image below.

Tailwind CSS Form

Table of content

  • Prerequisites
  • Add Tailwind CSS to project
  • Adding a logo to the Tailwind CSS form
  • Adding the Tailwind CSS form input fields
  • Adding the button
  • Overview of everything
  • Conclusion

Prerequisites

  • Latest version of Tailwind CSS
  • Basic knowledge of HTML
  • Basic knowledge of Tailwind CSS

Add Tailwind CSS to project

For us to be able to build our Tailwind CSS form, we must first install it. You can check our article on how to go about this here, or you can check out the Tailwind CSS docs.

Once the Tailwind CSS is installed, we can link the Tailwind CSS stylesheet to our page by using the link tag on our head element, as shown below.

Code:

1<!DOCTYPE html>
2<html lang="en">
3
4<head>
5    <meta charset="UTF-8">
6    <meta http-equiv="X-UA-Compatible" content="IE=edge">
7    <meta name="viewport" content="width=device-width, initial-scale=1.0">
8    <title>Login form</title>
9    <link rel="stylesheet" href="style.css">
10</head>

Now, we can build the rest of our login form. Adding a logo to the Tailwind CSS form

At this stage, we can go ahead to add some styles to the body of our page. This Tailwind CSS style will serve everything inside our page.

Code:

1<body class="bg-gray-300"
2style="font-family: -apple-system,
3BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;"
4>.

Furthermore, we can go ahead to add the logo to our Tailwind CSS login form.

Code:

1<div class="h-screen flex items-center justify-center">
2  <form action="" 
3class="w-full md:w-1/3 bg-white rounded-lg items-center">
4    <div class="flex font-bold justify-center mt-6">
5       <img src="images/avater1.png" 
6 alt="" 
7 class="h-24 w-24">
8     </div>
9     <h2 
10 class="text-3xl text-center text-gray-700 mb-4">
11 Welcome Back!
12 </h2>.

In the code above, we added the header for our form and the image of the header. Some of the tailwind CSS classes we included on this page include

  • flex which allows items to shrink and grow to prevent overflow
  • w-full gives the form a width of 100%
  • bg-white sets the background to white
  • rounded-lg gives the edge of the form a rounded look
  • md:w-1/3 sets the minimum width to 33.333%
  • mt-6, which sets the top margin to 24px and many other classes included.

The login form at this stage should look like the image below.

Tailwind CSS Form

Adding the Tailwind CSS form input fields

The next step will be to add the input fields and style them using Tailwind CSS.

Code:

1 <div class="px-12 pb-10">
2    <div class="w-full mb-2">
3        <div class="flex justify-center">
4            <input type="text" placeholder="Username"
5             class="px-8 w-full border rounded py-2 text-gray-700 focus:outline-none items-center">
6     </div>
7 </div>
8 <div class="w-full mb-2">
9     <div class="flex justify-center">
10         <input type="password" placeholder="Password"
11           class="px-8 w-full border rounded py-2 text-gray-700 focus:outline-none">
12  </div>
13</div>

In our code, we made two inputs Username and Password. We also styled them the same way. Using some Tailwind CSS classes like

  • border which sets the width of the input to 1px
  • px-8 set the left and right padding to 32px while py-2 sets the top and bottom margin to 8px

The image of our project at this point should look like the image below.

Tailwind CSS Form

Adding the button

For the final step, we need to add the button that the user will click to log in. We are also going to include a forget password and create an account link below our button.

Code:

1<button 
2class="w-full mt-6 py-2 rounded bg-purple-500 text-gray-100 focus:outline-none">
3 Log In
4</button>
5<a href="#"
6    class="text-sm text-opacity-200 float-right mt-6 mb-4 hover:text-purple-600 underline">
7 Forget Password?
8</a>
9<a href="#" 
10 class="text-sm text-opacity-200 float-left mt-6 mb-8 hover:text-purple-600 underline">
11 Create Account
12</a>
13</div>
14</body>
15</html>

The classes we added to the button will have rounded borders with a purple background color, full width, outline focus with padding and margins.

Our web page should look like the image below.

Tailwind CSS Form

Overview of everything

If you have made mistakes while coding due to the wrong usage of ‚Äúdiv‚ÄĚ or didn‚Äôt place a tag well. You can check our complete code below.

Code:

1<!DOCTYPE html>
2<html lang="en">
3
4<head>
5    <meta charset="UTF-8">
6    <meta http-equiv="X-UA-Compatible" content="IE=edge">
7    <meta name="viewport" content="width=device-width, initial-scale=1.0">
8    <title>Login form</title>
9    <link rel="stylesheet" href="style.css">
10</head>
11
12<body class="bg-gray-300"
13style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;">
14<div class="h-screen flex items-center justify-center">
15    <form action="" class="w-full md:w-1/3 bg-white rounded-lg items-center">
16        <div class="flex font-bold justify-center mt-6">
17            <img src="images/avater1.png" alt="" class="h-24 w-24">
18        </div>
19        <h2 class="text-3xl text-center text-gray-700 mb-4">Welcome Back!</h2>
20        <div class="px-12 pb-10">
21            <div class="w-full mb-2">
22                <div class="flex justify-center">
23                    <input type="text" placeholder="Username"
24                        class="px-8 w-full border rounded py-2 text-gray-700 focus:outline-none items-center">
25                </div>
26            </div>
27            <div class="w-full mb-2">
28                <div class="flex justify-center">
29                    <input type="password" placeholder="Password"
30                        class="px-8 w-full border rounded py-2 text-gray-700 focus:outline-none">
31                </div>
32            </div>
33             <button class="w-full mt-6 py-2 rounded bg-purple-500 text-gray-100 focus:outline-none">Log In</button>
34            <a href="#"
35                class="text-sm text-opacity-200 float-right mt-6 mb-4 hover:text-purple-600 underline">
36 Forget Password?
37 </a>
38             <a href="#" 
39 class="text-sm text-opacity-200 float-left mt-6 mb-8 hover:text-purple-600 underline">
40 Create Account
41 </a>
42        </div>
43</div>
44</body>
45
46</html>

Conclusion

In today Tailwind CSS tutorial practice, we built a login form using Tailwind CSS. The tailwind CSS form had an image, two inputs (Username and Password) and a login button.

However, we styled our Tailwind CSS form using a CSS framework called Tailwind CSS.

I hope you enjoyed the Tailwind CSS tutorial.

Create Stunning websites and web apps

Trying to build out all user interfaces and components for your website or web app from scratch can become a very tedious task. A huge reason why we created Contrast Bootstrap to help reduce the amount of time we spend doing that, so we can focus on building some other aspects of the project. Contrast Bootstrap PRO consists of a UI Kit featuring over 10000+ component variants. Together with a template of 5 admin dashboards and 23+ additional multipurpose pages template for building almost any type of website or web app. You can view a demo and learn more about Contrast by clicking here.Try contrast pro

ad-banner

Contrast Bootstrap PRO was built using the most popular CSS framework Bootstrap to help build your next landing, admin SAAS, prelaunch etc project with a clean, prebuilt and well documented template and UI components.Learn more about Contrast

Related Posts

Comments

...