HTML5Shiv is a JavaScript workaround, discovered by Sjoerd Visscher, to enable support styling of HTML5 elements in versions of Internet Explorer prior to version 9.0, which do not allow unknown elements to be styled without JavaScript. Means your CSS classes and attributes will not be applied to the particular HTML5 specific display element, until and unless the object is available in the DOM tree.
What HTML5Shiv does is that it creates the objects for all known HTML5 elements(of the Page) in the DOM tree?. This gives the browser an implication that the particular element is supported and available in the DOM tree and it applies the specific CSS classes to the element.
Follow these simple steps to integrate HTML5Shiv to your existing page:
Step 1: Get HTML5Shiv binary – You can get HTML5Shiv binary(html5shiv.js) from http://code.google.com/p/html5shiv/
Step 2: Insert the necessary code block in the <head> element of your html page (after or before your CSS)
code block:
<blockquote><p><!--[if lt IE 9]><br /><script src="scripts/html5shiv.js"></script><br /><![endif]—></p></blockquote>
NB: Assuming that html5shiv.js is kept under the scripts folder under the root folder of your web application.
Lets look for a simple example:
Look at the below html sample, with an article element:
Copy the below code block in to notepad and save as ‘test.html’ – to a location wherever you like 🙂
<!DOCTYPE HTML> <html> <head> <style> article { font-size: 22px; color: orange; } </style> </head> <body> <article>Hello!</article> </body> </html>
Try to Browse the sample in Internet Explorer 7.0(by double clicking on ‘test.html’ file) and you can see that font color and font size are not applied and as a default fallback – it is displaying text in a normal font and color. It is because browser will not apply the CSS to an unknown element, HTML5 elements are aliens 🙂 for IE 8.0 and below.
[Before – HTML5 Shiv is applied]
Now try to apply the HTML5Shiv code block on to the above sample and see the magic. Modified code block will look like below:
<!DOCTYPE HTML> <html> <head> <!--[if lt IE 9]><br /><script src="scripts/html5shiv.js"></script><br /><![endif]--> <style> article { font-size: 22px; color: orange; } </style> </head> <body> <article>Hello!</article> </body> </html>
[After – HTML5 Shiv is applied]
Very nice! right?. Yes, it is indeed helpful for enabling backward support of your HTML5 elements styling on IE 6,7,8 versions.
DOWNLOAD and USE
You can get HTML5Shiv binary from here: http://code.google.com/p/html5shiv/
and Full original, uncompressed source available here: https://github.com/aFarkas/html5shiv
Hope you enjoy this nice tip.
Courtesy: Wikipedia and Google Code
Discover more from Cloud Distilled ~ Nithin Mohan
Subscribe to get the latest posts sent to your email.
Hi
Thanks for writing nice artical on this topic. have you tried this plugin with local and session storage of HTML 5.0 ?. One time i used local storage in my project, but it was not supporting on IE 7 and 6 . I also checked with this plugin.
HTML5 support is available from IE9 onwards only. I have you are aware that IE7 and 6, are released way earlier, thus these API support will not be extended to IE7 and below.