Published on

How To Create A Form With Tailwind CSS From Scratch

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 form ui component

Its a business form

Why use Tailwind CSS to create a form ui component?

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

The preview of form ui component

Free download of the form's source code

The source code of form ui component

<!-- This is an example component -->
<div
        class="w-full h-14 pt-2 text-center  bg-gray-700  shadow overflow-hidden sm:rounded-md font-bold text-3xl text-white ">
        Job Requisition Form

    </div>

    <section class="text-gray-600 body-font  m-0 p-0 relative"></section>


    <div class="container    mx-auto">
        <div class="flex flex-col text-center w-full mb-1">

        </div>

        <div class="mt-10 md:mt-0 md:col-span-2">
            <form action="#" method="POST">
                <div class="shadow overflow-hidden sm:rounded-md">
                    <div class="px-2 py-8 bg-white sm:p-6">
                        <div class="grid grid-cols-6 gap-6">
                            <div class="col-span-6 sm:col-span-3">
                                <label for="first-name" class="block text-sm font-medium text-gray-700">Requisition
                                    No</label>
                                <input type="text" name="first-name" placeholder="1" id="first-name"
                                    autocomplete="given-name"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>

                            <div class="col-span-6 sm:col-span-3">
                                <label for="last-name" class="block text-sm font-medium text-gray-700">Requisition
                                    date</label>
                                <input type="text" name="last-name" placeholder="09/02/2021" id="last-name"
                                    autocomplete="family-name"
                                    class="mt-1 focus:ring-indigo-500 text-gray-300  focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md" />
                            </div>
                            <div class="col-span-6 sm:col-span-3">
                                <label for="last-name" class="block text-sm font-medium text-gray-700">Required
                                    date</label>
                                <input type="text" name="last-name" placeholder="09/02/2021" id="last-name"
                                    autocomplete="family-name"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>




                            <div class="col-span-6 sm:col-span-3">
                                <label for="last-name" class="block text-sm font-medium text-gray-700">
                                    Designation</label>
                                <input type="text" name="last-name" placeholder="Gate Pass Officer" id="last-name"
                                    autocomplete="family-name"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>



                            <div class="col-span-6 sm:col-span-3">
                                <label for="country" class="block text-sm font-medium text-gray-700">
                                    Location</label>
                                <select id="country" name="country" autocomplete="country"
                                    class="mt-1 block w-full py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
                                    <option>Head office</option>
                                    <option>Canada</option>
                                    <option>Mexico</option>
                                </select>
                            </div>
                            <div class="col-span-6 sm:col-span-3">
                                <label for="country" class="block text-sm font-medium text-gray-700">
                                    project</label>
                                <select id="country" name="country" autocomplete="country"
                                    class="mt-1 block w-full py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
                                    <option>construction Road</option>
                                    <option>Canada</option>
                                    <option>Mexico</option>
                                </select>
                            </div>



                            <div class="col-span-6 sm:col-span-3">
                                <label for="country" class="block text-sm font-medium text-gray-700">
                                    Gender</label>
                                <select id="country" name="country" autocomplete="country"
                                    class="mt-1 block w-full py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
                                    <option>Male</option>
                                    <option>female</option>
                                    <option>other</option>
                                </select>
                            </div>
                            <div class="col-span-6 sm:col-span-3">
                                <label for="last-name" class="block text-sm font-medium text-gray-700">
                                    Age</label>
                                <input type="text" name="last-name" placeholder="above 18" id="last-name"
                                    autocomplete="family-name"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>


                            <div class="col-span-6 sm:col-span-3">
                                <label for="country" class="block text-sm font-medium text-gray-700">
                                    No of Vacanices</label>
                                <select id="country" name="country" autocomplete="country"
                                    class="mt-1 block w-full py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
                                    <option>1</option>
                                    <option>2</option>
                                    <option>3</option>
                                </select>
                            </div>
                            <div class="col-span-6 sm:col-span-3">
                                <label for="last-name" class="block text-sm font-medium text-gray-700">
                                    Job Lavel</label>
                                <input type="text" name="last-name" id="last-name" placeholder="internee officer"
                                    autocomplete="family-name"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>



                            <div class="col-span-6 sm:col-span-3">
                                <label for="country" class="block text-sm font-medium text-gray-700">
                                    Department</label>
                                <select id="country" name="country" autocomplete="country"
                                    class="mt-3 block w-full py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
                                    <option class="mt-2">HR</option>
                                    <option>Canada</option>
                                    <option>Mexico</option>
                                </select>
                            </div>
                            <div class="col-span-6 sm:col-span-3">
                                <label for="last-name" class="block text-sm font-medium text-gray-700">
                                    Section</label>
                                <input type="text" name="last-name" placeholder="gate managment" id="last-name"
                                    autocomplete="family-name"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>



                            <div class="col-span-6 sm:col-span-3">
                                <label for="last-name" class="block text-sm font-medium text-gray-700">
                                    Academic Qualification</label>
                                <input type="text" name="last-name" placeholder="BBA" id="last-name"
                                    autocomplete="family-name"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>
                            <div class="col-span-6 sm:col-span-3">
                                <label for="last-name" class="block text-sm font-medium text-gray-700">
                                    Required experience</label>
                                <input type="text" name="last-name" placeholder="2 years or above" id="last-name"
                                    autocomplete="family-name"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>

                            <div class="col-span-6 sm:col-span-6">
                                <label for="email-address" class="block text-sm font-medium text-gray-700">Email
                                    description</label>
                                <input type="text" name="email-address"
                                    placeholder="1- 334343434 It should be an editor to fill the job description of around 5 to 10 Lines ."
                                    id="email-address" autocomplete="email"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>


                            <div class="col-span-6 sm:col-span-3">
                                <label for="last-name" class="block text-sm font-medium text-gray-700">
                                    No. of meetings/interviews</label>
                                <input type="text" name="last-name" placeholder="3" id="last-name"
                                    autocomplete="family-name"
                                    class="mt-1 focus:ring-indigo-500 focus:border-indigo-500 block w-full shadow-sm sm:text-sm border-gray-300 rounded-md">
                            </div>


                        </div>
                        <fieldset class="mt-8 ">
                            <legend class=" text-base  text-1.5xl font-medium text-gray-900">Job Skill</legend>
                            <div class="mt-2 space-y-4">
                                <div class="flex place-items-center">
                                    <div class="flex items-center h-5">
                                        <input id="comments" name="comments" type="checkbox"
                                            class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                    </div>
                                    <div class="ml-3 text-sm">
                                        <label for="comments" class="font-regular text-gray-700">Accounting</label>

                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex items-center h-5">
                                        <input id="comments" name="comments" type="checkbox"
                                            class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                    </div>
                                    <div class="ml-3 text-sm">
                                        <label for="comments" class="font-regular text-gray-700">Bookkeeping</label>

                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex items-center h-5">
                                        <input id="comments" name="comments" type="checkbox"
                                            class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                    </div>
                                    <div class="ml-3 text-sm">
                                        <label for="comments" class="font-regular text-gray-700">Auditing</label>

                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex items-center h-5">
                                        <input id="comments" name="comments" type="checkbox"
                                            class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                    </div>
                                    <div class="ml-3 text-sm">
                                        <label for="comments" class="font-regular text-gray-700">written
                                            communication</label>

                                    </div>
                                </div>
                                <div class="flex items-start">
                                    <div class="flex items-center h-5">
                                        <input id="comments" name="comments" type="checkbox"
                                            class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                    </div>
                                    <div class="ml-3 text-sm">
                                        <label for="comments" class="font-regular text-gray-700">Team
                                            Managment</label>

                                    </div>
                                </div>
                                <legend class=" text-base  text-1.5xl font-medium text-gray-900">
                                    Interview/type
                                </legend>
                                <div class="mt-2 space-y-4">
                                    <div class="flex items-start">
                                        <div class="flex items-center h-5">
                                            <input id="comments" name="comments" type="checkbox"
                                                class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                        </div>
                                        <div class="ml-3 text-sm">
                                            <label for="comments"
                                                class="font-mediuregular text-gray-700">Technical</label>

                                        </div>
                                    </div>
                                    <div class="flex items-start">
                                        <div class="flex items-center h-5">
                                            <input id="comments" name="comments" type="checkbox"
                                                class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                        </div>
                                        <div class="ml-3 text-sm">
                                            <label for="comments" class="font-mediuregular text-gray-700">HR</label>

                                        </div>
                                    </div>
                                    <div class="flex items-start">
                                        <div class="flex items-center h-5">
                                            <input id="comments" name="comments" type="checkbox"
                                                class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                        </div>
                                        <div class="ml-3 text-sm">
                                            <label for="comments" class="font-mediuregular text-gray-700">Final</label>

                                        </div>
                                    </div>

                                    <legend class=" text-base  text-1.5xl font-medium text-gray-900">
                                        Competencies
                                    </legend>
                                    <div class="   space-y-4">
                                        <div class="flex  items-start">
                                            <div class="flex items-center h-5">
                                                <input id="comments" name="comments" type="checkbox"
                                                    class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                            </div>
                                            <div class=" text-sm">
                                                <label for="comments"
                                                    class=" ml-3 font-mediuregular text-gray-700">Analysis</label>

                                            </div>
                                        </div>
                                        <div class="flex items-start">
                                            <div class="flex items-center h-5">
                                                <input id="comments" name="comments" type="checkbox"
                                                    class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                            </div>
                                            <div class="ml-3 text-sm">
                                                <label for="comments" class="font-mediuregular text-gray-700">R &
                                                    D</label>

                                            </div>
                                        </div>
                                        <div class="flex items-start">
                                            <div class="flex items-center h-5">
                                                <input id="comments" name="comments" type="checkbox"
                                                    class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                            </div>
                                            <div class="ml-3 text-sm">
                                                <label for="comments"
                                                    class="font-mediuregular text-gray-700">Bookkeeping</label>

                                            </div>
                                        </div>
                                        <div class="flex items-start">
                                            <div class="flex items-center h-5">
                                                <input id="comments" name="comments" type="checkbox"
                                                    class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                            </div>
                                            <div class="ml-3 text-sm">
                                                <label for="comments" class="font-mediuregular text-gray-700">Quick
                                                    Larner</label>

                                            </div>
                                        </div>
                                        <div class="flex items-start">
                                            <div class="flex items-center h-5">
                                                <input id="comments" name="comments" type="checkbox"
                                                    class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
                                            </div>
                                            <div class="ml-3 text-sm">
                                                <label for="comments" class="font-mediuregular text-gray-700">Team
                                                    Managment</label>

                                            </div>
                                        </div>


                                    </div>
                        </fieldset>

                    </div>
                    <div class="px-4 py-3 bg-white text-right sm:px-6">
                        <button type="submit"
                            class="mr-4 inline-flex justify-center w-24 py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md ring ring-gray-500 ring-offset-4  text-white bg-gray-600 hover:bg-gray-700 focus:outline-none focus:ring-2  focus:ring-indigo-500">
                            New
                        </button>
                        <button type="submit"
                            class="inline-flex justify-center w-24 py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md ring  ring-indigo-500 ring-offset-4 bg-indigo-600 hover:bg-indigo-700 text-whitefocus:outline-none focus:ring-2  focus:ring-indigo-500">
                            Save
                        </button>

                    </div>
                </div>
        </div>
        </form>
    </div>
    </section>

    <div class="hidden sm:block" aria-hidden="true">
        <div class="py-5">
            <div class=""></div>
        </div>
    </div>

