Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modernizr vs HTML shiv

If I ONLY need older browsers to recognize HTML5 tags, which should I use, Modernizr or the popular HTML5 shiv? And also, if I don't need to style this HTML5 tags, do I need the browsers to recognize them anyways? Or is it only necessary when adding CSS to these tags?

Thanks!

like image 724
federico-t Avatar asked Nov 26 '11 01:11

federico-t


People also ask

What is modernizr used for?

Modernizr is a JavaScript library that detects which HTML5 and CSS3 features your visitor's browser supports. In detecting feature support, it allows developers to test for some of the new technologies and then provide fallbacks for browsers that do not support them.

What is the purpose of the HTML5 shiv?

The HTML5 Shiv enables use of HTML5 sectioning elements in legacy Internet Explorer and provides basic HTML5 styling for Internet Explorer 6-9, Safari 4. x (and iPhone 3. x), and Firefox 3.

What is script modernizr?

Modernizr is a JavaScript library that detects the features available in a user's browser. This lets web pages avoid unsupported features by informing the user their browser isn't supported or loading a polyfill.


3 Answers

html5shiv basically allows IE to recognize and style HTML5 elements, while Modernizr provides the same plus feature detection supported by a broswer.

So to answer your question HTML5 shiv should be sufficient to recognize HTML5 tags in IE. (note I say IE here since that is what the html5shiv targets, not sure what you mean when you say older browsers)

For the second part, even if you don't want to style the HTML5 tags, I would advice to use the shiv since the browser may either display them incorrectly, or not at all, so it is better to be safe.

like image 72
omarello Avatar answered Oct 06 '22 08:10

omarello


HTML5 Shiv is smaller, and unless you need some of Modernizr's detection functionality, go for the shiv.

The size of the file is very important, since it is always in the head of the html document and blocks the download of additional resources until fully executed.

Since it is only needed for older browsers, I use the following code:

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

You can remove the html tags you don't use, but then you will be unable the use the file hosted at Google.

like image 34
Emil Avatar answered Oct 06 '22 07:10

Emil


You can alternatively use Modernizr to load a particular file if browser supports that particular CSS or HTML5 features.

Let say if the browser doesn't support 'canvas' as HTML5 element and 'fontface' as CSS3 property

Modernizr.load({
test: Modernizr.fontface && Modernizr.canvas, // Test if the browser supports it or not
yep : '/path-to/html5-css3-attributes.css',  // If browser supports it, load this file
nope: '/path-to/old-css-attributes.css' // If NOT, load this instead
});

You can use .js also in your file path condition.

like image 31
ElvinD Avatar answered Oct 06 '22 07:10

ElvinD