What flavour is your HTML?

If you are anything like me, your HTML code is a mish-mash of standard HTML tags, browser specific tags, and whatever else it takes to get your design to look the way you want it to on the majority of browsers. I worry less about what the standards are and more about what is going to get the job done. This often means using a hybrid of HTML code to hack together pages, duplicating code for different browsers and often using JavaScript just to deliver the right layout for the right browser.

If you are anything like me, your HTML code is a mish-mash of standard HTML tags, browser specific tags, and whatever else it takes to get your design to look the way you want it to on the majority of browsers. I worry less about what the standards are and more about what is going to get the job done. This often means using a hybrid of HTML code to hack together pages, duplicating code for different browsers and often using JavaScript just to deliver the right layout for the right browser.

The problem is that, despite the standards, each browser, version and platform works differently even if only slightly so.

The Extensible Markup Language (XML) and Extensible Style Language (XSL) hold the promise of allowing Web designers to separate the display of content from its actual layout. This will, hopefully, free us from many of the worries of the particular quirks of a browser.

However, despite the recent ratification of a stepping stone to that future in the form of XHTML, browsers continue to be "flawed", at least from a standards point of view.

Recognizing that we live in a flawed World Wide Web, the World Wide Web Consortium has introduced three "flavours" of HTML code in the recently revised HTML 4.01 standard. These three flavors allow Web designers to declare what form their HTML will take: strict, transitional or frameset.

So, I am sure you are scratching your head in wonder, how does the browser know what flavor I am using? Simple, you have to place a <!DOCTYPE> tag at the very top of every Web page, before the tag in fact, to the browser what Document Type Definition (DTD) it should use.

HTML 4.0 Strict The strict form of HTML is nothing but the standard tags HTML 4.01 tags. It's rare that you will see any site - even the W3C's own Web site - using this one. The fact is, standards are great, but no Web browser out there follows them 100 per cent. However, if you are really sure of your coding capabilities, place this tag at the top of your page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

HTML 4.0 Transitional Transitional HTML is what most people are using now. It includes all of the HTML 4.0 tags, but also allows you to include tags and attributes that are either being "depreciated" (ie, eliminated) from the HTML standard or are used only by a specific browser. Unfortunately, due to incompatibilities between different browser types, some of the power of HTML 4.01 will be sacrificed when using transitional HTML. For example, table elements will not be able to inherit styles and font sizes will very more radically.

More than likely you will want to use the transitional <!DOCTYPE> in your HTML code for the foreseeable future, at least until the overwhelming majority of browsers being used are standards compliant. In theory, the transitional <!DOCTYPE> tag should look like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

Unfortunately, this version of the tag still causes IE5/Mac (the only browser to currently make use of the <!DOCTYPE>) to act as if this is strict HTML 4.01 code. This can cause your page to display improperly as I learned the first time I fired my own site up with IE5/Mac. The good news is that there is an easy way around this: take the URL out, thus:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

HTML 4.0 Frameset Finally, frames deserve there own <!DOCTYPE> . If your HTML document is a frameset definition, then you want to use this one:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">

Validating your pages and !DOCTYPE switching The fact is, however, if you don't add the <!DOCTYPE> to your Web pages, most Web browsers will never notice. However, if you want to check your HTML code for accuracy, by including the <!DOCTYPE> you can then use the W3C's HTML validator to check your code for "accuracy".

Once you have fixed all of these errors you get a nifty "HTML 4.0" button that you can add to the mass of graphics that are cluttering your page. And now your HTML will work everywhere, right. No, not really. Actually, only a very few people surfing the Web right now with anything close to a standards compliant browser, much to many Web designer's chagrin.

But the times they are a changing.

Although currently the only non-beta browser that actually even notices the <!DOCTYPE> tag is IE5/Mac, Navigator 6 and iCab should also make use of it when they are finally released later this year. These programs will use the <!DOCTYPE> tag to validate pages on the fly, allowing the browser to determine the difference between a backwards compatible page (transitional) and a standardised page (strict). This is known as "doctype switching" and will allow standards based browsers to take advantage of the power of HTML 4.01 when the standards are obeyed while still being able to properly render older Web pages.

Jason Cranford Teague is the author of DHTML For the World Wide Web, available from book stores around the UK. If you have questions, you can find an archive of his column at Webbed Environments or email him at jason@webbedenvironments.com

