Doctype advice

groovyjon

Free Member
Jun 12, 2008
594
64
I'm currently in the process of re-writing our website so that it uses CSS for layout instead of tables, and eliminating old tags such as <center>.

One thing I'm confused about is that I need to put as a doctype. I've read various articles on the web and I'm still just as confused. It doesn't help that some of them were written several years ago so are probably out of date now.

Can anyone give me a brief explanation of doctype, what doctype I should be using, and what happens if I don't put a doctype?
 
F

Faevilangel

xhtml = extensible hyper text markup language = replacement for html
html 4 = old style html

I prefer to use xhtml, and you have 3 options, strict, transitional and frameset (don't use this).

I would go with xhtml strict but if you need to use tables and some older html coding then transitional will suffice. Strict just means the code is cleaner and no more use of blank="_target" and other html code.

this link explains a little and the actual doctype code
 
Upvote 0

groovyjon

Free Member
Jun 12, 2008
594
64
By the sounds of it transitional is what I'd need then. I will still use tables but only when presenting tabular data, not for layout.

I presume you meant target='_blank' above. I hadn't realised there was anything wrong with using that - I still have that code on our site.

When people talk about "validating an XHTML document". Does this mean validation at the editing stage using some XHTML editor (i.e. flagging when you've not closed a DIV or something) or does it mean validation by an end user's browser. If the latter, then what happens if it doesn't validate?
 
Upvote 0
F

Faevilangel

By the sounds of it transitional is what I'd need then. I will still use tables but only when presenting tabular data, not for layout.

I presume you meant target='_blank' above. I hadn't realised there was anything wrong with using that - I still have that code on our site.

When people talk about "validating an XHTML document". Does this mean validation at the editing stage using some XHTML editor (i.e. flagging when you've not closed a DIV or something) or does it mean validation by an end user's browser. If the latter, then what happens if it doesn't validate?

Good, tables for data and not layouts :D

It creates an error in xhtml strict, I use another method to the exact thing, using javascript (check my website code), any link that is external e.g. has http://www. will open in a new tab / window.

If a website doesn't validate then it doesn't hurt the site (unless you haven't closed an important div etc). No one can notice unless they look in the code, I always validate mine if I can though, as it just means cleaner code.
Traditional html elements like <img> and <meta> end in > while xhtml needs to end in />. That is the only main difference.
 
  • Like
Reactions: groovyjon
Upvote 0
K

Kev Jaques

Remember they're guidelines, plenty of things in the standards that can be argued/discussed. Such as target='_blank' can be added to strict doctype AND still validate (although this particular one is a weird issue) but in a slightly different way. Not everything is 100%.
Then you have HTML5 doctype, which is even simpler.
For what you want at this stage Transitional will suffice. If you don't use a doctype then browsers fall back to quirks mode for rendering.
 
Last edited by a moderator:
Upvote 0

groovyjon

Free Member
Jun 12, 2008
594
64
I'm still not 100% sure about this doctype business.

I've just put the following at the top of our page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Is this the "standard" transitional DTD?

It's not going to affect how I code, so I guess it just means I can be more certain how people will see the rendered page, as I test in each browser.
 
Upvote 0
K

Kev Jaques

Yep and it will affect how you code ;)
Depends on what browsers you are looking to support, if looking at the new gen then use HTML 5 doctype, even simpler.
Would probably be best to flick through the W3C specs on Doctype, it will give you some useful information you can digest (even if not all of it)
 
Upvote 0

groovyjon

Free Member
Jun 12, 2008
594
64
Yep and it will affect how you code ;)
Depends on what browsers you are looking to support, if looking at the new gen then use HTML 5 doctype, even simpler.
Would probably be best to flick through the W3C specs on Doctype, it will give you some useful information you can digest (even if not all of it)

Well according to Google Analytics, 65% of our visitors are using IE, and of those 55% use 8.0 and 33% use 7.0. Is the 8.0 what you're referring to when you say "new gen"?

And how will it affect how I code?? If I want to position a div absolutely then I'll position a div absolutely, regardless of what that DTD line might say!

I shall have a look at the W3C specs.
 
Upvote 0

rachelandrew

Free Member
Jun 15, 2005
10
3
The DOCTYPE just tells the browser what version of mark-up language you are using. If you don't use one at all then you leave it up to the browser to guess at what you want to do - it might guess something very strange! Modern browsers use something called 'doctype switching'. If you don't use a DOCTYPE at all or use an old DOCTYPE then some browsers will switch into Quirks mode - essentially displaying your page like IE5 which had a broken implementation of the box model so you will find all kinds of inconsistencies.

Use a strict DOCTYPE in development - either HTML or XHTML depending on your preferred style of markup. The deprecated stuff in strict is all the presentational stuff you should be replacing with CSS these days. If you have to copy in some crufty code then you might want to switch to Transitional when you deploy so you can still validate but definitely work and validate to strict.

You don't really need to worry about HTML5 unless you want to use something like HTML5 video at this point. You can code HTML5 in an HTML or XHTML way so if you need to move to HTML5 in the future when there is more browser support you won't need to change much if anything, just the DOCTYPE. If you do decide to use HTML5 right now then be aware that a lot of the really cool stuff doesn't yet have browser support so you will essentially be coding just as you would in latest versions of HTML or XHTML anyway.
 
  • Like
Reactions: groovyjon
Upvote 0

Latest Articles

Join UK Business Forums for free business advice