Gadgets

Sunday, 8 June 2014

HTML5 new input type with examples



HTML5 New Input Types


HTML5 has several new input types for forms. These new features allow better input control and validation.
  • color
  • date
  • datetime
  • datetime-local
  • email
  • month
  • number
  • range
  • search
  • tel
  • time
  • url
  • week
Input Type Examples:
Select a color from a color picker:
Select your favorite color :  <input type="color" name="favcolor">


                                                                                                                                                                   
Select Birthday :  <input type="date" name="bday">

Define a date and time control (with time zone):
Birthday (date and time) :  <input type="datetime" name="bdaytime">

Define a date and time control (no time zone):
Birthday (date and time) :  <input type="datetime-local" name="bdaytime">

The time type allows the user to select a time.
Define a control for entering a time (no time zone):
Select a time: <input type="time" name="usr_time">
 


Define a week and year control (no time zone):
Select a week: <input type="week" name="week_year">




The time type allows the user to select a time.
Define a control for entering a time (no time zone):
Select a time: <input type="time" name="usr_time">



Define a month and year control (no time zone):
Birthday (month and year) : <input type="month" name="bdaymonth">


Define a field for an e-mail address (it will be automatically validated when submitted):
E-mail: <input type="email" name="email">
 

The value of the URL field should contain a URL address and automatically validated when the form is submitted.
Below example allow only http://www.example.example
Add your homepage: <input type="url" name="homepage">


The number type is used for input fields that should contain a numeric value.
Define a numeric field (with restrictions):
Quantity (between 1 and 5): <input type="number" name="quantity" min="1" max="5">

Use the following attributes to specify restrictions:
  • max - specifies the maximum value allowed
  • min - specifies the minimum value allowed
  • step - specifies the legal number intervals
  • value - Specifies the default value
The range type is used for input fields that should contain a value from a range of numbers.
You can also set restrictions on what numbers are accepted.
<input type="range" name="points" min="1" max="10">


Use the following attributes to specify restrictions:
  • max - specifies the maximum value allowed
  • min - specifies the minimum value allowed
  • step - specifies the legal number intervals
  • value - Specifies the default value

Define a search field (like a site search, or Google search):
Search Google: <input type="search" name="googlesearch">
 
Input Type: tel
The tel type is used for input fields that should contain a telephone number. 
Below example allow only 10 digits mobile number.
Telephone: <input type="tel"  name="tel" pattern="\d{10}"  required />                                                                                                                                             

Introduction about HTML5

What is HTML5 :

HTML5 is advanced to the HTML
HTML5 was designed to replaced HTML4,XHTML, and HTML DOM level2
It was specially designed to deliver rich content without the need for additional plugins. The current version delivers everything from animation to graphics, music to movies, and can also be used to build complicated web applications.
HTML5 is also cross-platform. It is designed to work whether you are using a PC, or a Tablet, a Smartphone, or a Smart TV.

Who Created New HTML5? :

Web Hypertext Application Technology Working Group (WHATWG) was working with web forms and applications, and World Wide Web Consortium (W3C) was working with XHTML 2.0. In 2006, they decided to cooperate and create a new version of HTML.

HTML5 - New Features
  • New features should be based on HTML, CSS, DOM, and JavaScript
  • The need for external plugins (like Flash) should be reduced
  • Error handling should be easier than in previous versions
  • Scripting has to be replaced by more markup
  • HTML5 should be device-independent
  • The development process should be visible to the public
HTML5 Document structure 

Simple HTML5 document structure, with the minimum of required tags:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>

<body>
Content of the document......
</body>

</html>

Browser Support for HTML5

All major browsers (Chrome, Firefox, Internet Explorer, Safari, and Opera) support the new HTML5 elements and APIs, and continue to add new HTML5 features to their latest versions.