How to Make an HTML Form with a Submit Button
A <form> with a text box and a <button type="submit"> is all it takes to collect something from the people who visit a page. When they click the button, the browser sends each field's name and value, by default by adding them to the page's address.
Syntax
<form action="<address>">
<input name="<field name>">
<button type="submit"><button text></button>
</form>
| Part | What it does |
|---|---|
<form> | Holds the fields that are sent together. |
action="<address>" | Where the form is sent. Leave it out and the form is sent to the page it's on. |
<input name="<field name>"> | A text box. Its name is the name its value is sent under. |
<button type="submit"> | The button that sends the form. |
<button text> | The text on the button. |
MDN's form page lists all the form's attributes.
The Example
The example page asks for a name, with a text box and a Send button. When you send it, the name appears in the page's address.
Step 1: Write the Code
Create a file named index.html in a text editor, such as Visual Studio Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Form</title>
</head>
<body>
<form>
<label for="name">Name</label>
<input id="name" name="name">
<button type="submit">Send</button>
</form>
</body>
</html>
The label is the text box's caption: its for attribute names the text box's id. The text box's name="name" is what the browser sends with the value.
Step 2: Type a Name
Double-click index.html to open it in your browser, then type Ana into the text box:

The screenshot comes from Chromium 159, the open-source browser that Chrome is built on.
Step 3: Send the Form
Click Send. The page loads again with an empty text box, and the address in the address bar now ends with index.html?name=Ana.
What Happened
- The browser sent the form to the same page, because the form has no
action. - It added
?name=Anato the address: the text box'sname, an equals sign, and what you typed. A form sends its data this way unless it says otherwise. - The text box is empty again, because the browser loaded the page anew, at the new address.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Leaving out name on a field | The value isn't sent: with no name on the text box, the address ended with just a ? | Give every field you want sent a name |
Expecting id to be sent | Only name is sent: the text box above still had its id, and nothing was sent | Use id for the label, and name for the data |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
The address ends with only ? | The fields have no name | Add name to each field |
| The typed text is gone after sending | That's expected: the browser loaded the page again | Read the values from the address, or send the form to another page |
FAQ
Does pressing Enter send the form?
Yes. Typing Ben in the text box and pressing Enter sent the form just like the button did: the address ended with ?name=Ben.
How do I send the form to another page?
Set action. With <form action="thanks.html">, clicking Send opened thanks.html?name=Ana.
What happens to the data after that?
Nothing, unless something reads it. An HTML page can't store data on its own: a program on a web server, or a script in the page, reads the values from the address and does something with them.
Conclusion
A form, a field with a name and a submit button are enough to send data. Without an action, the form is sent to the same page, with each name=value pair added to the address.
Additional Resources
- form: The Form element, on MDN.
- Sending form data, on MDN.
