Create a Simple HTML Form with Name, Email, and Password Fields
Creating a form in HTML is one of the most essential skills for any web developer. Whether you're building a contact form, login form, or registration page, HTML forms are used to collect input from users.
In this guide, you'll learn how to create a basic HTML form with three common fields:
-
Name
-
Email
-
Password
Let’s get started step-by-step.
πΉ Step 1: Create the Basic HTML Structure
Before creating the form, we need a basic HTML page structure. This includes:
Explanation:
-
<!DOCTYPE html>
: Declares that this is an HTML5 document. -
Google Advertisement
<html>
: Root element that wraps all content. -
<head>
: Contains the title and other metadata. -
<title>
: Sets the title of the web page. -
<body>
: All visible content goes inside the body tag.
πΉ Step 2: Add the Form Tag
Now let’s insert a form element inside the <body>
:
Explanation:
-
<form>
: Starts the form. -
action="#"
: Where the form data will be sent. We’re using#
for now. -
method="post"
: Sends data securely (especially useful for passwords).
πΉ Step 3: Add Input Fields – Name, Email, Password
Now let’s add the three input fields and a submit button inside the form:
π Explanation of Each Part
β
<label for="name">Name:</label>
-
Google Advertisement
This is a text label for the name field.
-
The
for
attribute connects the label to theid
of the input field.
β
<input type="text" id="name" name="name">
-
type="text"
: Creates a text box for name input. -
id
andname
: Important for identifying the field. -
required
: Makes the field mandatory to fill.
β
<input type="email" id="email" name="email">
-
type="email"
: Ensures the user enters a proper email format. -
Browsers will show an error if the email format is incorrect.
β
<input type="password" id="password" name="password">
-
type="password"
: Hides the input by displaying dots or asterisks. -
Used for secure data like login passwords.
β
<input type="submit" value="Submit">
-
Creates a submit button.
-
Google Advertisement
Clicking this sends the data to the server (or does nothing in our example since
action="#"
).
π§ͺ Final Code – Copy and Paste
Here’s the full code with everything combined:
π Output Preview
When this code runs in a browser, you’ll see:
-
A heading: "Registration Form"
-
Fields: Name, Email, Password
-
A Submit button
Try entering values and hitting Submit — although the data won't go anywhere right now, the browser will check if all fields are filled.
π οΈ Tips for Beginners
-
Always use
label
tags — they improve accessibility. -
Use
required
to make sure users don’t skip fields. -
Use
type="email"
andtype="password"
to improve user experience and validation. -
Eventually, you can connect the form to a server with PHP, Node.js, or other languages.
π Conclusion
You’ve just learned how to create a basic HTML form with name, email, and password fields! This is the foundation of most login, registration, and contact pages. Once you're comfortable with forms, you can explore things like validation, styling with CSS, or processing with JavaScript.