IT online Exam

Thursday 18 June 2020

HTML5 New Form Input Type Elements

HTML5 introduces several new <input> types like email, date, time, color, range, and so on. to improve the user experience and to make the forms more interactive. 


In this section we're going to take a brief look at each of the following new input types:




  • color
  • number
  • url
  • image
  • date
  • datetime-local
  • time
  • month
  • week
  • email
  • range
  • search
  • file
  • tel




Input Type Color
The <input type="color"> is used for input fields that should contain a color. It displays a color picker.

The color input type allows the user to select a color from a color picker and returns the color value in hexadecimal format (#rrggbb). If you don't specify a value, the default is #000000, which is black.

Example :

    <label for="favcolor">Select your favorite color:</label>
    <input type="color" id="favcolor" name="favcolor">





Input Type Number
The <input type="number"> defines a numeric input field.
The number input type can be used for entering a numerical value. You can also restrict the user to enter only acceptable values using the additional attributes min, max, and step.


Example :

  <label for="quantity">Quantity (between 1 and 5):</label>
  <input type="number" id="quantity" name="quantity" min="1" max="5">





Input Type URL
The <input type="url"> is used for input fields that should contain a URL or web addresses.

You can use the multiple attribute to enter more than one URL. Also, if required attribute is specified browser will automatically carry out validation to ensure that only text that matches the standard format for URLs is entered into the input box. 


Example :

    <label for="myurl">Enter Website URL:</label>
    <input type="url" name="myurl"  id="myurl" required>





Input Type Image
<input type=image"> defines a image as button for submitting form data to a form-handler.


Example :

    <input type="image" src="images/pic.gif">




Input Type Date
The <input type="date"> is used for input fields that should contain a date. It defines a date picker which allows the user to select a date from a drop-down calendar.

The date value includes the year, month, and day, but not the time.


Example :

   <label for="birthday">Birthday:</label>
   <input type="date" id="birthday" name="birthday">





Input Type Datetime-local
The <input type="datetime-local"> specifies a date and time input field, with no time zone.
The datetime-local input type allows the user to select both local date and time, including the year, month, and day as well as the time in hours and minutes.


Example :

  <label for="birthdaytime">Birthday (date and time):</label>
  <input type="datetime-local" id="birthdaytime" name="birthdaytime">




Input Type Time
The <input type="time"> allows the user to select a time (no time zone).

The time input type can be used for entering a time (hours and minutes).

Browser may use 12- or 24-hour format for inputting times, based on local system's time setting.


Example :


  <label for="appt">Select a time for appointment:</label>
  <input type="time" id="appt" name="appt">




Input Type Month
The <input type="month"> allows the user to select a month and year from a drop-down calendar.

The value is a string in the format "YYYY-MM", where YYYY is the four-digit year and MM is the month number. 


Example :


  <label for="birthmonth">Birthday (month and year):</label>
  <input type="month" id="birthmonth" name="bdaymonth">





Input Type Week
The <input type="week"> allows the user to select a week and year from a drop-down calendar.


Example :

  <label for="week">Select a week:</label>
  <input type="week" id="week" name="week">






Input Type Email
The <input type="email"> is used for input fields that should contain an e-mail address.

The email input type allows the user to enter e-mail address. It is very similar to a standard text input type, but if it is used in combination with the required attribute, the browser may look for the patterns to ensure a properly-formatted e-mail address should be entered.


Example :

  <label for="email">Enter your email:</label>
  <input type="email" id="email" name="email">





Input Type Range
The <input type="range"> defines a control for entering a number whose exact value is not important (like a slider control).

The range input type can be used for entering a numerical value within a specified range. It works very similar to number input, but it offers a simpler control for entering a number.

Default range is 0 to 100. However, you can set restrictions on what numbers are accepted with the min, max, and step attributes


Example :


  <label for="vol">Volume (between 0 and 50):</label>
  <input type="range" id="vol" name="vol" min="0" max="50">





Input Type Search
The <input type="search"> is used for creating search input fields.

A search field typically behaves like a regular text field, but in some browsers like Chrome and Safari as soon as you start typing in the search box a small cross appears on the right side of the field that lets you quickly clear the search field. 


Example :

  <label for="gsearch">Search Google:</label>
  <input type="search" id="gsearch" name="gsearch">





Input Type File
The <input type="file"> defines a file-select field and a "Browse" button for file uploads.

Example :

  <label for="myfile">Select a file to upload:</label>
  <input type="file" id="myfile" name="myfile">





Input Type Tel
The <input type="tel"> is used for input fields that should contain a telephone number.

Browsers don't support tel input validation natively. However, you can use the placeholder attribute to help users in entering the correct format for a phone number, or specify a regular expression to validate the user input using the pattern attribute.


Example :


  <label for="myphone">Telephone Number:</label>
  <input type="tel" id="myphone" placeholder="xx-xxxx-xxxx" required>



A Form Example :




















No comments:

Post a Comment

Bitcoins