How to create a form with Tailwind CSS?

Install tailwind css of verion 2.2.4

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

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

All the unility class needed to create a form component

  • w-full
  • h-14
  • pt-2
  • text-center
  • bg-gray-700
  • overflow-hidden
  • text-3xl
  • text-white
  • text-gray-600
  • m-0
  • p-0
  • relative
  • mx-auto
  • flex
  • flex-col
  • mb-1
  • mt-10
  • md:mt-0
  • px-2
  • py-8
  • bg-white
  • sm:p-6
  • grid
  • grid-cols-6
  • gap-6
  • block
  • text-sm
  • text-gray-700
  • mt-1
  • focus:border-indigo-500
  • sm:text-sm
  • border-gray-300
  • text-gray-300
  • py-2
  • px-3
  • mt-3
  • mt-2
  • mt-8
  • text-base
  • text-1.5xl
  • text-gray-900
  • h-5
  • h-4
  • w-4
  • text-indigo-600
  • ml-3
  • px-4
  • py-3
  • text-right
  • sm:px-6
  • mr-4
  • inline-flex
  • w-24
  • border-transparent
  • bg-gray-600
  • hover:bg-gray-700
  • bg-indigo-600
  • hover:bg-indigo-700
  • hidden
  • sm:block
  • py-5

