How I Built a Sleek Profile Update Form with Tailwind CSS

As a full-stack web developer, I always strive to create forms that are both visually appealing and functional. Recently, I needed to build a user profile update form, and I decided to use Tailwind CSS for the task. Why Tailwind? It’s lightweight, flexible, and allows me to quickly design modern, responsive components. In this article, I’m going to walk you through how I created a profile update form from scratch, using my personal approach and experience with Tailwind CSS.
The goal was to design a simple, intuitive form that would look great on both desktop and mobile devices, as well as seamlessly switch between light and dark modes. After some consideration, I opted to build a form that would allow users to update their full name, email address, phone number, and home address, as those are common details users typically need to modify in their profile settings.
Why Tailwind CSS?
If you’ve used Tailwind before, you already know that it’s a game-changer. It enables me to apply styling directly in HTML with utility classes, removing the need to write custom CSS. The flexibility of Tailwind CSS makes it perfect for rapidly prototyping and customizing components. And let’s not forget the dark mode support—it’s incredibly easy to implement, and it was an essential feature for this form since many users prefer dark mode these days.
Creating the Container
First, I began by building the container for the form. I wanted a clean, modern look, so I went with a rounded container with shadows and a slight border for a touch of elegance. Additionally, I wanted it to be centered on the page. Tailwind’s grid and flex utilities made that a breeze.
The following code is what I came up with for the container:
<div class="mx-auto mt-10 max-w-md rounded-xl bg-white p-6 shadow-lg ring-1 ring-gray-200 dark:bg-gray-800 dark:ring-gray-700">
<h2 class="mb-4 flex items-center gap-2 text-xl font-semibold text-gray-800 dark:text-gray-100">
<svg class="h-5 w-5 text-blue-600 dark:text-blue-400" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" d="M5.121 17.804A3 3 0 017 17h10a3 3 0 012.879 2.121M15 11a3 3 0 11-6 0 3 3 0 016 0z" />
</svg>
Update Profile
</h2>
<form class="space-y-3 text-sm">
<div class="grid grid-cols-1 gap-2">
<label class="font-medium text-gray-700 dark:text-gray-300" for="name">Full Name</label>
<input type="text" id="name" name="name" placeholder="John Doe" class="rounded-lg border border-gray-300 bg-white px-3 py-2 text-gray-800 focus:ring-2 focus:ring-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100" />
</div>
<div class="grid grid-cols-1 gap-2">
<label class="font-medium text-gray-700 dark:text-gray-300" for="email">Email</label>
<input type="email" id="email" name="email" placeholder="you@example.com" class="rounded-lg border border-gray-300 bg-white px-3 py-2 text-gray-800 focus:ring-2 focus:ring-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100" />
</div>
<div class="grid grid-cols-1 gap-2">
<label class="font-medium text-gray-700 dark:text-gray-300" for="phone">Phone</label>
<input type="tel" id="phone" name="phone" placeholder="+1234567890" class="rounded-lg border border-gray-300 bg-white px-3 py-2 text-gray-800 focus:ring-2 focus:ring-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100" />
</div>
<div class="grid grid-cols-1 gap-2">
<label class="font-medium text-gray-700 dark:text-gray-300" for="address">Address</label>
<textarea id="address" name="address" rows="2" placeholder="Your address here..." class="rounded-lg border border-gray-300 bg-white px-3 py-2 text-gray-800 focus:ring-2 focus:ring-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100"></textarea>
</div>
<button type="submit" class="w-full rounded-lg bg-blue-600 py-2 font-medium text-white transition duration-200 hover:bg-blue-700">
Save Changes
</button>
</form>
</div>
For the container, I used the max-w-md
class to ensure it’s not too wide. The rounded-xl
class rounded the corners, and the shadow-lg
added a subtle depth effect. The ring-1
and ring-gray-200
classes provided a faint border around the form. To make it suitable for dark mode, I used the dark:bg-gray-800
and dark:ring-gray-700
classes to change the background color and ring color in dark mode.
Adding the Input Fields
Next, I created the input fields for Full Name, Email, Phone, and Address. Each input field has a consistent design, with rounded corners and a border to ensure a cohesive look. I used the focus:ring-2
class to add a blue outline when the user interacts with any of the inputs. This effect not only enhances the user experience but also helps users focus on the input field they are currently editing.
Here is a closer look at how I styled the Full Name input field:
<div class="grid grid-cols-1 gap-2">
<label class="font-medium text-gray-700 dark:text-gray-300" for="name">Full Name</label>
<input type="text" id="name" name="name" placeholder="John Doe" class="rounded-lg border border-gray-300 bg-white px-3 py-2 text-gray-800 focus:ring-2 focus:ring-blue-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-gray-100" />
</div>
For each input, I made sure to add some padding inside, which was achieved using the px-3
and py-2
classes. This gives the form a bit of breathing room and makes it easier for users to interact with.
The Submit Button
The submit button is one of the most critical elements of the form. I wanted it to stand out while still maintaining a clean look. So, I went with a blue button that changes shade when hovered over. The bg-blue-600
class gave it a vibrant blue color, while the hover:bg-blue-700
class darkens the color on hover, creating a nice interactive effect. Additionally, I made sure the button spanned the full width of the form with w-full
to ensure it looks balanced.
<button type="submit" class="w-full rounded-lg bg-blue-600 py-2 font-medium text-white transition duration-200 hover:bg-blue-700">
Save Changes
</button>
Dark Mode Integration
One of the coolest features of Tailwind is the ability to create a dark mode version of your design with minimal effort. By simply prefixing classes with dark:
, I was able to make sure that the form adapts beautifully in both light and dark modes. All of the background colors, text colors, and borders switch automatically depending on the system’s theme.
Final Thoughts
Overall, this project was a great way to showcase how Tailwind CSS can make building a profile update form simple, yet elegant. The form is fully responsive, adapts seamlessly to light and dark modes, and is incredibly easy to customize further if necessary. What I like most about using Tailwind is that I don’t have to fight with pre-set styles—everything I need is at my fingertips, and I can tweak it on the fly.
If you haven’t tried Tailwind CSS yet, I highly recommend giving it a go for your next web development project. It’ll make your life easier, and your users will appreciate the clean, responsive design.
Thanks for reading, and happy coding!
Subscribe to my newsletter
Read articles from Sharukhan Patan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
