Published on

3 Things You Must Know To Make A Responsive Contact Form With Tailwind CSS

Responsive Contact 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 Responsive Contact Form ui component

Responsive contact form

Why use Tailwind CSS to build a Responsive Contact Form ui component?

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

The preview of Responsive Contact Form ui component

Free download of the Responsive Contact Form's source code

The source code of Responsive Contact Form ui component

<div class="flex justify-center items-center w-screen h-screen bg-white">
	<!-- COMPONENT CODE -->
	<div class="container mx-auto my-4 px-4 lg:px-20">

		<div class="w-full p-8 my-4 md:px-12 lg:w-9/12 lg:pl-20 lg:pr-40 mr-auto rounded-2xl shadow-2xl">
			<div class="flex">
				<h1 class="font-bold uppercase text-5xl">Send us a <br /> message</h1>
			</div>
			<div class="grid grid-cols-1 gap-5 md:grid-cols-2 mt-5">
				<input class="w-full bg-gray-100 text-gray-900 mt-2 p-3 rounded-lg focus:outline-none focus:shadow-outline"
            type="text" placeholder="First Name*" />
				<input class="w-full bg-gray-100 text-gray-900 mt-2 p-3 rounded-lg focus:outline-none focus:shadow-outline"
            type="text" placeholder="Last Name*" />
				<input class="w-full bg-gray-100 text-gray-900 mt-2 p-3 rounded-lg focus:outline-none focus:shadow-outline"
            type="email" placeholder="Email*" />
				<input class="w-full bg-gray-100 text-gray-900 mt-2 p-3 rounded-lg focus:outline-none focus:shadow-outline"
            type="number" placeholder="Phone*" />
        </div>
				<div class="my-4">
					<textarea placeholder="Message*" class="w-full h-32 bg-gray-100 text-gray-900 mt-2 p-3 rounded-lg focus:outline-none focus:shadow-outline"></textarea>
				</div>
				<div class="my-2 w-1/2 lg:w-1/4">
					<button class="uppercase text-sm font-bold tracking-wide bg-blue-900 text-gray-100 p-3 rounded-lg w-full 
                      focus:outline-none focus:shadow-outline">
            Send Message
          </button>
				</div>
			</div>

			<div
				class="w-full lg:-mt-96 lg:w-2/6 px-8 py-12 ml-auto bg-blue-900 rounded-2xl">
				<div class="flex flex-col text-white">
					<h1 class="font-bold uppercase text-4xl my-4">Drop in our office</h1>
					<p class="text-gray-400">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam
						tincidunt arcu diam,
						eu feugiat felis fermentum id. Curabitur vitae nibh viverra, auctor turpis sed, scelerisque ex.
					</p>

					<div class="flex my-4 w-2/3 lg:w-1/2">
						<div class="flex flex-col">
							<i class="fas fa-map-marker-alt pt-2 pr-2" />
            </div>
            <div class="flex flex-col">
              <h2 class="text-2xl">Main Office</h2>
              <p class="text-gray-400">5555 Tailwind RD, Pleasant Grove, UT 73533</p>
            </div>
          </div>
          
          <div class="flex my-4 w-2/3 lg:w-1/2">
            <div class="flex flex-col">
              <i class="fas fa-phone-alt pt-2 pr-2" />
            </div>
            <div class="flex flex-col">
              <h2 class="text-2xl">Call Us</h2>
              <p class="text-gray-400">Tel: xxx-xxx-xxx</p>
              <p class="text-gray-400">Fax: xxx-xxx-xxx</p>
            </div>
          </div>
          
          <div class="flex my-4 w-2/3 lg:w-1/2">
            <a href="https://www.facebook.com/ENLIGHTENEERING/" target="_blank" rel="noreferrer" class="rounded-full bg-white h-8 w-8 inline-block mx-1 text-center pt-1">
              <i class="fab fa-facebook-f text-blue-900" />
            </a>
            <a href="https://www.linkedin.com/company/enlighteneering-inc-" target="_blank" rel="noreferrer" class="rounded-full bg-white h-8 w-8 inline-block mx-1 text-center pt-1">
              <i class="fab fa-linkedin-in text-blue-900" />
            </a>
          </div>
        </div>
      </div>
    </div>
    <!-- COMPONENT CODE -->
</div>