61 steps to create a form component with Tailwind CSS

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

  2. Use h-14 to set an element to a fixed height(3.5rem).

  3. Control the padding on top side of an element to 0.5rem using the pt-2 utilities.

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

  5. Control the background color of an element to gray-700 using the bg-gray-700 utilities.

  6. Use overflow-hidden to clip any content within an element that overflows the bounds of that element.

  7. Control the text color of an element to 3xl using the text-3xl utilities.

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

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

  10. Control the margin on all sides of an element to 0rem using the m-0 utilities.

  11. Control the padding on all sides of an element to 0rem using the p-0 utilities.

  12. Use relative to position an element according to the normal flow of the document.

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

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

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

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

  17. Control the margin on top side of an element to 2.5rem using the mt-10 utilities.

  18. Control the margin on top side of an element to 0rem at only medium screen sizes using the md:mt-0 utilities.

  19. Control the horizontal padding of an element to 0.5rem using the px-2 utilities.

  20. Control the vertical padding of an element to 2rem using the py-8 utilities.

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

  22. Control the padding on all sides of an element to 1.5rem at only small screen sizes using the sm:p-6 utilities.

  23. Use grid to create a grid container.

  24. Use grid to create a grid container.

  25. To specify the width between columns, you can use the gap-6 utilities.

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

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

  28. Control the text color of an element to gray-700 using the text-gray-700 utilities.

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

  30. Control the border color of an element to indigo-500 using the focus:border-indigo-500 utilities on focus.

  31. Control the text color of an element to sm at only small screen sizes using the sm:text-sm utilities.

  32. Control the border color of an element to gray-300 using the border-gray-300 utilities.

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

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

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

  36. Control the margin on top side of an element to 0.75rem using the mt-3 utilities.

  37. Control the margin on top side of an element to 0.5rem using the mt-2 utilities.

  38. Control the margin on top side of an element to 2rem using the mt-8 utilities.

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

  40. Control the text color of an element to 1.5xl using the text-1.5xl utilities.

  41. Control the text color of an element to gray-900 using the text-gray-900 utilities.

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

  43. Use h-4 to set an element to a fixed height(1rem).

  44. Use w-4 to set an element to a fixed width(1rem).

  45. Control the text color of an element to indigo-600 using the text-indigo-600 utilities.

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

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

  48. Control the vertical padding of an element to 0.75rem using the py-3 utilities.

  49. Control the text color of an element to right using the text-right utilities.

  50. Control the horizontal padding of an element to 1.5rem at only small screen sizes using the sm:px-6 utilities.

  51. Control the margin on right side of an element to 1rem using the mr-4 utilities.

  52. Use inline-flex to create an inline flex container that flows with text.

  53. Use w-24 to set an element to a fixed width(6rem).

  54. Control the border color of an element to transparent using the border-transparent utilities.

  55. Control the background color of an element to gray-600 using the bg-gray-600 utilities.

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

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

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

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

  60. Use inline utilities to put the element on its own line and fill its parent at only small screen sizes.

  61. Control the vertical padding of an element to 1.25rem using the py-5 utilities.

Conclusion

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