What is a shiv in HTML5?




A shiv, which is also known as a shim, is some Javascript code that allows HTML5 elements to be properly styled in versions of Internet Explorer before version 9. The reason a shiv is needed in earlier versions of Internet Explorer is because of the fact that those earlier versions of the IE browser do not allow unknown elements to be styled without the use of Javascript. And, since the HTML5 standard was not followed in those earlier versions (because the standard wasn’t even out at that time), there is a need for a “shiv” so that HTML5 applications running in earlier versions of Internet Explorer can display properly. Think of a shiv as a Javascript fix for Internet Explorer.

So, an HTML5 shiv basically allows new HTML5 elements to be styled using older styles.

How to use the HTML shiv

In order to use the shiv Javascript code, all you have to do is add the following code in the head section of your webpage (between the <head> </head> tags) :

<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js">
</script>
<![endif]--> 

The code above simply points to a Javascript file on Google’s servers – so you don’t have to host the file yourself.

How to download the HTML shiv

If you want to download and then upload the HTML shiv on your web server then you can simply go directly to the page http://html5shiv.googlecode.com/svn/trunk/html5.js, and copy and paste the code into a Javascript file on your own server, and then point to that file in the src attribute shown above.

Shiv versus shim

There is absolutely no difference between a shiv and a shim. The person who coined the term shiv actually meant for it to be called “shim”, but the term shiv was the term that became more popular – although you are likely to come across “shim” as well

What is the difference between a shiv and a polyfill?

A polyfill is different from a shiv because, assuming your code is correctly written, even if you remove the polyfill script your code should still work just fine. However, if you remove a shiv, then your code will not work correctly (at least in older versions of IE) because of the issues with styling elements that are not recognized by earlier versions of IE.

Hiring? Job Hunting? Post a JOB or your RESUME on our JOB BOARD >>

Subscribe to our newsletter for more free interview questions.

  • Varoon

    It's been fixed – thanks for pointing it out!

  • Administrator

    It's been fixed – thanks for pointing this out!

  • irach11 .

    Hi,
    hmmm… where is the shiv code?
    The placeholder is empty…