YouTip LogoYouTip

Html5 Form Input Types

HTML5 introduces several new form input types. These new features provide better input control and validation. This chapter provides a comprehensive introduction to these new input types: * color * date * datetime * datetime-local * email * month * number * range * search * tel * time * url * week **Note:** Not all mainstream browsers support the new input types, but you can already use them in all major browsers. Even if they're not supported, they'll still render as regular text fields. * * * ## Input Type: color The color type is used in input fields primarily for selecting colors, as shown below: ![Image 1: Opera]( 2: Safari]( 3: Chrome]( 4: Firefox]( 5: Internet Explorer]( ## Example Select a color from the color picker: Choose your favorite color: [Try it out Β»]( * * * ## Input Type: date The date type allows you to select a date from a date picker. ![Image 6: Opera]( 7: Safari]( 8: Chrome]( 9: Firefox]( 10: Internet Explorer]( ## Example Define a date controller: Birthday: [Try it out Β»]( * * * ## Input Type: datetime The datetime type allows you to select a date (UTC time). ![Image 11: Opera]( 12: Safari]( 13: Chrome]( 14: Firefox]( 15: Internet Explorer]( ## Example Define a date and time controller (local time): Birthday (date and time): [Try it out Β»]( * * * ## Input Type: datetime-local The datetime-local type allows you to select a date and time (no timezone). ![Image 16: Opera]( 17: Safari]( 18: Chrome]( 19: Firefox]( 20: Internet Explorer]( ## Example Define a date and time (no timezone): Birthday (date and time): [Try it out Β»]( * * * ## Input Type: email The email type is used for input fields that should contain an email address. ![Image 21: Opera]( 22: Safari]( 23: Chrome]( 24: Firefox]( 25: Internet Explorer]( ## Example When submitting the form, the value of the email field will be automatically validated for validity: E-mail: [Try it out Β»]( **Tip:** The Safari browser on iPhone supports the email input type and adapts its touchscreen keyboard accordingly (adding @ and .com options). * * * ## Input Type: month The month type allows you to select a month. ![Image 26: Opera]( 27: Safari]( 28: Chrome]( 29: Firefox]( 30: Internet Explorer]( ## Example Define a month and year (no timezone): Birthday (month and year): [Try it out Β»]( * * * ## Input Type: number The number type is used for input fields that should contain numeric values. You can also set limits on the numbers accepted: ![Image 31: Opera]( 32: Safari]( 33: Chrome]( 34: Firefox]( 35: Internet Explorer]( ## Example Define a numeric input field (with limits): Quantity (between 1 and 5): [Try it out Β»]( Use the following attributes to specify limits for numeric types: | Attribute | Description | | --- | --- | | disabled | Specifies that the input field is disabled | | max | Specifies the maximum allowed value | | maxlength | Specifies the maximum number of characters allowed in the input field | | min | Specifies the minimum allowed value | | pattern | Specifies the pattern used to validate the input field | | readonly | Specifies that the value of the input field cannot be modified | | required | Specifies that the input field's value is required | | size | Specifies the number of visible characters in the input field | | step | Specifies the legal interval between numbers in the input field | | value | Specifies the default value of the input field | Try an example with all limiting attributes ( * * * ## Input Type: range The range type is used for input fields that should contain numeric values within a certain range. The range type is displayed as a slider. ![Image 36: Opera]( 37: Safari]( 38: Chrome]( 39: Firefox]( 40: Internet Explorer]( ## Example Define a numeric field that doesn't need to be very precise (similar to a slider control): [Try it out Β»]( Please use the following attributes to specify limits for numeric types: * max - Specifies the maximum allowed value * min - Specifies the minimum allowed value * step - Specifies the legal interval between numbers * value - Specifies the default value * * * ## Input Type: search The search type is used for search fields, such as site searches or Google searches. ![Image 41: Opera](
← Html5 Form ElementsHtml5 Audio β†’