Published on

Surprisingly Effective Ways To Create A Login Form With Tailwind CSS

Login form

What is Tailwind CSS?

Tailwind CSS is a utility-first CSS framework that focuses on creating personalized user interfaces quickly. It can gives you all the building blocks you are able to create personalized designs without having to fight to override irritating opinionated styles. Also, Tailwind CSS is a highly configurable, low-level CSS framework.

The description of Login form ui component

Simple login form

Why use Tailwind CSS to create a Login form ui component?

  • It can make the building process of Login form ui component faster and more easily.
  • Enables building complex responsive layouts and components freely.
  • Minimum lines of CSS code in Login form component file.

The preview of Login form ui component

Free download of the Login form's source code

The source code of Login form ui component

<style>
  .login_img_section {
  background: linear-gradient(rgba(2,2,2,.7),rgba(0,0,0,.7)),url(https://images.unsplash.com/photo-1650825556125-060e52d40bd0?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80) center center;
}
</style>
<div class="h-screen flex">
          <div class="hidden lg:flex w-full lg:w-1/2 login_img_section
          justify-around items-center">
            <div 
                  class=" 
                  bg-black 
                  opacity-20 
                  inset-0 
                  z-0"
                  >

                  </div>
            <div class="w-full mx-auto px-20 flex-col items-center space-y-6">
              <h1 class="text-white font-bold text-4xl font-sans">Simple App</h1>
              <p class="text-white mt-1">The simplest app to use</p>
              <div class="flex justify-center lg:justify-start mt-6">
                  <a href="#" class="hover:bg-indigo-700 hover:text-white hover:-translate-y-1 transition-all duration-500 bg-white text-indigo-800 mt-4 px-4 py-2 rounded-2xl font-bold mb-2">Get Started</a>
              </div>
            </div>
          </div>
          <div class="flex w-full lg:w-1/2 justify-center items-center bg-white space-y-8">
            <div class="w-full px-8 md:px-32 lg:px-24">
            <form class="bg-white rounded-md shadow-2xl p-5">
              <h1 class="text-gray-800 font-bold text-2xl mb-1">Hello Again!</h1>
              <p class="text-sm font-normal text-gray-600 mb-8">Welcome Back</p>
              <div class="flex items-center border-2 mb-8 py-2 px-3 rounded-2xl">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                  <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M16 12a4 4 0 10-8 0 4 4 0 008 0zm0 0v1.5a2.5 2.5 0 005 0V12a9 9 0 10-9 9m4.5-1.206a8.959 8.959 0 01-4.5 1.207" />
                </svg>
                <input id="email" class=" pl-2 w-full outline-none border-none" type="email" name="email" placeholder="Email Address" />
              </div>
              <div class="flex items-center border-2 mb-12 py-2 px-3 rounded-2xl ">
                <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor">
                  <path fillRule="evenodd" d="M5 9V7a5 5 0 0110 0v2a2 2 0 012 2v5a2 2 0 01-2 2H5a2 2 0 01-2-2v-5a2 2 0 012-2zm8-2v2H7V7a3 3 0 016 0z" clipRule="evenodd" />
                </svg>
                <input class="pl-2 w-full outline-none border-none" type="password" name="password" id="password" placeholder="Password" />
                
              </div>
              <button type="submit" class="block w-full bg-indigo-600 mt-5 py-2 rounded-2xl hover:bg-indigo-700 hover:-translate-y-1 transition-all duration-500 text-white font-semibold mb-2">Login</button>
              <div class="flex justify-between mt-4">
                <span class="text-sm ml-2 hover:text-blue-500 cursor-pointer hover:-translate-y-1 duration-500 transition-all">Forgot Password ?</span>

                <a href="#" class="text-sm ml-2 hover:text-blue-500 cursor-pointer hover:-translate-y-1 duration-500 transition-all">Don't have an account yet?</a>
              </div>
              
            </form>
            </div>
            
          </div>
      </div>

How to create a Login form with Tailwind CSS?

Install tailwind css of verion 3.0.18

Use the script html tag to import the script of Tailwind CSS of the version 3.0.18

<script src="https://cdn.tailwindcss.com"></script>

All the unility class needed to create a Login form component

  • h-screen
  • flex
  • hidden
  • lg:flex
  • w-full
  • lg:w-1/2
  • bg-black
  • z-0
  • mx-auto
  • px-20
  • flex-col
  • text-white
  • text-4xl
  • mt-1
  • lg:justify-start
  • mt-6
  • hover:bg-indigo-700
  • hover:text-white
  • bg-white
  • text-indigo-800
  • mt-4
  • px-4
  • py-2
  • mb-2
  • px-8
  • md:px-32
  • lg:px-24
  • p-5
  • text-gray-800
  • text-2xl
  • mb-1
  • text-sm
  • text-gray-600
  • mb-8
  • border-2
  • px-3
  • h-5
  • w-5
  • text-gray-400
  • pl-2
  • border-none
  • mb-12
  • block
  • bg-indigo-600
  • mt-5
  • ml-2
  • hover:text-blue-500

47 steps to create a Login form component with Tailwind CSS

  1. Use h-screen to make an element span the entire height of the viewport.

  2. Use flex to create a block-level flex container.

  3. Use hidden to set an element to display: none and remove it from the page layout.

  4. Use flex to create a block-level flex container at only large screen sizes.

  5. Use w-full to set an element to a 100% based width.

  6. Use lg:w-1/2 to set an element to a fixed width(1/2) at only large screen sizes.

  7. Control the background color of an element to black using the bg-black utilities.

  8. Control the stack order (or three-dimensional positioning) of an element to 0 in Tailwind, regardless of order it has been displayed, using the z-0 utilities.

  9. Control the horizontal margin of an element to auto using the mx-auto utilities.

  10. Control the horizontal padding of an element to 5rem using the px-20 utilities.

  11. Use flex to create a block-level flex container.

  12. Control the text color of an element to white using the text-white utilities.

  13. Control the text color of an element to 4xl using the text-4xl utilities.

  14. Control the margin on top side of an element to 0.25rem using the mt-1 utilities.

  15. Use justify-start to justify items against the start of the container’s main axis at only large screen sizes.

  16. Control the margin on top side of an element to 1.5rem using the mt-6 utilities.

  17. Control the background color of an element to indigo-700 using the hover:bg-indigo-700 utilities on hover.

  18. Control the text color of an element to white on hover using the hover:text-white utilities.

  19. Control the background color of an element to white using the bg-white utilities.

  20. Control the text color of an element to indigo-800 using the text-indigo-800 utilities.

  21. Control the margin on top side of an element to 1rem using the mt-4 utilities.

  22. Control the horizontal padding of an element to 1rem using the px-4 utilities.

  23. Control the vertical padding of an element to 0.5rem using the py-2 utilities.

  24. Control the margin on bottom side of an element to 0.5rem using the mb-2 utilities.

  25. Control the horizontal padding of an element to 2rem using the px-8 utilities.

  26. Control the horizontal padding of an element to 8rem at only medium screen sizes using the md:px-32 utilities.

  27. Control the horizontal padding of an element to 6rem at only large screen sizes using the lg:px-24 utilities.

  28. Control the padding on all sides of an element to 1.25rem using the p-5 utilities.

  29. Control the text color of an element to gray-800 using the text-gray-800 utilities.

  30. Control the text color of an element to 2xl using the text-2xl utilities.

  31. Control the margin on bottom side of an element to 0.25rem using the mb-1 utilities.

  32. Control the text color of an element to sm using the text-sm utilities.

  33. Control the text color of an element to gray-600 using the text-gray-600 utilities.

  34. Control the margin on bottom side of an element to 2rem using the mb-8 utilities.

  35. Control the border color of an element to 0.5rem using the border-2 utilities.

  36. Control the horizontal padding of an element to 0.75rem using the px-3 utilities.

  37. Use h-5 to set an element to a fixed height(1.25rem).

  38. Use w-5 to set an element to a fixed width(1.25rem).

  39. Control the text color of an element to gray-400 using the text-gray-400 utilities.

  40. Set the left padding of the element to 0.5rem using the pl-2 utilities class

  41. Control the border color of an element to none using the border-none utilities.

  42. Control the margin on bottom side of an element to 3rem using the mb-12 utilities.

  43. Use inline utilities to put the element on its own line and fill its parent.

  44. Control the background color of an element to indigo-600 using the bg-indigo-600 utilities.

  45. Control the margin on top side of an element to 1.25rem using the mt-5 utilities.

  46. Control the margin on left side of an element to 0.5rem using the ml-2 utilities.

  47. Control the text color of an element to blue-500 on hover using the hover:text-blue-500 utilities.

Conclusion

The above is a step-by-step tutorial on how to use Tailwind CSS to create a Login form components, learn and follow along to implement your own components.