HTML5 Day 5: New Date Input Type <input type=date />

18. November 2010

Date is one of the new, and much needed, input types added in HTML5. This has been added as a replacement of using a text box for the input of dates. Below is a screenshot of the custom UI that the Opera web browser automatically implements for this new input type.

Display in Modern Browsers

HTML5_INPUT_DATE_OPERA

This is a screenshot of the Opera web browser’s UI for the date input field. The actual display of this field is handled by the web browser and will vary in each browser and device the page is being viewed on. For example, iOS and other mobile devices will display a more mobile friendly calendar picker than the desktop version of Opera shown above.

Here’s the HTML5 source for the above screenshot:

<!DOCTYPE html>
<meta charset="utf-8">
<html lang="en">
<head>
</head>
<body>

Date: <input type=date />

</body>
</html>

As you can see in the screenshot the format for the date is “yyyy-mm-dd” That is a four digit year, two digit month and a two digit day in that order, separated each by a hyphen.

What about Older Browsers?

Older web browsers render any <input> tags with an “unknown” type as a regular text box. So consequentially older web browsers will render the above date input type as a text input type.

Even though older web browsers do not display any special UI for the date input type, you can still use your own JavaScript code or the jQuery UI DatePicker to display your own UI in those browsers.

HTML5_INPUT_DATE_jQuery_IE8

Here’s a modified version of the above code including a “patch” using the jQuery UI DatePicker and Modernizr to display custom UI in older browsers that do not support the date input type. The above screenshot is an example of this in action in Internet Explorer 8.

<!DOCTYPE html>
<meta charset="utf-8">
<html lang="en">
<head>
<!-- Include jQuery, jQuery UI and Modernizr -->
<script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.4.js"></script>
<script src="http://ajax.microsoft.com/ajax/jquery.ui/1.8.5/jquery-ui.js"></script>
<script src="http://cachedcommons.org/cache/modernizr/1.5.0/javascripts/modernizr.js"></script>

<link href="http://ajax.microsoft.com/ajax/jquery.ui/1.8.5/themes/redmond/jquery-ui.css"
    rel="stylesheet" type="text/css" />
</head>
<body>

Date: <input type=date />

<script>
$(function() {
    // Check if the browser supports the date input type
    if (!Modernizr.inputtypes.date){
        // Add the jQuery UI DatePicker to all
        // input tags that have their type attributes
        // set to 'date'
        $('input[type=date]').datepicker({
            // specify the same format as the spec
            dateFormat: 'yy-mm-dd'
        });
    }
});
</script>

</body>
</html>

Conclusion

Support for the Date Input, as is the same it seems with every aspect of HTML5, can be “patched” in older web browsers whilst maintaining future compatibility with modern browsers and future browsers to come. The current JavaScript frameworks (jQuery, jQuery UI, Modernizr, etc.) offer some real power to building applications and now the HTML5 specification offers a target to shoot for with those frameworks that offers unity across websites. Once you have enough “patches” built, like the one in this article, you could include them all in any HTML5 site to add support for older browsers. HTML5 is usable today and not just a dream about the future of web development.

HTML, HTML, HTML, HTML, JavaScript, JavaScript, JavaScript, JavaScript , , , , , , , , , , ,

Comments

12/3/2010 2:46:49 PM #
hello my kind friend
12/12/2010 9:47:31 AM #
There is obviously  a bunch to identify about this.  I feel you made various good points in features also.
12/12/2010 8:49:15 PM #
After all, what a great website and informative posts, I will add backlink - bookmark this web site?
12/12/2010 11:28:11 PM #
I’m having a strange problem I cannot make my reader pick up your feed, I’m using google reader by the way.
12/13/2010 12:15:34 AM #
When are you going to post again? You really entertain  a lot of people!
12/13/2010 12:35:20 AM #
Hello! Is that Okay if I ask anything kinda off subject? I am attempting to check out this blog page with my new iphone but it will not present up right, will you get any ideas about this problems? Do i have to possess an update for my program or something like that? Thanks a lot! x Smile
12/13/2010 3:51:41 AM #
Absolutely Great! The contexts ended up very informational and educative. I’ve learned a large amount of ideas through this material. Thank you!
12/13/2010 4:19:43 AM #
I like the way you write. Organized, concise, yet elaborate. Smile
12/13/2010 5:01:05 AM #
what kind javascript error which I get everytime I tried to reposnd
12/13/2010 5:08:12 AM #
When I originally commented I clicked the "Notify me when new comments are added" checkbox and now each time a comment is added I get three emails with the same comment. Is there any way you can remove me from that service? Thanks!

