HTML forms guide

This guide is a series of articles that will help you master HTML forms. HTML forms are a very powerful tool for interacting with users; however, for historical and technical reasons, it's not always obvious how to use them to their full potential. In this guide, we'll cover all aspects of HTML forms, from structure to styling, from data handling to custom widgets. You'll learn to enjoy the great power they offer!


  1. My first HTML form
  2. How to structure an HTML form
  3. The native form widgets
  4. CSS with HTML forms
    1. Styling HTML forms
    2. Advanced styling for HTML forms
    3. Property compatibility table for form widgets
  5. Sending and retrieving form data
  6. Data form validation
  7. How to build custom form widgets
  8. Sending forms through JavaScript
    1. Using the FormData object
  9. HTML forms in legacy browsers

HTML Documentation

HTML Elements

Element Related DOM interface Description
<button> (en-US) HTMLButtonElement (en-US) The button element represents a clickable button.
<datalist> (en-US) HTMLDataListElement (en-US) The datalist element contains a set of <option> (en-US) elements that represent the possible options for the value of other form elements.
<fieldset> (en-US) HTMLFieldSetElement (en-US) The fieldset is used to group several form elements within a form.
<form> (en-US) HTMLFormElement (en-US) The form element represents a section of document that contains interactive element that enables a user to submit information to a web server.
<input> (en-US) HTMLInputElement (en-US) The  input element is used to create interactive controls for forms.
<keygen> (en-US) HTMLKeygenElement (en-US) The keygen element exists to facilitate generation of key material, and submission of the public key as part of an HTML form
<label> (en-US) HTMLLabelElement (en-US) The label element represents a caption for an item in a user interface
<legend> (en-US) HTMLLegendElement (en-US) The legend element represents a caption for the content of its parent <fieldset> (en-US).
<meter> (en-US) HTMLMeterElement (en-US) The meter element  represents either a scalar value within a known range or a fractional value.
<optgroup> (en-US) HTMLOptGroupElement (en-US) the optgroup element creates a group of options within a <select> (en-US) element.
<option> (en-US) HTMLOptionElement (en-US) the HTML option element is used to create a control representing an item within a <select> (en-US), an <optgroup> (en-US) or a <datalist> (en-US) element.
<output> (en-US) HTMLOutputElement (en-US) The output element represents the result of a calculation.
<progress> (en-US) HTMLProgressElement (en-US) The progress element is used to view the completion progress of a task.
<select> (en-US) HTMLSelectElement (en-US) The select element represents a control that presents a menu of options.
<textarea> (en-US) HTMLTextAreaElement (en-US) The textarea element represents a multi-line plain-text editing control.

Note: All form elements, as all HTML elements, support the HTMLElement (en-US) DOM interface.

HTML Attributes

Attribute Name Elements Description
accept <form> (en-US), <input> (en-US) List of types the server accepts, typically a file type.
accept-charset <form> (en-US) List of supported charsets.
action <form> (en-US) The URI of a program that processes the information submitted via the form.
autocomplete <form> (en-US), <input> (en-US) Indicates whether controls in this form can by default have their values automatically completed by the browser.
autofocus <button> (en-US), <input> (en-US), <keygen> (en-US), <select> (en-US), <textarea> (en-US) The element should be automatically focused after the page loaded.
challenge <keygen> (en-US) A challenge string that is submitted along with the public key.
checked <input> (en-US) Indicates whether the element should be checked on page load.
cols <textarea> (en-US) Defines the number of columns in a textarea.
data <object> (en-US) Specifies the URL of the resource.
dirname <input> (en-US), <textarea> (en-US)  
disabled <button> (en-US), <fieldset> (en-US), <input> (en-US), <keygen> (en-US), <optgroup> (en-US), <option> (en-US), <select> (en-US), <textarea> (en-US) Indicates whether the user can interact with the element.
enctype <form> (en-US) Defines the content type of the form data when the method is POST.
for <label> (en-US), <output> (en-US) Describes elements which belong to this one.
form <button> (en-US), <fieldset> (en-US), <input> (en-US), <keygen> (en-US), <label> (en-US), <meter> (en-US), <object> (en-US), <output> (en-US), <progress> (en-US), <select> (en-US), <textarea> (en-US) Indicates the form that is the owner of the element.
high <meter> (en-US) Indicates the lower bound of the upper range.
keytype <keygen> (en-US) Specifies the type of key generated.
list <input> (en-US) Identifies a list of pre-defined options to suggest to the user.
low <meter> (en-US) Indicates the upper bound of the lower range.
max <input> (en-US), <meter> (en-US), <progress> (en-US) Indicates the maximum value allowed.
maxlength <input> (en-US), <textarea> (en-US) Defines the maximum number of characters allowed in the element.
method <form> (en-US) Defines which HTTP method to use when submitting the form. Can be GET (default) or POST.
min <input> (en-US), <meter> (en-US) Indicates the minimum value allowed.
multiple <input> (en-US), <select> (en-US) Indicates whether multiple values can be entered in an input of the type email or file.
name <button> (en-US), <form> (en-US), <fieldset> (en-US), <input> (en-US), <keygen> (en-US), <output> (en-US), <select> (en-US), <textarea> (en-US) Name of the element. For example used by the server to identify the fields in form submits.
novalidate <form> (en-US) This attribute indicates that the form shouldn't be validated when submitted.
optimum <meter> (en-US) Indicates the optimal numeric value.
pattern <input> (en-US) Defines a regular expression which the element's value will be validated against.
placeholder <input> (en-US), <textarea> (en-US) Provides a hint to the user of what can be entered in the field.
readonly <input> (en-US), <textarea> (en-US) Indicates whether the element can be edited or not.
required <input> (en-US), <select> (en-US), <textarea> (en-US) Indicates whether this element is required to fill out or not.
rows <textarea> (en-US) Defines the number of rows in a textarea.
selected <option> (en-US) Defines a value which will be selected on page load.
size <input> (en-US), <select> (en-US) Defines the width of the element (in pixels). If the element's type attribute is text or password then it's the number of characters.
src <img> (en-US) The URL of the embeddable content.
step <input> (en-US)  
target <form> (en-US)  
type <button> (en-US), <input> (en-US) Defines the type of the element.
usemap <img> (en-US)  
value <button> (en-US), <option> (en-US), <input> (en-US), <meter> (en-US), <progress> (en-US) Defines a default value which will be displayed in the element on page load.
wrap <textarea> (en-US) Indicates whether the text should be wrapped or not.

Normative reference