**`<form>`** groups related input controls and defines how their values get submitted: **`action`** is the URL the data is sent to, and **`method`** is either `get` (appends data to the URL, visible and bookmarkable, only for non-sensitive reads) or `post` (sends data in the request body, used for anything that changes data or includes sensitive info like passwords). Pressing Enter in a text field, or clicking a `type="submit"` button inside the form, both trigger submission.
1Understanding <form>
`<form>` groups related input controls and defines how their values get submitted: `action` is the URL the data is sent to, and `method` is either get (appends data to the URL, visible and bookmarkable, only for non-sensitive reads) or post (sends data in the request body, used for anything that changes data or includes sensitive info like passwords). Pressing Enter in a text field, or clicking a type="submit" button inside the form, both trigger submission.
Never use method="get" for a form containing a password or other sensitive field — GET puts the values directly in the URL, which can end up logged in browser history, server logs, or shared links.
<form action="/login" method="post">
<input type="email" name="email" required>
<input type="password" name="password" required>
<button type="submit">Log In</button>
</form>2Practical Example
Here is a real-world application of <form> showing how it is used in production HTML.
<!-- Intercepting submission with JavaScript instead of a full page reload -->
<form id="searchForm">
<input type="search" name="q">
</form>
<script>
document.getElementById('searchForm').addEventListener('submit', (e) => {
e.preventDefault();
console.log('Search submitted without reloading the page');
});
</script>3Best Practices
Follow these guidelines when working with <form>:
1. Use method="post" for anything that creates/changes data or includes sensitive fields
2. Use method="get" only for simple, non-sensitive searches/filters where a bookmarkable URL is useful
3. Give every form control a name attribute — unnamed fields aren't included in the submitted data
Tip: Never use method="get" for a form containing a password or other sensitive field — GET puts the values directly in the URL, which can end up logged in browser history, server logs, or shared links.
<form action="/login" method="post">
<input type="email" name="email" required>
<input type="password" name="password" required>
<button type="submit">Log In</button>
</form>