4.html-forms.md
Quiz
~/ hackweb.dev
...
~/
/tutorials
/en/html/html-forms/edit
~ Contribute
Suggest a correction or improvement. The author reviews it before it goes live.
Loading...
en/tutorials/html/4html-forms
# HTML Forms Forms collect user input. A well-built form pairs every input with a label and lets the browser handle validation. ## Form basics The `<form>` element wraps all the fields. `action` and `method` describe where the data goes. ```html <form action="/signup" method="post"> <!-- fields go here --> </form> ``` ## Inputs Different `type` values change behavior and validation automatically. ```html <input type="text" name="username" placeholder="pick a name" /> <input type="email" name="email" placeholder="you@example.com" /> <input type="password" name="password" /> ``` ## Labels Every input should have a `<label>` — it makes the field clickable and announces it to screen readers. ```html <label for="email">Email</label> <input type="email" id="email" name="email" /> ``` ## Buttons A `<button type="submit">` submits the form. `type="button"` does nothing by default — use it for JavaScript. ```html <button type="submit">Create account</button> ``` ## Validation The browser can validate for free with `required`, `minlength`, and type-specific rules. ```html <input type="email" name="email" required /> <input type="password" name="password" minlength="8" /> ```
Submit suggestion
cancel