How to create a Registration Form with Labels in HTML and CSS

Creating a registration form is an essential skill for any web developer. Forms allow users to input data and interact with websites, making them a fundamental part of user authentication, sign-ups, and data collection. A well-designed registration form improves user experience, enhances accessibility, and ensures a smooth data submission process.

In this tutorial, we will focus on building a registration form using HTML for structure and CSS for styling. We will also discuss best practices for creating user-friendly forms that are both visually appealing and functional.

Advertisement

A registration form serves as the gateway for users to sign up for a website or service. It plays a crucial role in collecting information such as names, email addresses, and passwords.

Step 1: Structuring the Registration Form with HTML

HTML provides the foundation for the registration form. A basic form consists of a <form> tag containing various input fields with corresponding <label> elements. Labels help users understand what information to enter, improving clarity and accessibility.

✲    index.html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="style.css">
  <title>Login Form | Coding Zemigle</title>
</head>
<body>
  <form action="/login" method="post">
    <div class="container">
      <h2>Registration Form</h2>
      <label for="name">Full Name</label>
      <input type="text" name="name" id="name" required>
      <label for="email">Email Address</label>
      <input type="email" name="email" id="email" required>
      <label for="phone">Phone Number</label>
      <input type="tel" name="phone" id="phone" required>
      <label for="password">Password</label>
      <input type="password" name="password" id="password" required>
      <label for="password">Confirm Password</label>
      <input type="password" name="password" id="confirm-password">
      <button type="submit">REGISTER</button>
      <div class="registration">Already have an account › <a href="#">Login</a></div>
    </div>
  </form>
</body>
</html>

Best Practices for HTML Structure:

Use <label> elements for each input field to improve usability and accessibility. Assign the for attribute in labels to match the corresponding input field’s id. Organize the form logically, grouping similar fields together. Include the required attribute for essential fields to prevent empty submissions.

Advertisement

Use <select> for dropdown options instead of text input where applicable. Provide clear placeholders for additional guidance but do not rely on them alone.

Step 2: Styling the Form with CSS

While HTML structures the form, CSS enhances its visual appearance and usability. A well-styled form improves readability, aligns elements properly, and makes interaction smooth.

✲    style.css
body{
  font-family: "Roboto", sans-serif;
  background: #225560;
  display: flex;
  justify-items: center;
  align-items: center;
  padding: 20px;
  height: 100%;
  margin: 0;
}

form {
    display: flex;
    flex-direction: column;
}

.container{
  background: #FFF;
  border-radius: 10px;
  padding: 10px 25px 40px 25px;
  width: 345px;
  position: absolute;
  top: 50%; /* adjust accordingly */
  left: 50%;
  transform: translate(-50%, -50%);
}

h2{
  text-align: center;
  font-size: 30px;
  margin-bottom: 40px;
}

label{
  display: block;
  margin-bottom: 10px;
}

input{
  padding: 15px;
  margin-bottom: 35px;
  font-size: 15px;
  width: 90%;
}

button{
  background: #225560;
  width: 100%;
  padding: 17px;
  border: none;
  margin-top: 10px;
  border-radius: 3px;
  font-size: 18px;
  color: #FFF;
  font-weight: 600;
  border: none;
  cursor: pointer;
}

.registration{
  text-align: center;
  margin-top: 30px;
}

.registration a{
  color: royalblue;
  text-decoration-line: none;
}

Best Practices for CSS Styling:

Consistent Layout: Ensure proper alignment of form elements to create a clean and structured layout.

Whitespace and Padding: Add spacing between elements to avoid a cluttered appearance.

Legible Font Styles: Use readable fonts with appropriate sizes for both labels and inputs.

Highlight Active Inputs: Apply focus styles (e.g., border color change) to indicate when a user is typing.

Button Styling: Design submit buttons with distinct colors and hover effects for better visibility.

Mobile Responsiveness: Ensure the form adapts well to different screen sizes for a seamless experience.

Accessibility Considerations:

Use high-contrast colors for text to ensure readability. Ensure labels and input fields have sufficient spacing. Provide clear error messages when a user enters invalid data. Optimize form elements for touch interaction on mobile devices.

Advertisement

Enhancing User Experience with Good Form Design

A well-structured and properly styled form significantly enhances user experience. Here are some additional tips:

1. Keep It Simple

Avoid excessive form fields. Only ask for necessary information to reduce friction during the registration process. Long forms can discourage users from completing sign-ups.

2. Use Descriptive Labels

Instead of generic labels like “Name,” use “Full Name” to clarify what is expected. Avoid using only placeholder text, as it disappears when users start typing.

3. Group Related Fields Together

Arrange fields logically, such as placing name and email fields at the top, followed by password creation, and finishing with agreement checkboxes.

4. Provide Real-Time Feedback

While we are not covering JavaScript validation in this tutorial, consider using CSS pseudo-classes like :valid and :invalid to provide basic validation styling. This can visually indicate errors before form submission.

5. Make the Submit Button Stand Out

Ensure the submit button is prominent by using a distinct color and larger size. A well-designed button encourages users to complete the form.

6. Optimize for Mobile Devices

Many users will fill out the form on their smartphones. Ensure inputs are large enough for touch interactions and that the form scales properly on smaller screens.

Creating a registration form with clear labels using HTML and CSS is a fundamental web development skill. By structuring the form correctly and applying effective styling, you can ensure a seamless and visually appealing user experience.

To further enhance your form, consider adding validation, server-side processing, and additional styling for error messages. With these improvements, you can create a professional and user-friendly registration process.