- Published on
How To Create A Form With Tailwind CSS From Scratch

- What is Tailwind CSS?
- The description of form ui component
- Why use Tailwind CSS to create a form ui component?
- The preview of form ui component
- The source code of form ui component
- How to create a form with Tailwind CSS?
- Install tailwind css of verion 2.2.4
- All the unility class needed to create a form component
- 61 steps to create a form component with Tailwind CSS
- Conclusion
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
Use
w-full
to set an element to a 100% based width.Use
h-14
to set an element to a fixed height(3.5rem).Control the padding on top side of an element to 0.5rem using the
pt-2
utilities.Control the text color of an element to center using the
text-center
utilities.Control the background color of an element to gray-700 using the
bg-gray-700
utilities.Use
overflow-hidden
to clip any content within an element that overflows the bounds of that element.Control the text color of an element to 3xl using the
text-3xl
utilities.Control the text color of an element to white using the
text-white
utilities.Control the text color of an element to gray-600 using the
text-gray-600
utilities.Control the margin on all sides of an element to 0rem using the
m-0
utilities.Control the padding on all sides of an element to 0rem using the
p-0
utilities.Use
relative
to position an element according to the normal flow of the document.Control the horizontal margin of an element to auto using the
mx-auto
utilities.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Control the margin on bottom side of an element to 0.25rem using the
mb-1
utilities.Control the margin on top side of an element to 2.5rem using the
mt-10
utilities.Control the margin on top side of an element to 0rem at only medium screen sizes using the
md:mt-0
utilities.Control the horizontal padding of an element to 0.5rem using the
px-2
utilities.Control the vertical padding of an element to 2rem using the
py-8
utilities.Control the background color of an element to white using the
bg-white
utilities.Control the padding on all sides of an element to 1.5rem at only small screen sizes using the
sm:p-6
utilities.Use
grid
to create a grid container.Use
grid
to create a grid container.To specify the width between columns, you can use the
gap-6
utilities.Use
inline
utilities to put the element on its own line and fill its parent.Control the text color of an element to sm using the
text-sm
utilities.Control the text color of an element to gray-700 using the
text-gray-700
utilities.Control the margin on top side of an element to 0.25rem using the
mt-1
utilities.Control the border color of an element to indigo-500 using the
focus:border-indigo-500
utilities on focus.Control the text color of an element to sm at only small screen sizes using the
sm:text-sm
utilities.Control the border color of an element to gray-300 using the
border-gray-300
utilities.Control the text color of an element to gray-300 using the
text-gray-300
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the horizontal padding of an element to 0.75rem using the
px-3
utilities.Control the margin on top side of an element to 0.75rem using the
mt-3
utilities.Control the margin on top side of an element to 0.5rem using the
mt-2
utilities.Control the margin on top side of an element to 2rem using the
mt-8
utilities.Control the text color of an element to base using the
text-base
utilities.Control the text color of an element to 1.5xl using the
text-1.5xl
utilities.Control the text color of an element to gray-900 using the
text-gray-900
utilities.Use
h-5
to set an element to a fixed height(1.25rem).Use
h-4
to set an element to a fixed height(1rem).Use
w-4
to set an element to a fixed width(1rem).Control the text color of an element to indigo-600 using the
text-indigo-600
utilities.Control the margin on left side of an element to 0.75rem using the
ml-3
utilities.Control the horizontal padding of an element to 1rem using the
px-4
utilities.Control the vertical padding of an element to 0.75rem using the
py-3
utilities.Control the text color of an element to right using the
text-right
utilities.Control the horizontal padding of an element to 1.5rem at only small screen sizes using the
sm:px-6
utilities.Control the margin on right side of an element to 1rem using the
mr-4
utilities.Use
inline-flex
to create an inline flex container that flows with text.Use
w-24
to set an element to a fixed width(6rem).Control the border color of an element to transparent using the
border-transparent
utilities.Control the background color of an element to gray-600 using the
bg-gray-600
utilities.Control the background color of an element to gray-700 using the
hover:bg-gray-700
utilities on hover.Control the background color of an element to indigo-600 using the
bg-indigo-600
utilities.Control the background color of an element to indigo-700 using the
hover:bg-indigo-700
utilities on hover.Use
hidden
to set an element to display: none and remove it from the page layout.Use
inline
utilities to put the element on its own line and fill its parent at only small screen sizes.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.