2. HTML Form Tag
2.1. Text Field
A Text field accepts a single line of text. The HTML element for this is <input type="text">. This means that the input tag accepts text. Notice the use of id and name as attributes for the input tag in the sample code below. During the previous modules, we know that the id attribute is used to access the HTML element in CSS and JS. The name attribute is used to refer to the HTML form element and will be used by the browser when a form is submitted.
Refer to the code below for a demonstration on how to use input with text type.
<input type="text" id="userName" name="userName">
Note that the sample code above also used the <label> tag. This tag is used before the input tag to indicate what a form element is for. The attribute for is used to indicate which form tag it is labeling. The value for this attribute is the name of the form tag that it is referring to, which is in the example, refers to “userName” and when the user clicks on the label the browser focus will automatically go to the input tag in this case.
Output:
