How to write backwards compatible HTML5?
Asked Answered
O

6

14

I'd like to start using HTML5's basic features, but at the same time, keep my code backwards compatible with older browsers (graceful degradation). For instance, I'd like to use the cool CSS3 properties for making rounded corners. Is there any available tutorial for writing gracefully degradable HTML5 ?

Additionally, what browsers should I support so that my app. is functional for at least 95% of visitors? What are the ways to test those browsers painlessly ?

Otranto answered 20/4, 2010 at 11:33 Comment(0)
H
13

When talking about HTML5 or CSS3, you should head over to:

When can I use...

As can be seen, we are still far far away from using that.

Also, since old versions of the browsers won't support HTML5 or CSS3, however, you can do what is known as:

Progressive Enhancement and Graceful Degradation

Here are some resources also:

Homophonic answered 20/4, 2010 at 11:38 Comment(5)
I know I can do that... My question was how to do Graceful Degradation specifically for HTML5.Otranto
@Olivier Lalonde: The Graceful Degradation is not specific to anything like html5. There are a host of resources on that you might want to google about. ThanksHomophonic
Great resource, exactly what I was looking for.Otranto
Sounds promising, but unfortunately the deveria and sitepoint links are brokenRance
From the "Progressive Enhancement" link: No one can force software or upgrades on a user: doing so would be contrary to their democratic right of choice. Someone teach Microsoft, please.Fifteen
D
2

Browsers that, collectively, cover 95% of the world: Firefox, Chrome, IE6/7/8. The best way to test them is to install them on your computer.

Dimitris answered 20/4, 2010 at 11:40 Comment(6)
@Dimitris - Good idea but...installing IE6/7/8 is a particular pain in the ass :)Jallier
That's what VMs are for. The hard part is finding a VM image that still has IE6 on it.Planet
Or you could use something like SuperPreview etc that does compatability checks :)Ineducable
If you open the IE9 debuger (F12), you can select IE7, IE8 and IE9 emulation. It works great.Irreverence
and if you're still supporting IE6, you really need to tell your end users to upgrade. Supporting an old browser sucks up $, time, and adds lots of gray hair. IE9 doesn't even have an IE6 emulation. Only goes back as far as 7 as Plippie stated.Caducous
@JimWitte - Between 7% and 14%Dimitris
L
2

You want to use html tags and css compatible with mobile browsers.

For anything CSS3 wrap it in conditional javascript. I always make sure the device width is atleast 240px, then anything below that is the old, crappy, mobile look.

You can use a small mobile boilerplate for CSS, to reset the basic tags you use (make them look them same in different browsers). As with any boilerplate, you should look at the css to see if it's WAY overkill.

For a comprehensive guide check out the W3 Mobile CSS2 guidelines: http://www.w3.org/TR/2000/WD-css-mobile-20001013

Another good resource is this compatibility table: http://www.quirksmode.org/m/css.html

Laural answered 29/10, 2012 at 23:38 Comment(0)
O
1

Graceful Degradation is all about making compromises -- if you could do everything in the lower version, you probably would. To pick on the example of rounded corners you cite, it may acceptable to you (or your client) to live without them, where there don't exist renderer specific CSS extensions to support them (this is how http://www.ipswich-angle.com/ handles it, for example, I believe). Other options involving images are there, but it is largely dependant on what compromises you and your client are willing to make.

Ornithomancy answered 20/4, 2010 at 11:44 Comment(0)
T
1

A service like browsershots.org is quite useful to check how your site renders on different browsers and operating systems. You have to wait in a queue for a while but it's worth doing that.

Tartaglia answered 5/7, 2011 at 4:58 Comment(0)
R
0

I was going to make this a comment, but then I got carried away..

w3schools has suggestions for using semantic web elements on your site. It suggests using a Javascript library called html5shiv.js to add styling support to IE8 and below so you can find javascript files which emulate specific functionality built into HTML5 like JSON2.js and Webforms2.js.

Finally this article gives a full example of emulating a HTML5 form with many of the new attributes/functionality.

As for building the site, I'd recommend building a HTML4 site first using semantic elements freely (with html5shiv) and testing with IE7. Then as you build parts of the site that require new features, research a Javascript file that will provide older browsers with the same functionality, e.g: when it's time to add your first rounded corner or gradient maybe add CSS3Pie. Always remember as well that your box-model; border-radius and gradients are supported in webkit as well as mozilla's API so many css3 attributes you'll need to add 3 times:

border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;

Unfortunately I don't have a good resource for how the webkit/mozilla APIs compare with HTML5 functionality.

The only functionality I've struggled to find is support for CSS3 selectors in older browsers, often you can get away with this, I mean if you're not gonna upgrade your browser IMHO you can live with few double-thickness borders or missing alternate row styling in tables.

Maybe one day there will be a site that you can upload your code to that will tell you things like "chrome 20.xyz doesn't support rounded corners, add -webkit-border-radius to add support" but until then adding backwards compatibility after the fact will be near-impossible for complex sites.

Rance answered 13/5, 2013 at 13:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.