Should I use HTML5 and/or CSS3 to build my website?
HTML5 is supported by all browsers now, even IE5!(if you use the html5shiv script). I highly recommend reading http://diveintohtml5.org It is one of the best HTML5 resources out there.
As for CSS3, if you do use it, make sure to use vendor predix too, on top of the regular syntax. e.g.
border-radius
-moz-border-radius
-webkit-border-radius
I believe in progressive enhancement. IE9's css3 support sounds very promising.
Probably.
There are parts of HTML5 that you can use right now, today. Forms for example. If you have <input type="email">
in a browser that doesn't support HTML5 (yes, even IE6) you will simply see the same thing you'd see if you used <input type="text">
. Yet on a browser that supports HTML5 form elements, you gain the advantages of the email
type: namely the client will error check the value with no extra JS required. While yes, you'll still need the JS for non-HTML5 browsers, you will have one more layer of validation in the supporting browsers.
Another question on this site provides a good overview of the new features available to you through HTML5 and CSS3. There's a lot of good data on forms in that question, too.
Because Internet Explorer (and older versions of Safari and Firefox, however rare they may be) do not support many of these features you are left with JavaScript libraries to fill the void. These include a performance hit (even though it's only for the browsers that need to use them) so be mindful of your users when employing them.
To mitigate the issues with lack of feature support, should you decide that these new features are worth it, use the following resources:
- html5shiv: a JavaScript shiv for IE to recognize and style the HTML5 elements.
- CSS3 Pie: an IE attached behavior (an
.htc
file) that makes Internet Explorer 6-8 capable of rendering several of the most useful CSS3 decoration features. When applied to an element, it allows IE to recognize and displayborder-radius
,box-shadow
,border-image
, multiple background images, andlinear-gradient
as background image. - Modernizr: a Javascript library that uses feature detection to test the current browser against upcoming CSS3/HTML5 features, adding classes to the <html> element for those which are supported. Also creates a self-titled global JavaScript object which contains a boolean property for each feature,
true
if supported andfalse
if not. Adds support for styling and printing HTML5 elements so you can use elements such as<section>
,<header>
and<nav>
. - ie-css3.js: allows Internet Explorer to identify CSS3 pseudo-class selectors and render any style rules defined with them. Supports different CSS3 selectors based on which JavaScript library your site uses.
- DD_belatedPNG: a Javascript library that adds PNG image support to IE6. You can use PNGs as the
src
of an<img />
element or as abackground-image
property in CSS. UnlikeAlphaImageLoader
,background-position
andbackground-repeat
work as intended, and elements will respond to thea:hover
pseudo-class. - TwinHelix IE PNG Fix: an IE attached behavior (an
.htc
file) that adds PNG support with alpha opacity to IE 6. Full CSS background positioning and repeat are supporting (including CSS sprites) with additional (included) JavaScript. - Whatever:hover: an IE attached behavior (an
.htc
file) that automatically patches :hover, :active and :focus for IE6, IE7 and IE8 quirks, letting you use them like you would in any other browser. Includes AJAX support, meaning that any html that gets inserted into the document via javascript will also trigger:hover
,:active
and:focus
styles in IE.
Interesting to note that DD_belatedPNG solves both issues addressed by Whatever:hover and TwinHelix's IE PNG Fix with pure JavaScript, while Whatever:hover and TwinHelix's IE PNG Fix use a combination of JavaScript and IE attached behaviors (.htc files
).
Generally people who use non-IE browsers upgrade them when asked to, and so IE bears the brunt of "But some browsers don't support this feature!" complaints. Modernizr will add the ability to use HTML5/CSS3 to any browser you're likely to see and not just IE. ie-css3.js will do the same thing, you simply have to implement it without an IE conditional comment (which means all browsers will end up getting it unless you include it with server-side user-agent checks – this will greatly reduce performance for all of your visitors, rather than just your IE users.)
Use whatever technology suits your needs most.
Eric Meyer wrote a nice article about why starting to use vendor-specific prefixes on CSS rules isn't lame like using css filter hacks used to be.
I think the same applies to HTML5. If you can check browser support for different features, why not use it. So long as the site degrades gracefully, live it up.