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

News
Jeremy Paxman has admitted he is a 'one-nation Tory' and complained that Newsnight is made by idealistic '13-year-olds' who foolishly think they can 'change the world'.
peopleThe idea has been greeted enthusiastically by the party's MPs
News
Michael Buerk in the I'm A Celebrity jungle 2014
people
Voices
File: David Cameron offers a toast during a State Dinner in his honour March 14, 2012
voicesAnd nobody from Ukip said babies born to migrants should be classed as migrants, says Nigel Farage
Arts and Entertainment
Avatar grossed $2.8bn at the box office after its release in 2009
filmJames Cameron is excited
PROMOTED VIDEO
Arts and Entertainment
Stik on the crane as he completed the mural
art
News
Happy in his hat: Pharrell Williams
people
Arts and Entertainment
Stella Gibson is getting closer to catching her killer
tvReview: It's gripping edge-of-the-seat drama, so a curveball can be forgiven at such a late stage
News
Brazilian football legend Pele pictured in 2011
peopleFans had feared the worst when it was announced the Brazil legand was in a 'special care' unit
News
i100(More than you think)
Sport
Brendan Rodgers seems more stressed than ever before as Liverpool manager
FOOTBALLI like Rodgers as a manager but Liverpool seem to be going backwards not forwards this season
News
The Magna Carta
archaeologyContemporary account of historic signing discovered
News
Phyllis Dorothy James on stage during a reading of her book 'Death Comes to Pemberley' last year
peopleJohn Walsh pays tribute to PD James, who died today
Sport
Benjamin Stambouli celebrates his goal for Tottenham last night
FOOTBALL
Life and Style
Dishing it out: the head chef in ‘Ratatouille’
food + drinkShould UK restaurants follow suit?
News
peopleExclusive: Maryum and Hana Ali share their stories of the family man behind the boxing gloves
Latest stories from i100
Have you tried new the Independent Digital Edition apps?

Day In a Page

Homeless Veterans Christmas Appeal: ‘We give them hope. They come to us when no one else can help’

Christmas Appeal

Meet the charity giving homeless veterans hope – and who they turn to when no one else can help
Should doctors and patients learn to plan humane, happier endings rather than trying to prolong life?

Is it always right to try to prolong life?

Most of us would prefer to die in our own beds, with our families beside us. But, as a GP, Margaret McCartney sees too many end their days in a medicalised battle
Thomas Cook's outgoing boss Harriet Green got by on four hours sleep a night - is that what it takes for women to get to the top?

What does it take for women to get to the top?

Thomas Cook's outgoing boss Harriet Green got by on four hours sleep a night and told women they had to do more if they wanted to get on
Christmas jumper craze: Inside the UK factory behind this year's multicultural must-have

Knitting pretty: British Christmas Jumpers

Simmy Richman visits Jack Masters, the company behind this year's multicultural must-have
French chefs have launched a campaign to end violence in kitchens - should British restaurants follow suit?

French chefs campaign against bullying

A group of top chefs signed a manifesto against violence in kitchens following the sacking of a chef at a Paris restaurant for scalding his kitchen assistant with a white-hot spoon
Radio 4 to broadcast 10-hour War and Peace on New Year's Day as Controller warns of cuts

Just what you need on a New Year hangover...

Radio 4 to broadcast 10-hour adaptation of War and Peace on first day of 2015
Cuba set to stage its first US musical in 50 years

Cuba to stage first US musical in 50 years

Claire Allfree finds out if the new production of Rent will hit the right note in Havana
Christmas 2014: 10 best educational toys

Learn and play: 10 best educational toys

Of course you want them to have fun, but even better if they can learn at the same time
Paul Scholes column: I like Brendan Rodgers as a manager but Liverpool seem to be going backwards not forwards this season

Paul Scholes column

I like Brendan Rodgers as a manager but Liverpool seem to be going backwards not forwards this season
Lewis Moody column: Stuart Lancaster has made all the right calls – now England must deliver

Lewis Moody: Lancaster has made all the right calls – now England must deliver

So what must the red-rose do differently? They have to take the points on offer 
Cameron, Miliband and Clegg join forces for Homeless Veterans campaign

Cameron, Miliband and Clegg join forces for Homeless Veterans campaign

It's in all our interests to look after servicemen and women who fall on hard times, say party leaders
Millionaire Sol Campbell wades into wealthy backlash against Labour's mansion tax

Sol Campbell cries foul at Labour's mansion tax

The former England defender joins Myleene Klass, Griff Rhys Jones and Melvyn Bragg in criticising proposals
Nicolas Sarkozy returns: The ex-President is preparing to fight for the leadership of France's main opposition party – but will he win big enough?

Sarkozy returns

The ex-President is preparing to fight for the leadership of France's main opposition party – but will he win big enough?
Is the criticism of Ed Miliband a coded form of anti-Semitism?

Is the criticism of Miliband anti-Semitic?

Attacks on the Labour leader have coalesced around a sense that he is different, weird, a man apart. But is the criticism more sinister?
Ouija boards are the must-have gift this Christmas, fuelled by a schlock horror film

Ouija boards are the must-have festive gift

Simon Usborne explores the appeal - and mysteries - of a century-old parlour game