HTML Forms Best Practices
HTML Forms Best Practices
HTML Forms Best Practices
_georgemoller
1 4 H T M L
F O R M S
B E S T
PRACTICES
01
George Moller
_georgemoller
<form>
Email
<input>
Password <label>
SIGN UP <button>
02 Always use a <form> element.
Why?
If you have more than one page component for user input,
make sure to put each in its own <form> element
03
George Moller
_georgemoller
type=”email” type=”tel”
05
George Moller
_georgemoller
Add an asterisk to the label for every required field, and add a note at the
start of the form to explain what the asterisk means.
Full name *
When a form is submitted modern browsers
e.g. John Doe automatically prompt and set focus on required
fields with missing data, and you can use the
:required pseudo-class to highlight required
fields. No JavaScript required!
06 Help users enter the right data
George Moller
_georgemoller
Year of birth:
1800
07
George Moller
_georgemoller
<input enterkeyhint=” next ” /> Takes the user to the next field that accepts text
<input enterkeyhint=” prev ” /> Takes the user to the previous field that accepts text
<input enterkeyhint=” search ” /> Takes the user to the results of searching for the text
they have typed
<input enterkeyhint=” done ” /> Last input on the form
08
George Moller
_georgemoller
_georgemoller
Don’t have two separate fields for the name (like first name, last name).
Don’t add a separate input for a prefix or title (like Mrs, Dr or Lord)
Full name *
options to fill in the field, in this case only name related options
10
George Moller
_georgemoller
Do disable a submit button once the user has tapped or clicked it.
Give each form submit button a value that says what it does.
e.g.
Label the submit button on your delivery address form ‘Proceed to Payment’
rather than ‘Continue’ or ‘Save’.
12
George Moller
_georgemoller
For entering a URL. It must start with a For entering email addresses, and hints
valid URI scheme, for example http://, that the @ should be shown on the
ftp:// or mailto:. keyboard by default.
14
George Moller
_georgemoller
To use a label, in cases you can’t use a label, add it anyways and hide it with CSS.
To include any instructions with specific fields using aria-describedby.