<!-- BUY ME A PIZZA AND HELP SUPPORT OPEN-SOURCE RESOURCES -->
<div class="flex items-end justify-end fixed bottom-0 right-0 mb-4 mr-4 z-10">
  <div>
    <a title="Buy me a pizza" href="https://www.buymeacoffee.com/Dekartmc" target="_blank" class="block w-16 h-16 rounded-full transition-all shadow hover:shadow-lg transform hover:scale-110 hover:rotate-12">
      <img class="object-cover object-center w-full h-full rounded-full" src="https://img.icons8.com/emoji/48/000000/pizza-emoji.png"/>
    </a>
  </div>
</div>

How to build a Responsive Contact 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 build a Responsive Contact Form component

  • flex
  • w-screen
  • h-screen
  • bg-white
  • mx-auto
  • my-4
  • px-4
  • lg:px-20
  • w-full
  • p-8
  • md:px-12
  • lg:w-9/12
  • lg:pl-20
  • lg:pr-40
  • mr-auto
  • text-5xl
  • grid
  • grid-cols-1
  • gap-5
  • md:grid-cols-2
  • mt-5
  • bg-gray-100
  • text-gray-900
  • mt-2
  • p-3
  • h-32
  • my-2
  • w-1/2
  • lg:w-1/4
  • text-sm
  • bg-blue-900
  • text-gray-100
  • lg:-mt-96
  • lg:w-2/6
  • px-8
  • py-12
  • ml-auto
  • flex-col
  • text-white
  • text-4xl
  • text-gray-400
  • w-2/3
  • lg:w-1/2
  • pt-2
  • pr-2
  • text-2xl
  • h-8
  • w-8
  • inline-block
  • mx-1
  • text-center
  • pt-1
  • text-blue-900
  • fixed
  • bottom-0
  • right-0
  • mb-4
  • mr-4
  • z-10
  • block
  • w-16
  • h-16
  • h-full

63 steps to build a Responsive Contact Form component with Tailwind CSS

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

  2. Use w-screen to make an element span the entire width of the viewport.

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

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

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

  6. Control the vertical margin of an element to 1rem using the my-4 utilities.

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

  8. Control the horizontal padding of an element to 5rem at only large screen sizes using the lg:px-20 utilities.

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

  10. Control the padding on all sides of an element to 2rem using the p-8 utilities.

  11. Control the horizontal padding of an element to 3rem at only medium screen sizes using the md:px-12 utilities.

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

  13. Set the left padding of an element to 5rem at only large screen sizes using the lg:pl-20 utilities class

  14. Control the padding on right side of an element to 10rem at only large screen sizes using the lg:pr-40 utilities.

  15. Control the margin on right side of an element to auto using the mr-auto utilities.

  16. Control the text color of an element to 5xl using the text-5xl utilities.

  17. Use grid to create a grid container.

  18. Use grid to create a grid container.

  19. To specify the width between columns, you can use the gap-5 utilities.

  20. Use grid to create a grid container at only medium screen sizes.

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

  22. Control the background color of an element to gray-100 using the bg-gray-100 utilities.

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

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

  25. Control the padding on all sides of an element to 0.75rem using the p-3 utilities.

  26. Use h-32 to set an element to a fixed height(8rem).

  27. Control the vertical margin of an element to 0.5rem using the my-2 utilities.

  28. Use w-1/2 to set an element to a fixed width(1/2).

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

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

  31. Control the background color of an element to blue-900 using the bg-blue-900 utilities.

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

  33. Control the margin on top side of an element to -24rem at only large screen sizes using the lg:-mt-96 utilities.

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

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

  36. Control the vertical padding of an element to 3rem using the py-12 utilities.

  37. Control the margin on left side of an element to auto using the ml-auto utilities.

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

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

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

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

  42. Use w-2/3 to set an element to a fixed width(2/3).

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

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

  45. Control the padding on right side of an element to 0.5rem using the pr-2 utilities.

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

  47. Use h-8 to set an element to a fixed height(2rem).

  48. Use w-8 to set an element to a fixed width(2rem).

  49. Use inline-block utilities to wrap the element to prevent the text inside from extending beyond its parent.

  50. Control the horizontal margin of an element to 0.25rem using the mx-1 utilities.

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

  52. Control the padding on top side of an element to 0.25rem using the pt-1 utilities.

  53. Control the text color of an element to blue-900 using the text-blue-900 utilities.

  54. Use fixed to position an element relative to the browser window.

  55. Use the bottom-0 utilities to set the bottom position of a positioned element to 0rem.

  56. Use the right-0 utilities to set the right position of a positioned element to 0rem.

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

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

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

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

  61. Use w-16 to set an element to a fixed width(4rem).

  62. Use h-16 to set an element to a fixed height(4rem).

  63. Use h-full to set an element’s height to 100% of its parent, as long as the parent has a defined height.

Conclusion

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