- Published on
Best Ways To Build A Form With Tailwind CSS

- What is Tailwind CSS?
- The description of form ui component
- Why use Tailwind CSS to make a form ui component?
- The preview of form ui component
- The source code of form ui component
- How to make a form with Tailwind CSS?
- Install tailwind css of verion 2.2.4
- All the unility class needed to make a form component
- 64 steps to make 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
Form - responsive
Why use Tailwind CSS to make 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
<div class="container items-center px-5 py-12 lg:px-20">
<form class="flex flex-col w-full p-10 px-8 pt-6 mx-auto my-6 mb-4 transition duration-500 ease-in-out transform bg-white border rounded-lg lg:w-1/2 ">
<section class="flex flex-col w-full h-full p-1 overflow-auto">
<label for="name" class="text-base leading-7 text-blueGray-500 mb-5">Input Image</label>
<header class="flex flex-col items-center justify-center py-12 text-base text-blueGray-500 transition duration-500 ease-in-out transform bg-white border border-dashed rounded-lg focus:border-blue-500 focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2">
<p class="flex flex-wrap justify-center mb-3 text-base leading-7 text-blueGray-500">
<span>Drag and drop your</span> <span>files anywhere or</span>
</p>
<button class="w-auto px-2 py-1 my-2 mr-2 text-blueGray-500 transition duration-500 ease-in-out transform border rounded-md hover:text-blueGray-600 text-md focus:shadow-outline focus:outline-none focus:ring-2 ring-offset-current ring-offset-2 hover:bg-gray-100"> Upload a file </button>
</header>
</section>
<div class="relative pt-4">
<label for="name" class="text-base leading-7 text-blueGray-500">Input Text</label>
<input type="text" id="name" name="name" placeholder="name" class="w-full px-4 py-2 mt-2 mr-4 text-base text-black transition duration-500 ease-in-out transform rounded-lg bg-gray-100 focus:border-blueGray-500 focus:bg-white focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2">
</div>
<div class="relative pt-4">
<label for="name" class="text-base leading-7 text-blueGray-500">Input Text</label>
<input type="number" id="number" name="number" placeholder="number" class="w-full px-4 py-2 mt-2 mr-4 text-base text-black transition duration-500 ease-in-out transform rounded-lg bg-gray-100 focus:border-blueGray-500 focus:bg-white focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2">
</div>
<div class="relative pt-4">
<label for="name" class="text-base leading-7 text-blueGray-500">Input Date</label>
<input type="date" id="date" name="date" placeholder="name" class="w-full px-4 py-2 mt-2 mr-4 text-base text-black transition duration-500 ease-in-out transform rounded-lg bg-gray-100 focus:border-blueGray-500 focus:bg-white focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2">
</div>
<div class="relative pt-4">
<label for="name" class="text-base leading-7 text-blueGray-500">Input Color</label>
<input type="color" id="color" name="color" placeholder="name" class="w-full px-4 py-2 mt-2 mr-4 text-base text-black transition duration-500 ease-in-out transform rounded-lg bg-gray-100 focus:border-blueGray-500 focus:bg-white focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2">
</div>
<div class="relative pt-4">
<label for="name" class="text-base leading-7 text-blueGray-500">Input Range</label>
<input type="range" id="range" name="range" placeholder="name" class="w-full px-0 py-2 mt-2 mr-4 text-base text-black transition duration-500 ease-in-out transform rounded-lg bg-gray-100 focus:border-blueGray-500 focus:bg-white focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2">
</div>
<div class="relative mt-4">
<label for="name" class="text-base leading-7 text-blueGray-500">Component Select</label>
<select class="w-full px-4 py-2 mt-2 text-base text-black transition duration-500 ease-in-out transform rounded-lg bg-gray-100 focus:border-blueGray-500 focus:bg-white focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2">
<option>Surabaya</option>
<option>Bandung</option>
<option>jakarta</option>
</select>
</div>
<div class="flex flex-wrap mt-4 mb-6 -mx-3">
<div class="w-full px-3">
<label class="text-base leading-7 text-blueGray-500" for="description">Text Area </label>
<textarea class="w-full h-32 px-4 py-2 mt-2 text-base text-blueGray-500 transition duration-500 ease-in-out transform bg-white border rounded-lg focus:border-blue-500 focus:outline-none focus:shadow-outline focus:ring-2 ring-offset-current ring-offset-2 apearance-none autoexpand" id="description" type="text" name="description" placeholder="Message..." required=""></textarea>
</div>
</div>
<div class="flex">
<label class="flex items-center">
<input type="checkbox" class="form-checkbox ">
<span class="ml-2 text-blueGray-500">checkbox </span>
</label>
</div>
<div class="flex items-center w-full pt-4 mb-4">
<button class="w-full py-3 text-base text-white transition duration-500 ease-in-out transform bg-blue-600 border-blue-600 rounded-md focus:shadow-outline focus:outline-none focus:ring-2 ring-offset-current ring-offset-2 hover:bg-blue-800 "> Button </button>
</div>
<hr class="my-4 border-gray-200">
<span class="px-4 py-1 mx-auto -mt-8 text-xs text-black transition duration-500 ease-in-out transform bg-gray-200 rounded-lg">Or continue with </span>
<div class="inline-flex items-center justify-between w-full pt-8 ">
<button class="w-auto px-8 py-2 mr-2 text-base text-black transition duration-500 ease-in-out transform rounded-lg bg-gray-100 hover:bg-blueGray-200 focus:shadow-outline focus:outline-none focus:ring-2 ring-offset-current ring-offset-2 focus:border-blueGray-700 focus:bg-blueGray-800 ">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-github" width="20" height="20" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5"></path>
</svg>
</button>
<button class="w-auto px-8 py-2 mr-2 text-base text-black transition duration-500 ease-in-out transform rounded-lg bg-gray-100 hover:bg-blueGray-200 focus:shadow-outline focus:outline-none focus:ring-2 ring-offset-current ring-offset-2 focus:border-blueGray-700 focus:bg-blueGray-800 ">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-gitlab" width="20" height="20" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M21 14l-9 7l-9 -7l3 -11l3 7h6l3 -7z"></path>
</svg>
</button>
<button class="w-auto px-8 py-2 mr-2 text-base text-black transition duration-500 ease-in-out transform rounded-lg bg-gray-100 hover:bg-blueGray-200 focus:shadow-outline focus:outline-none focus:ring-2 ring-offset-current ring-offset-2 focus:border-blueGray-700 focus:bg-blueGray-800 ">
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-brand-twitter" width="20" height="20" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M22 4.01c-1 .49 -1.98 .689 -3 .99c-1.121 -1.265 -2.783 -1.335 -4.38 -.737s-2.643 2.06 -2.62 3.737v1c-3.245 .083 -6.135 -1.395 -8 -4c0 0 -4.182 7.433 4 11c-1.872 1.247 -3.739 2.088 -6 2c3.308 1.803 6.913 2.423 10.034 1.517c3.58 -1.04 6.522 -3.723 7.651 -7.742a13.84 13.84 0 0 0 .497 -3.753c-.002 -.249 1.51 -2.772 1.818 -4.013z"></path>
</svg>
</button>
</div>
</form>
</div>
How to make 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 make a form component
px-5
py-12
lg:px-20
flex
flex-col
w-full
p-10
px-8
pt-6
mx-auto
my-6
mb-4
bg-white
lg:w-1/2
h-full
p-1
overflow-auto
text-base
text-blueGray-500
mb-5
border-dashed
focus:border-blue-500
flex-wrap
mb-3
w-auto
px-2
py-1
my-2
mr-2
hover:text-blueGray-600
text-md
hover:bg-gray-100
relative
pt-4
px-4
py-2
mt-2
mr-4
text-black
bg-gray-100
focus:border-blueGray-500
focus:bg-white
px-0
mt-4
mb-6
-mx-3
px-3
h-32
ml-2
py-3
text-white
bg-blue-600
border-blue-600
hover:bg-blue-800
my-4
border-gray-200
-mt-8
text-xs
bg-gray-200
inline-flex
pt-8
hover:bg-blueGray-200
focus:border-blueGray-700
focus:bg-blueGray-800
64 steps to make a form component with Tailwind CSS
Control the horizontal padding of an element to 1.25rem using the
px-5
utilities.Control the vertical padding of an element to 3rem using the
py-12
utilities.Control the horizontal padding of an element to 5rem at only large screen sizes using the
lg:px-20
utilities.Use
flex
to create a block-level flex container.Use
flex
to create a block-level flex container.Use
w-full
to set an element to a 100% based width.Control the padding on all sides of an element to 2.5rem using the
p-10
utilities.Control the horizontal padding of an element to 2rem using the
px-8
utilities.Control the padding on top side of an element to 1.5rem using the
pt-6
utilities.Control the horizontal margin of an element to auto using the
mx-auto
utilities.Control the vertical margin of an element to 1.5rem using the
my-6
utilities.Control the margin on bottom side of an element to 1rem using the
mb-4
utilities.Control the background color of an element to white using the
bg-white
utilities.Use
lg:w-1/2
to set an element to a fixed width(1/2) at only large screen sizes.Use
h-full
to set an element’s height to 100% of its parent, as long as the parent has a defined height.Control the padding on all sides of an element to 0.25rem using the
p-1
utilities.Use
overflow-auto
to add scrollbars to an element in the event that its content overflows the bounds of that element. Unlike.overflow-scroll
, which always shows scrollbars, this utility will only show them if scrolling is necessary.Control the text color of an element to base using the
text-base
utilities.Control the text color of an element to blueGray-500 using the
text-blueGray-500
utilities.Control the margin on bottom side of an element to 1.25rem using the
mb-5
utilities.Control the border color of an element to dashed using the
border-dashed
utilities.Control the border color of an element to blue-500 using the
focus:border-blue-500
utilities on focus.Use
flex
to create a block-level flex container.Control the margin on bottom side of an element to 0.75rem using the
mb-3
utilities.The
w-auto
utility can be useful if you need to remove an element’s assigned width under a specific condition, like at a particular breakpoint.Control the horizontal padding of an element to 0.5rem using the
px-2
utilities.Control the vertical padding of an element to 0.25rem using the
py-1
utilities.Control the vertical margin of an element to 0.5rem using the
my-2
utilities.Control the margin on right side of an element to 0.5rem using the
mr-2
utilities.Control the text color of an element to blueGray-600 on hover using the
hover:text-blueGray-600
utilities.Control the text color of an element to md using the
text-md
utilities.Control the background color of an element to gray-100 using the
hover:bg-gray-100
utilities on hover.Use
relative
to position an element according to the normal flow of the document.Control the padding on top side of an element to 1rem using the
pt-4
utilities.Control the horizontal padding of an element to 1rem using the
px-4
utilities.Control the vertical padding of an element to 0.5rem using the
py-2
utilities.Control the margin on top side of an element to 0.5rem using the
mt-2
utilities.Control the margin on right side of an element to 1rem using the
mr-4
utilities.Control the text color of an element to black using the
text-black
utilities.Control the background color of an element to gray-100 using the
bg-gray-100
utilities.Control the border color of an element to blueGray-500 using the
focus:border-blueGray-500
utilities on focus.Control the background color of an element to white using the
focus:bg-white
utilities on focus.Control the horizontal padding of an element to 0rem using the
px-0
utilities.Control the margin on top side of an element to 1rem using the
mt-4
utilities.Control the margin on bottom side of an element to 1.5rem using the
mb-6
utilities.Control the horizontal margin of an element to -0.75rem using the
-mx-3
utilities.Control the horizontal padding of an element to 0.75rem using the
px-3
utilities.Use
h-32
to set an element to a fixed height(8rem).Control the margin on left side of an element to 0.5rem using the
ml-2
utilities.Control the vertical padding of an element to 0.75rem using the
py-3
utilities.Control the text color of an element to white using the
text-white
utilities.Control the background color of an element to blue-600 using the
bg-blue-600
utilities.Control the border color of an element to blue-600 using the
border-blue-600
utilities.Control the background color of an element to blue-800 using the
hover:bg-blue-800
utilities on hover.Control the vertical margin of an element to 1rem using the
my-4
utilities.Control the border color of an element to gray-200 using the
border-gray-200
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 xs using the
text-xs
utilities.Control the background color of an element to gray-200 using the
bg-gray-200
utilities.Use
inline-flex
to create an inline flex container that flows with text.Control the padding on top side of an element to 2rem using the
pt-8
utilities.Control the background color of an element to blueGray-200 using the
hover:bg-blueGray-200
utilities on hover.Control the border color of an element to blueGray-700 using the
focus:border-blueGray-700
utilities on focus.Control the background color of an element to blueGray-800 using the
focus:bg-blueGray-800
utilities on focus.
Conclusion
The above is a step-by-step tutorial on how to use Tailwind CSS to make a form components, learn and follow along to implement your own components.