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

Voices
There will be a chance to bid for a rare example of the SAS Diary, collated by a former member of the regiment in the aftermath of World War II but only published – in a limited run of just 5,000 – in 2011
charity appealTime is running out to secure your favourite lot as our auction closes at 2pm tomorrow
News
Elton John and David Furnish will marry on 21 December 2014
people
News
people
Arts and Entertainment
Caroline Flack became the tenth winner of Strictly Come Dancing
tvReview: 'Absolutely phenomenal' Xtra Factor presenter wins Strictly Come Dancing final
PROMOTED VIDEO
Life and Style
A still from the 1939 film version of Margaret Mitchell's 'Gone with the Wind'
life
Arts and Entertainment
J Jefferson Farjeon at home in 1953
booksBooksellers say readers are turning away from modern thrillers and back to golden age of crime writing
Sport
Amir Khan is engaged in a broader battle than attempting to win a fight with Floyd Mayweather
boxing Exclusive: Amir Khan reveals plans to travel to Pakistan
News
Stacey Dooley was the only woman to be nominated in last month’s Grierson awards
mediaClare Balding and Davina McCall among those overlooked for Grierson awards
Voices
Joseph Kynaston Reeves arguing with Russell Brand outside the RBS’s London offices on Friday
voicesDJ Taylor: The great tradition of St Paul and Zola reached its nadir with a worker's rant to Russell Brand
News
Twitchers see things differently, depending on their gender
scienceNew study shows that birdwatching men have a lot in common with their feathered friends...
News
i100
News
Xander van der Burgt, at the Royal Botanic Gardens, Kew
scienceA Kew Gardens botanist has found 25 new large tree species - and he's sure there are more out there
Latest stories from i100
Have you tried new the Independent Digital Edition apps?

Day In a Page

The week Hollywood got scared and had to grow up a bit

The week Hollywood got scared and had to grow up a bit

Sony suffered a chorus of disapproval after it withdrew 'The Interview', but it's not too late for it to take a stand, says Joan Smith
From Widow Twankey to Mother Goose, how do the men who play panto dames get themselves ready for the performance of a lifetime?

Panto dames: before and after

From Widow Twankey to Mother Goose, how do the men who play panto dames get themselves ready for the performance of a lifetime?
Thirties murder mystery novel is surprise runaway Christmas hit

Thirties murder mystery novel is surprise runaway Christmas hit

Booksellers say readers are turning away from dark modern thrillers and back to the golden age of crime writing
Anne-Marie Huby: 'Charities deserve the best,' says founder of JustGiving

Anne-Marie Huby: 'Charities deserve the best'

Ten million of us have used the JustGiving website to donate to good causes. Its co-founder says that being dynamic is as important as being kind
The botanist who hunts for giant trees at Kew Gardens

The man who hunts giants

A Kew Gardens botanist has found 25 new large tree species - and he's sure there are more out there
The 12 ways of Christmas: Spare a thought for those who will be working to keep others safe during the festive season

The 12 ways of Christmas

We speak to a dozen people who will be working to keep others safe, happy and healthy over the holidays
Birdwatching men have a lot in common with their feathered friends, new study shows

The male exhibits strange behaviour

A new study shows that birdwatching men have a lot in common with their feathered friends...
Diaries of Evelyn Waugh, Virginia Woolf and Noël Coward reveal how they coped with the December blues

Famous diaries: Christmas week in history

Noël Coward parties into the night, Alan Clark bemoans the cost of servants, Evelyn Waugh ponders his drinking…
From noble to narky, the fall of the open letter

From noble to narky, the fall of the open letter

The great tradition of St Paul and Zola reached its nadir with a hungry worker's rant to Russell Brand, says DJ Taylor
A Christmas ghost story by Alison Moore: A prodigal daughter has a breakthrough

A Christmas ghost story by Alison Moore

The story was published earlier this month in 'Poor Souls' Light: Seven Curious Tales'
Marian Keyes: The author on her pre-approved Christmas, true love's parking implications and living in the moment

Marian Keyes

The author on her pre-approved Christmas, true love's parking implications and living in the moment
Bill Granger recipes: Our chef creates an Italian-inspired fish feast for Christmas Eve

Bill Granger's Christmas Eve fish feast

Bill's Italian friends introduced him to the Roman Catholic custom of a lavish fish supper on Christmas Eve. Here, he gives the tradition his own spin…
Liverpool vs Arsenal: Brendan Rodgers is fighting for his reputation

Rodgers fights for his reputation

Liverpool manager tries to stay on his feet despite waves of criticism
Amir Khan: 'The Taliban can threaten me but I must speak out... innocent kids, killed over nothing. It’s sick in the mind'

Amir Khan attacks the Taliban

'They can threaten me but I must speak out... innocent kids, killed over nothing. It’s sick in the mind'
Michael Calvin: Sepp Blatter is my man of the year in sport. Bring on 2015, quick

Michael Calvin's Last Word

Sepp Blatter is my man of the year in sport. Bring on 2015, quick