How to Build a Basic HTML Form with Input Fields Step-by-Step

May 9, 2025

Follow us on


Learn how to create a simple HTML form with name, email, and password fields. This beginner-friendly guide explains everything step by step with clear code examples.

📝 Create a Simple HTML Form with Name, Email, and Password Fields

Forms are an essential part of web development. Whether you're collecting user information, signing up users, or handling contact details, HTML forms are the building blocks.

In this guide, we’ll create a simple HTML form with three fields:

  • Name

  • Email

  • Password

Let’s break it down step-by-step in easy words so that even a beginner can understand.


🔧 Step 1: Basic Structure of an HTML Page

Before we create a form, we need to set up a basic HTML page.

<!DOCTYPE html>
<html>
<head>
    <title>Simple HTML Form</title>
</head>
<body>

    <!-- Our form will go here -->

</body>
</html>

📝 Explanation:

  • <!DOCTYPE html>: Declares this file as an HTML5 document.

  • <html>: The root element of the HTML document.

  • <head>: Contains metadata like the page title.

  • <body>: Everything visible on the webpage goes inside the body.


🧾 Step 2: Create the Form Tag

Now let’s add the form inside the <body>.

<form action="#" method="post">
    <!-- Form elements will go here -->
</form>

📝 Explanation:

  • <form>: This tag starts the form.

  • action="#": This is where the form data will be sent. For now, # means we are not sending it anywhere.

  • method="post": This tells the browser to send the form data securely (commonly used for login, signup, etc.).


✏️ Step 3: Add the Name Field

<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br><br>
 

📝 Explanation:

  • <label>: Defines a label for the input field. The for="name" connects it with the input having id="name".

  • <input type="text">: Creates a text input for the name.

  • required: This makes the field mandatory (form won’t submit if it’s empty).


📧 Step 4: Add the Email Field

<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>

📝 Explanation:

  • type="email": Special input type that ensures the entered value is a valid email address.

  • required: Makes this field mandatory.


🔐 Step 5: Add the Password Field

<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
 

📝 Explanation:

  • type="password": Masks the characters typed, for privacy.

  • Useful for login or signup forms.

  • required: Field must be filled to submit.


▶️ Step 6: Add a Submit Button

<input type="submit" value="Submit">
 

📝 Explanation:

  • type="submit": Creates a button that sends the form data.

  • value="Submit": The text shown on the button.


Final Complete Code

Here’s the full HTML form code:

<!DOCTYPE html>
<html>
<head>
    <title>Simple HTML Form</title>
</head>
<body>

    <h2>Registration Form</h2>
    
    <form action="#" method="post">
        <label for="name">Name:</label>
        <input type="text" id="name" name="name" required><br><br>

        <label for="email">Email:</label>
        <input type="email" id="email" name="email" required><br><br>

        <label for="password">Password:</label>
        <input type="password" id="password" name="password" required><br><br>

        <input type="submit" value="Submit">
    </form>

</body>
</html>

 


💡 Extra Tips for Beginners

  • Always use labels for better accessibility.

  • Use type="email" and type="password" for proper validation and security.

  • Use required to ensure fields are not left empty.


© 2025 TtimesNow. All rights reserved.