Buttons should say what they do. A button inside a form defaults to submitting unless you set type explicitly, so type matters. We will keep the example small, so you can see how the fields work without building a whole application first.
What You Need to Know
Use type="submit" to send the form, type="reset" to restore initial values, and type="button" for behavior supplied separately. HTML alone does not implement an invented button action.
A form is like a question sheet. The label asks the question, the control holds the answer, and the name tells the receiving application what that answer is called.
Example: See It in Action
Take a look at this small piece of HTML. You can use it in a practice document and change the text to make it your own.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<form action="/save" method="post">
<button type="submit">Save changes</button>
<button type="reset">Reset fields</button>
<button type="button" id="show-help">Show help</button>
</form>
Let’s Understand the Example
- Button is a real keyboard-accessible control. Inside a form, specify type when you do not want the default submit action.
- Form groups controls that send named values to an endpoint when submitted.
- Action names the destination where the browser sends a form submission. A real server handler must exist there.
- Method controls how a form submits; GET makes values part of the URL, while POST sends them in the request body.
- Type changes the kind of input, script, resource or button, depending on the element.
- Id gives one element a unique name within the page, so a link, label, or script can point to it.
Try navigating between the form controls with Tab and activating the submit button. If an endpoint is missing, the browser cannot save the information by itself.
What Should You See?
You should see controls for one or more input fields. The example uses an input of type text and sends a POST request when submitted. If the action points to a missing server endpoint, the browser cannot complete the task.
Choose one field and predict its submitted name and value. Then change the value and check whether the browser accepts it. Do not assume that a working-looking form has a real server behind it.
Try It Yourself
- Explain which button in the example submits and which one needs JavaScript.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Adding a Help button without type and accidentally submitting the form.
- Client-side HTML validation is a helpful first check, not a security boundary. A real receiving application must validate the values again.
Key Takeaways
- Buttons should say what they do.
- Button is a real keyboard-accessible control. Inside a form, specify type when you do not want the default submit action.
- Use type="submit" to send the form, type="reset" to restore initial values, and type="button" for behavior supplied separately. HTML alone does not implement an invented button action.