Regards!


12/13/2010 5:21:38 AM #
Definitely, what a splendid website and educative posts, I will bookmark your site.Best Regards!
12/13/2010 6:11:30 AM #
i am creating a directory of active blogs and find your blog very interesting. This will definitely make the cut.
12/13/2010 6:29:53 AM #
lol a couple of the reviews bloggers write are silly and unrelated, there are times i wonder whether they at all read the post before writing or whether they just look at the subject of the blog post and compose the very first thought that drifts to their minds. But it is great to see a intelligent commentary every now and then in contrast to the exact same, traditional blog bull which I too many times notice on the blogs. Regards PokemonCraft Admin.
12/13/2010 6:42:46 AM #
Its ridiculous how much more attention I get from the opposite gender when I wear high heeled shoes!
12/13/2010 7:20:35 AM #
Hi, great article!! I got you bookmarked. Thanks and best wishes
12/13/2010 7:22:37 AM #
Brilliant, thank you, I will subscribe to you RSS later.
12/13/2010 7:37:25 AM #
Howdy - I should say, I?m happy with your website. I had no difficulties navigating via all of the tabs and the information was really easy to access. I found what I required in no time at all. Truly awesome.
12/13/2010 9:06:34 AM #
Hello there!  Just want to say that I found your site enough great for me.  Usefull information and all is nice arranged. Thank you for your work. I will visit your site more ofter from now and I bookmarked it. You can feel free to visit my <a href="www.24hrcrimescenecleaners.com">crime scene cleanup</a> site if you have a time.
12/13/2010 9:18:47 AM #
Thank you so much for so intelligent article. Good job!
12/13/2010 10:01:32 AM #
Blogroll links aint that great Tong but i am not the admin… Tong … Just Telling Tong
12/13/2010 11:04:28 AM #
Every time I read a great blog post I go ahead and do one of three thing:<p>1.Show it to my relevant friends.<p>2.save it in all of the common bookmarking sites.<p>3.Make sure to come back to the same blog where I came accross the article.<p>After reading this article I'm seriously thinking of going ahead and doing all three!
12/13/2010 12:39:51 PM #
Geat post, thansk! I'am sure will be back here soon!
12/13/2010 4:48:35 PM #
When are you going to post again? You really entertain me!
12/13/2010 5:13:15 PM #
Are Plants in the Bedroom Good Feng Shui or Bad Feng Shui? Plants are excellent feng shui for any home, especially the air-purifying plants. However, plants are generally not recommended in the bedroom.
12/13/2010 8:51:08 PM #
c00l
12/13/2010 9:50:31 PM #
This is a great Blog! thanks for the contribution.
12/13/2010 10:27:49 PM #
Blogengine FTW!
  HTML5 Day 5: New Date Input Type <input type=date />
is cool.  I am really interested and was wondering if anyone else had any other related posts they would suggest. I like writing squidoo lenses myself and would like to gather as much data as I can. Please take a look one of my little projects if you like
12/13/2010 10:42:20 PM #
I  enjoyed your article. I think I am going to have to subscribe.And awesome Topic.
12/13/2010 10:50:15 PM #
Have you considered adding some differing opinions to your article? I think it will really enhance viewers' understanding.
12/14/2010 12:02:06 AM #
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained! I’m sure you had fun writing this article.
12/14/2010 12:30:24 AM #
Love all the opinions expressed here! How is everyone? Love how everyone expresses whatr they feel Smile
12/14/2010 12:36:35 AM #
I definitely that this piece is the best post that i have ever read in my life.
12/14/2010 1:07:22 AM #
I was looking for an article about this subject and this one is just the most informative I've ever found.
12/14/2010 1:54:38 AM #
Finally i find something that is really informational and good to read. Thank you so much for maintaining this blog.
12/14/2010 2:11:18 AM #
neat column I am thankful to have read