HTML Tags: Forms
These are the HTML tags you use to make forms and their content.
| Tag | Type | Description |
|---|---|---|
<form> | Block | Represents a form |
| Input/output | ||
<label> | Inline | Represents the caption of a form field |
<input> | Inline | Creates an interactive input field |
<output> | Inline | Creates an output container |
<select> | Inline | Creates a dropdown selection |
<optgroup> | Other | Represents a group of <option> in <select> |
<option> | Other | Represents an option inside <select> |
<button> | Inline | Creates a button. |
<textarea> | Inline | Creates a multiline textbox. |
<meter> | Inline | Creates a meter |
<progress> | Inline | Creates a progress bar |
<datalist> | Other | Contains a set of <option> elements that represents permissible/recommended options for a field |
| Fieldset | ||
<fieldset> | Block | Groups fields together |
<legend> | Block | Represents the caption of a <fieldset> |
<form>
Represents a form.
Attributes related to submissionaction=[...]— the URL to which the form is submitted (which URL performs some action on the form data)method=[...]— the HTTP method with which the form is submitted; specify eitherpostorgetenctype=[...]— ifmethod="post", this specifies the MIME type of the form submission. Can be:application/x-www-form-urlencoded(the default value)multipart/form-data(use if there is any<input type="file">)
novalidate— don't validate form before being submittedtarget=[...]— where to display the response (read here)
accept-charset=[...]— space-separated character encodings the server accepts, e.g.utf-8autocomplete=[...]— indicates whether input fields can be autocompleted by the browser; specify eitheronoroffname=[...]— name of the form (must be unique)rel=[...]— read here
<label>
Represents the caption of a form field.
It's not a normal text — if you click on a label, the associated form field will receive focus.
Possible attributesfor=[...]—idof a form item to be associated with.
<input>
Creates an interactive input field.
Common attributes (apply to most, if not all)name=[...]— name of this inputvalue=[...]— value of this inputtype=[...]— type of this input, read next sectionautofocus— sets focus on input when the page has finished loadingdisabled— disables input (the user cannot interact with it)readonly— makes the user unable to change this input's valuerequired— forces the user to specify this input's value before submitting the formautocomplete=[...]— hints if the browser can autofill this input; specify eitheronoroffform=[...]—idof a<form id="...">this element is associated with (read here)list=[...]—idof a<datalist id="...">this element is associated with
type values| Type | Description | Preview of <input type="..."> |
|---|---|---|
text | Single-line text input (default) Additional attributes
| |
password | Password input Additional attributes
| |
url | Like
| |
email | Like
| |
tel | Like
| |
search | Like
| |
checkbox | Checkbox input Additional attributes
| |
radio | Radio input (only one radio input with the same
| |
color | Color selector | |
number | Number selector Additional attributes
| |
range | Range selector Additional attributes
| |
file | File selector Additional attributes
| |
date | Date selector | |
time | Time selector | |
datetime-local | Date and time selector | |
month | Month and year selector | |
week | Week and year selector | |
button | Renders a button (use of | |
reset | Renders a reset button (resets the form to its default values) | |
submit | Renders a submit button Additional attributes
| |
image | Renders a graphical submit button Additional attributes
| |
hidden | Renders a hidden input (the control is not displayed to the user, but the value will still be sent on submission) |
<output>
Creates an output container. Its value/content is not submitted during form submission.
Does nothing by itself; you will need to implement the behavior using JavaScript.
Common attributes (apply to most, if not all)name=[...]— name of this outputfor=[...]— space-separatedid's of<input id="...">elements that contribute to the outputform=[...]— read here
<select>
Creates a dropdown selection.
Possible attributesname=[...]— name of this inputautofocus— sets focus on input when the page has finished loadingdisabled— disables input (the user cannot interact with it)required— forces the user to specify this input's value before submitting the formautocomplete=[...]— hints if the browser can autofill this input; specify eitheronoroffform=[...]—idof a<form id="...">this element is associated with (read here)multiple— allows selecting multiple valuessize=[...]— ifmultipleis specified, controls how many options in the scrolling list box are visible at one time
<optgroup>
Represents grouped options in <select>.
label=[...]— label of this groupdisabled— disables all options in this group
<option>
Represents an option inside <select> or <datalist>.
value=[...]— value of the option (to be sent if the option is selected). If omitted, the value is taken from the tag's content.label=[...]— label of the option (the one displayed to the user). If omitted, the value is taken from the tag's content.disabled— makes option unselectableselected— makes option selected by default
<button>
Creates a button.
Common attributestype=[...]— type of the button. Can be:submit(default: behaves like<input type="submit">)reset(behaves like<input type="reset">)button(behaves like normal button)
name=[...]— iftype="submit", this is name of the button when the form is submitted using this buttonvalue=[...]— iftype="submit", this is value of the button when the form is submitted using this buttonautofocus— sets focus on button when the page has finished loadingdisabled— disables button (the user cannot interact with it)
form=[...]—idof a<form id="...">this element is associated with (read here)formaction=[...]— overrides<form action="...">formmethod=[...]— overrides<form method="...">formenctype=[...]— overrides<form enctype="...">formnovalidate— overrides<form novalidate>formtarget=[...]— overrides<form target="...">
<textarea>
Creates a multiline textbox.
Common attributesname=[...]— name of this inputplaceholder=[...]— hint text to show when input is emptycols=[...]— width of input in character widthrows=[...]— height of input in linesdisabled— disables input (the user cannot interact with it)readonly— makes the user unable to change this input's value
autofocus— sets focus on input when the page has finished loadingautocomplete=[...]— hints if the browser can autofill this input; specify eitheronoroffspellcheck=[...]— controls spellcheck; specify eitheron,off, ordefaultwrap=[...]— controls line wrap. For both values, the browser ensures all line breaks consist of CR+LF pair. Can be:hard(insert line breaks for lines exceedingcols)soft(do not insert additional line breaks)
form=[...]—idof a<form id="...">this element is associated with (read here)
required— forces the user to specify this input's value before submitting the formminlength— minimum number of charactersmaxlength— maximum number of characters
<meter>
Creates a meter.
Possible attributesvalue— current meter valuemin— minimum valuemax— maximum valuelow— threshold to indicate low meter valuehigh— threshold to indicate low meter valueoptimum— optimum meter valueform=[...]—idof a<form id="...">this element is associated with (read here)
<progress>
Creates a progress bar.
Possible attributesvalue— current progres bar valuemax— maximum progress bar value
<datalist>
Contains a set of <option> elements that represents permissible/recommended options for a field.
You refer to this element by giving this element's id in <input list="...">.
<fieldset> and <legend>
<fieldset> groups fields together.
<legend> represents the caption of a <fieldset>.
References
- HTML elements reference (MDN) — https://developer.mozilla.org/en-US/docs/Web/HTML/Element
- What's the point of the <option> “label” attribute inside <select>? (Stack Overflow) — https://stackoverflow.com/questions/3905984/whats-the-point-of-the-option-label-attribute-inside-select