advertisement
The Working of new input types in HTML5 - HTML5 Forms
The type attribute of the input element determines what kind of input will be displayed in the user's browser. The default input is type="text".
The registration form for the session uses the following input types:
- Text
- Label
- Radio
- Textarea
- Checkbox
- Submit
HTML5 has introduced more data-specific user interface elements. Now, you will see the new input types in detail.
1. E-mail addresses
The type="email" is used for specifying one or more e-mail addresses. To allow multiple addresses in the e-mail field, separate each address with a comma-separator.
In the registration form, the input type has changed from text to email.
In the code, the <label> tag defines a label for the element on the form. The attribute of <label> tag binds it with the related element, that is the email element, on the form. The value of the form attribute must match the value of the ID attribute assigned to the element.
Note - If the browser does not provide support for new input types, such as email, then they are displayed as plain text fields.
2. URL
Browsers, such as Opera, Firefox, and Chrome support validation for the URL input type. While validating the URL, browsers only check for entries with a forward slash (/). For example, a URL such as x:l/mysite. Com will be considered valid, even though X:// is not a real protocol.
3. Telephone Number
4. Number
The input type="number" is used for accepting only number values. The input element displayed for the number type is a spinner box. The user can either type a number or click the up or down arrows to select a number from the spinner box.
In the code, the number input type has attributes, such as min and max to specify the minimum and maximum value for the input.
5. Range
The input type="range" is similar to the number type and displays a slider control on the page. The range type is used when the exact value is not required in input. In other words, the value of this type is not accurate. For example, an online survey form asking clients to rate the products may not receive exact values in the ratings.In the code, the range input type contains attributes, such as min, max, step, and value. The min and max attributes are used to specify the minimum and maximum value allowed for a range and are set to 1 and 10 respectively. The step attribute specifies intervals for incrementing the value. The value of the step attribute is 1 by default. The value attribute specifies the default value for the range. The default value is the midpoint of the range specified.
6. Date and Time
Date
In the code, all data input types have min and max attributes to set the range for the dates. The default value for the date input type is based on browsers. Different browsers take different dates by default. Thus, it is advisable to set the minimum and maximum values for the data type.
Month
Note - The month type is not supported in Firefox, Safari, or Internet Explorer 11 and earlier versions. However, it is supported by the Opera browser.
Week
The input type "week" provides a similar interface as displayed for the date type and selects the entire week.Time
The input type="time" displays a time of day in hours and minutes format (24-hour clock).DateTime
The input type "datetime" includes the full date and time in the input. The input includes a date part and a time part which is represented by coordinated universal time (UTC). Thus, UTC will be displayed with a 'T' followed by a 'Z'.Datetime-local
This input type is similar to the datetime input type, except that the time zone is omitted for input type="datetime-local".7. Color
HTML5 provides a predefined interface for selecting colors using the input type-"color". The input value from the color input field is a hexadecimal number. For example, #00FF00 represents a hexadecimal RGB color value.At present, the color input type is supported in Opera browsers and some new smartphones.
advertisement
Conversation
Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!
Join the discussion and share your insights now!
Comments 0