- HTML Form Elements
- The HTML Elements
- The Element
- Example
- The Element
- The Element
- Example
- Example
- Visible Values:
- Example
- Allow Multiple Selections:
- Example
- The Element
- Example
- Example
- The Element
- Example
- The and Elements
- Example
- The Element
- Example
- The Element
- Example
- HTML Exercises
- HTML Form Elements
- HTML Tag
- Browser Support
- Attributes
- Global Attributes
- Event Attributes
- More Examples
- Example
- HTML textarea – How to Add a Text Box Input Type Tag to Your Website
- How to Add a Text Field to Your Website
- How to Add a Text Area to Your Website
- Conclusion
HTML Form Elements
This chapter describes all the different HTML form elements.
The HTML Elements
The HTML element can contain one or more of the following form elements:
The Element
One of the most used form element is the element.
The element can be displayed in several ways, depending on the type attribute.
Example
All the different values of the type attribute are covered in the next chapter: HTML Input Types.
The Element
The element defines a label for several form elements.
The element is useful for screen-reader users, because the screen-reader will read out loud the label when the user focus on the input element.
The element also help users who have difficulty clicking on very small regions (such as radio buttons or checkboxes) — because when the user clicks the text within the element, it toggles the radio button/checkbox.
The for attribute of the tag should be equal to the id attribute of the element to bind them together.
The Element
The element defines a drop-down list:
Example
The elements defines an option that can be selected.
By default, the first item in the drop-down list is selected.
To define a pre-selected option, add the selected attribute to the option:
Example
Visible Values:
Use the size attribute to specify the number of visible values:
Example
Allow Multiple Selections:
Use the multiple attribute to allow the user to select more than one value:
Example
The Element
The element defines a multi-line input field (a text area):
Example
The rows attribute specifies the visible number of lines in a text area.
The cols attribute specifies the visible width of a text area.
This is how the HTML code above will be displayed in a browser:
You can also define the size of the text area by using CSS:
Example
The Element
The element defines a clickable button:
Example
This is how the HTML code above will be displayed in a browser:
Note: Always specify the type attribute for the button element. Different browsers may use different default types for the button element.
The and Elements
The element is used to group related data in a form.
The element defines a caption for the element.
Example
This is how the HTML code above will be displayed in a browser:
The Element
The element specifies a list of pre-defined options for an element.
Users will see a drop-down list of the pre-defined options as they input data.
The list attribute of the element, must refer to the id attribute of the element.
Example
The Element
The element represents the result of a calculation (like one performed by a script).
Example
Perform a calculation and show the result in an element:
HTML Exercises
HTML Form Elements
Tag | Description |
---|---|
Defines an HTML form for user input | |
Defines an input control | |
Defines a multiline input control (text area) | |
Defines a label for an element | |
Groups related elements in a form | |
Defines a caption for a element | |
Defines a drop-down list | |
Defines a group of related options in a drop-down list | |
Defines an option in a drop-down list | |
Defines a clickable button | |
Specifies a list of pre-defined options for input controls | |
Defines the result of a calculation |
For a complete list of all available HTML tags, visit our HTML Tag Reference.
HTML Tag
The tag defines a multi-line text input control.
The element is often used in a form, to collect user inputs like comments or reviews.
A text area can hold an unlimited number of characters, and the text renders in a fixed-width font (usually Courier).
The size of a text area is specified by the cols and rows attributes (or with CSS).
The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the text area will be submitted).
The id attribute is needed to associate the text area with a label.
Browser Support
Attributes
Attribute | Value | Description |
---|---|---|
autofocus | autofocus | Specifies that a text area should automatically get focus when the page loads |
cols | number | Specifies the visible width of a text area |
dirname | textareaname.dir | Specifies that the text direction of the textarea will be submitted |
disabled | disabled | Specifies that a text area should be disabled |
form | form_id | Specifies which form the text area belongs to |
maxlength | number | Specifies the maximum number of characters allowed in the text area |
name | text | Specifies a name for a text area |
placeholder | text | Specifies a short hint that describes the expected value of a text area |
readonly | readonly | Specifies that a text area should be read-only |
required | required | Specifies that a text area is required/must be filled out |
rows | number | Specifies the visible number of lines in a text area |
wrap | hard soft | Specifies how the text in a text area is to be wrapped when submitted in a form |
Global Attributes
Event Attributes
More Examples
Example
Disable default resize option:
HTML textarea – How to Add a Text Box Input Type Tag to Your Website
Joel Olawanle
A text box is a section of your website where users can enter text. A blinking cursor appears when you click or tap on or inside the text box, indicating that you are ready to begin typing. And an on-screen keyboard will appear if you’re using a tablet or smartphone.
Text boxes are classified into two types: text fields and text areas. These two text boxes serve different purposes and help your user understand what they should be typing into the text box.
A text field is a small, typically rectangular box where you can enter a single line of text, such as a name, number, or any other short text type.
A text area is a larger box where you can enter multiple lines of text, such as descriptions, paragraphs, and so on.
When you tap the enter button in a text field, the cursor will either move to the following field or submit the form. In a text area, on the other hand, the cursor will move to a new line, creating a line break.
How to Add a Text Field to Your Website
Whenever you want a user to input something into a webpage, you can use the tag. Then, to ensure this is a text field, you can add the type attribute of text :
This will output a single-line text field on our web page, which can take in all forms of text values. We can also add a label tag or other attributes like the placeholder attribute to let users know what to input in the text field.
There are many more attributes we can define on a text field, such as the maxlength and minlength , to help define the maximum or the minimum amount of text a field can accept.
We can also pass in default values to our text filed with the value attribute:
How to Add a Text Area to Your Website
A text area is defined by a tag. You use it to collect unlimited multi-line text like comments or reviews.
You specify the size of a text area by the cols and rows attributes (or with CSS).
The textarea field does not use the value attribute to pass in default values, but you can place default content between the opening and closing tags.
Like the input tags, we can add the maxlength , minlength and placeholder attributes to the textarea field.
Conclusion
In this article, you have learned how to add a text box to your website using the and tags, depending on the type of text you wish to add.
You can learn more about HTML tags in the following resources: