Learn HTML - Forms Cheatsheet - Codecademy
Learn HTML - Forms Cheatsheet - Codecademy
Forms
<input>: Checkbox Type
When using an HTML input element, the type="checkbox"
🥓
attribute will render a single checkbox item. To create a <input type="checkbox" name="breakfast"
group of checkboxes related to the same topic, they value="bacon">Bacon <br>
should all use the same name attribute. Since it’s a
🍳
<input type="checkbox" name="breakfast"
checkbox, multiple checkboxes can be selected for the value="eggs">Eggs <br>
same topic.
🥞
<input type="checkbox" name="breakfast"
value="pancakes">Pancakes <br>
<textarea> Element
The textarea element is used when creating a text-box
for multi-line input (e.g. a comment section). The element <textarea rows="10" cols="30" name="comment">
supports the rows and cols attributes which determine </textarea>
the height and width, respectively, of the element.
<form> Element
The HTML <form> element is used to collect and send
information to an external source. <form method="post" action="http://server1">
<form> can contain various input elements. When a user Enter your name:
submits the form, information in these input elements is
<br/>
attribute of the form.
<br/>
</form>
<input> Element
The HTML <input> element is used to render a variety of
input fields on a webpage including text fields, <label for="fname">First name:</label>
checkboxes, buttons, etc. <input> element have a type <input type="text" name="fname" id="fname">
attribute that determines how it gets rendered to a page. <br>
The example code block will create a text input field and
<select> Element
The HTML <select> element can be used to create a
dropdown list. A list of choices for the dropdown list can <select name="rental-option">
<option value="lux">Luxury</option>
<option> ’ s value attribute are sent as a key-value pair
</select>
when the form is submitted.
Submitting a Form
Once we have collected information in a form we can
send that information somewhere else by using the <form action="/index3.html" method="PUT">
action and method attribute. The action attribute tells </form>
the form to send the information. A URL is assigned that
determines the recipient of the information. The method
attribute tells the form what to do with that information
once it’s sent. An HTTP verb is assigned to the method
attribute that determines the action to be performed.
<datalist> Element
When using an HTML input, a basic search/autocomplete
functionality can be achieved by pairing an <input> with <input list="ide">
<datalist id="ide">
the <datalist> . The datalist element is used to store a
</datalist>
typing, the list will be updated to show elements that best
match what has been typed into the input field. The
actual list items are specified as multiple option
elements nested inside the datalist .
datalist s are ideal when providing users a list of pre-
defined options, but to also allow them to write
alternative inputs as well.
name attribute of the input element. The name will <input id="address" />
become the key and the value of the input will become
<label> Element
The HTML <label> element provides identification for a
specific <input> based on matching values of the <label for="password ">Password:</label>
<input> ‘s id attribute and the <label> ‘s for attribute. <input type="text" id="password"
By default, clicking on the <label> will focus the field of name="password">
the related <input> .
The example code will create a text input field with the
label text “Password: “ next to it. Clicking on “Password: “
on the page will focus the field for the related <input> .
allows the user to type censored text inside the field. It is <input type="password" name="password" />
used to type in sensitive information.
required Attribute
In HTML, input fields have an attribute called required
which specifies that the field must include a value. <input type="password" name="password"
The example code block shows an input field that is required >
required. The attribute can be written as required="true"
or simply required .
max Attribute
HTML <input> s of type number have an attribute called
max that specifies the maximum value for the input field. <input type="number" max="20">
The code block shows an input number field that is set
to have a maximum value of 20 . Any value larger than
20 will mark the input field as having an error.
maxlength Attribute
In HTML, input fields with type text have an attribute
called maxlength that specifies the maximum number of <input type="text" name="tweet"
characters that can be entered into the field. The code maxlength="140">
block shows an input text field that accepts text that has a
pattern Attribute
In a text input element, the pattern attribute uses a
regular expression to match against (or validate) the value <form action="/action_page.php">
pattern="[A-Za-z]{3}"
<input type="submit">
</form>
minlength Attribute
In HTML, an input field of type text has an attribute that
supports minimum length validation. To check that the <input type="text" name="username"
input text has a minimum length, add the minlength minlength="6" />
attribute with the character count.
min Attribute
In HTML, input fields with type number have an attribute
called min that specifies the minimum value that can be <input type="number" name="rating" min="1"
entered into the field. The code block provided shows an max="10">
input number field that accepts a number with minimum
value 1.