PROMOTED VIDEO
Travel
travel
News
Tim Vine has won the funniest joke award at the Edinburgh Festival 2014
peopleTim Vine, winner of the Funniest Joke of the Fringe award, has nigh-on 200 in his act. So how are they conceived?
News
people
Life and Style
techApp to start sending headlines, TV clips and ads to your phone
Arts and Entertainment
Taylor Swift crawls through the legs of twerking dancers in her 'Shake It Off' music video
musicEarl Sweatshirt thinks so
Life and Style
tech
Arts and Entertainment
Daniel Radcliffe and Zoe Kazan in What If
filmReview: Actor swaps Harry Potter for Cary Grant in What If
News
Our resilience to stress is to a large extent determined by our genes
science
Travel
travel
Sport
sportBesiktas 0 Arsenal 0: Champions League qualifying first-leg match ends in stalemate in Istanbul
News
Pornography is more accessible - and harder to avoid - than ever
news... but they still admit watching it
Latest stories from i100
Have you tried new the Independent Digital Edition apps?

Day In a Page

Ferguson: In the heartlands of America, a descent into madness

A descent into madness in America's heartlands

David Usborne arrived in Ferguson, Missouri to be greeted by a scene more redolent of Gaza and Afghanistan
BBC’s filming of raid at Sir Cliff’s home ‘may be result of corruption’

BBC faces corruption allegation over its Sir Cliff police raid coverage

Reporter’s relationship with police under scrutiny as DG is summoned by MPs to explain extensive live broadcast of swoop on singer’s home
Lauded therapist Harley Mille still in limbo as battle to stay in Britain drags on

Lauded therapist still in limbo as battle to stay in Britain drags on

Australian Harley Miller is as frustrated by court delays as she is with the idiosyncrasies of immigration law
Lewis Fry Richardson's weather forecasts changed the world. But could his predictions of war do the same?

Lewis Fry Richardson's weather forecasts changed the world...

But could his predictions of war do the same?
Kate Bush asks fans not to take photos at her London gigs: 'I want to have contact with the audience, not iPhones'

'I want to have contact with the audience, not iPhones'

Kate Bush asks fans not to take photos at her London gigs
Under-35s have rated gardening in their top five favourite leisure activities, but why?

Young at hort

Under-35s have rated gardening in their top five favourite leisure activities. But why are so many people are swapping sweaty clubs for leafy shrubs?
Tim Vine, winner of the Funniest Joke of the Fringe award: 'making a quip as funny as possible is an art'

Beyond a joke

Tim Vine, winner of the Funniest Joke of the Fringe award, has nigh-on 200 in his act. So how are they conceived?
The late Peter O'Toole shines in 'Katherine of Alexandria' despite illness

The late Peter O'Toole shines in 'Katherine of Alexandria' despite illness

Sadly though, the Lawrence of Arabia star is not around to lend his own critique
Wicken Fen in Cambridgeshire: The joy of camping in a wetland nature reserve and sleeping under the stars

A wild night out

Wicken Fen in Cambridgeshire offers a rare chance to camp in a wetland nature reserve
Comic Sans for Cancer exhibition: It’s the font that’s openly ridiculed for its jaunty style, but figures of fun have their fans

Comic Sans for Cancer exhibition

It’s the font that’s openly ridiculed for its jaunty style, but figures of fun have their fans
Besiktas vs Arsenal: Five things we learnt from the Champions League first-leg tie

Besiktas vs Arsenal

Five things we learnt from the Champions League first-leg tie
Rory McIlroy a smash hit on the US talk show circuit

Rory McIlroy a smash hit on the US talk show circuit

As the Northern Irishman prepares for the Barclays, he finds time to appear on TV in the States, where he’s now such a global superstar that he needs no introduction
Boy racer Max Verstappen stays relaxed over step up to Formula One

Boy racer Max Verstappen stays relaxed over step up to F1

The 16-year-old will become the sport’s youngest-ever driver when he makes his debut for Toro Rosso next season
Fear brings the enemies of Isis together at last

Fear brings the enemies of Isis together at last

But belated attempts to unite will be to no avail if the Sunni caliphate remains strong in Syria, says Patrick Cockburn
Charlie Gilmour: 'I wondered if I would end up killing myself in jail'

Charlie Gilmour: 'I wondered if I'd end up killing myself in jail'

Following last week's report on prison suicides, the former inmate asks how much progress we have made in the 50 years since the abolition of capital punishment