Request user data
input
An input field provides an interface between the browser and the user which allows data to be requested in specific ways.
The input element is multi-faceted, presenting itself to the user as: text input, radio buttons, check boxes, buttons, color pickers, dates and times, and more.
Input elements are typically placed subordinate to a form element.
Properties
- type
- This attribute controls the appearance and functionality of the element.
- Text types:
textA single-line text field.passwordA single-line text field whose value is obscured. Use the maxlength and minlength attributes to specify the acceptable length of the value that can be entered.searchA field for entering search strings.emailA field for entering an e-mail address.telA field for entering a telephone number.urlA field for entering a URL.numberA field for entering a number.hiddenAn input area that is not displayed but whose value is submitted to the server.- Radios and checkboxes:
radioA radio button, allowing a single value to be selected out of multiple choices.checkboxA check box allowing single values to be selected/deselected.- Date and time types:
dateAn input for entering a date (year, month, and day).timeAn input for entering a time value.datetime-localAn input for entering a date and time.monthAn input for entering a month and year.weekAn input for entering a date consisting of a week-number and a year.- Single purpose types:
colorAn input for specifying a color using the browser's color picker user interface.rangeAn input for entering an integer value between a minimum and maximum.fileA way to let the user select a file. Use the accept attribute to define the types of files that the control can select.- Button types:
buttonA push button with no default behavior.resetA button that resets the contents of the form to default values.submitA button that submits the form.imageA graphical submit button. The src attribute defines the source of the image. The alt attribute defines alternative text. The height and width attributes define the size of the image.- name
- The name attribute is used as the key name in the key/value pairs submitted to the server.
- value
- When the form is first loaded, this value is used to preset the element's display.
- When the form is submitted, this is the value that will be sent to the server.
- list
- This attribute is used to associate a list of predefined acceptable values which have been specified with a datalist element. Provide the ID of the datalist.
- form
- This attribute may be used to declare the input to be part of a form even when it is not directly subordinate to it. Provide the ID of the form.
- readonly
- The input should be visible, but unchangable. Its value will be included in the submission.
- disabled
- The input should be visible, but unchangable. Its value will not be included in the submission.
- required
- When present, this field must not be left blank.
- autofocus
- Identifies this input element as the one that should receive keyboard focus when the page is loaded.
- autocomplete
onThe browser can assist the user by automatically providing values that were previously used on similar forms.offThe browser should not provide any automatic assistance.nameThe browser should automatically provide the user's full name.honorific-prefixThe browser should automatically provide the user's prefix or title, like "Dr.", "Ms.", etc.given-nameThe browser should automatically provide the user's first name.additional-nameThe browser should automatically provide the user's middle name.family-nameThe browser should automatically provide the user's last name.honorific-prefixThe browser should automatically provide the user's suffix, like "Jr.", "PhD.", etc.nicknameThe browser should automatically provide the user's nickname.emailThe browser should automatically provide the user's email address.usernameThe browser should automatically provide the user's account name.- See the MDN documentation for more possibilities.
Examples
form `/api/text-input` {
label What is your nationality?
input *type=text *name=nationality
}
form `/api/password-input` {
label Enter a new password
input *type=password *name=new-password
}
form `/api/radio-input` {
label What is your gender?
input #male *type=radio *name=gender Male
input #female *type=radio *name=gender Female
}
form `/api/checkbox-input` {
label Do you want to receive periodic news about special offers?
input *type=checkbox *name=special-offers Yes, sign me up
}
form `/api/range-input` {
label What is your skill level?
input *type=range *name=skill-level *value=50 *min=0 *max=100 *step=10
}
form `/api/hidden-input` {
input *type=hidden *name=honeypot *value=2019-12-31-24-00-00
}
form `/api/file-upload` {
input *type=file *name=avatar *accept='image/jpeg, image/png'
}
form `/api/submission` {
label What is your nationality?
input *type=text *name=nationality
label Enter a new password
input *type=password *name=new-password
label What is your gender?
input #male *type=radio *name=gender Male
input #female *type=radio *name=gender Female
label Do you want to receive periodic news about special offers?
input *type=checkbox *name=special-offers Yes, sign me up
label What is your skill level?
input *type=range *name=skill-level *value=50 *min=0 *max=100 *step=10
input *type=hidden *name=honeypot *value=2019-12-31-24-00-00
input *type=submit *value='Sign up'
}
