ūüéČ
Windframe Form builder is finally here.
postImage

Tailwind form-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. You can use Windframe to create and customize your own Tailwind form. 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 login form
  • Adding the Tailwind CSS login 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:

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

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:

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

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

Code:

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

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 tailwind form will 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:

html
<div class="px-12 pb-10">
<div class="w-full mb-2">
<div class="flex justify-center">
<input
type="text"
placeholder="Username"
class="px-8 w-full border rounded py-2 text-gray-700 focus:outline-none items-center"
/>
</div>
</div>
<div class="w-full mb-2">
<div class="flex justify-center">
<input
type="password"
placeholder="Password"
class="px-8 w-full border rounded py-2 text-gray-700 focus:outline-none"
/>
</div>
</div>
</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

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:

html
<button 
class="w-full mt-6 py-2 rounded bg-purple-500 text-gray-100 focus:outline-none">
Log In
</button>
<a href="#"
    class="text-sm text-opacity-200 float-right mt-6 mb-4 hover:text-purple-600 underline">
Forget Password?
</a>
<a href="#" 
class="text-sm text-opacity-200 float-left mt-6 mb-8 hover:text-purple-600 underline">
Create Account
</a>
</div>
</body>
</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 Tailwind form 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:

html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login form</title>
    <link rel="stylesheet" href="style.css">
</head>
<body class="bg-gray-300"
style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell,
 'Open Sans','Helvetica Neue', sans-serif;">
<div class="h-screen flex items-center justify-center">
    <form action="" class="w-full md:w-1/3 bg-white rounded-lg items-center">
        <div class="flex font-bold justify-center mt-6">
            <img src="images/avater1.png" alt="" class="h-24 w-24">
        </div>
        <h2 class="text-3xl text-center text-gray-700 mb-4">Welcome Back!</h2>
        <div class="px-12 pb-10">
            <div class="w-full mb-2">
                <div class="flex justify-center">
                    <input type="text" placeholder="Username"
                        class="px-8 w-full border rounded py-2 text-gray-700
 focus:outline-none items-center">
                </div>
            </div>
            <div class="w-full mb-2">
                <div class="flex justify-center">
                    <input type="password" placeholder="Password"
                        class="px-8 w-full border rounded py-2 text-gray-700 focus:outline-none">
                </div>
            </div>
             <button class="w-full mt-6 py-2 rounded bg-purple-500 text-gray-100 focus:outline-none">Log In
</button>
            <a href="#"
                class="text-sm text-opacity-200 float-right mt-6 mb-4 hover:text-purple-600 underline">
Forget Password?
</a>
             <a href="#" 
class="text-sm text-opacity-200 float-left mt-6 mb-8 hover:text-purple-600 underline">
Create Account
</a>
        </div>
</div>
</body>
</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. You can decide to make really good UI by using Windframe, a drag and drop website builder that makes building website look like a piece of cake.

I hope you enjoyed the Tailwind CSS tutorial.

Resources

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.Download the free react template

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

...