Click to See Complete Forum and Search --> : Am I using the right doctype for my website?


Danaldinho
04-04-2009, 02:54 PM
Hey,

I really don't understand the differences with the doctypes, even though I have read all about them.

I am wondering if this doctype:

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

is correct for all of my website and its pages (www.lilwaynehq.com)

Thanks alot and I appreciate it :)

dmboyd
04-04-2009, 03:24 PM
You only need to use a Transitional doctype if you need access to elements like iframe, font, etc. or attributes like bgcolor on the body element or the align attribute. If you need actual frames (as in html > frameset > frame), you would need to use a Frameset doctype. Otherwise, you can use a Strict doctype, though you would need to be careful with your CSS in such a case for a couple of reasons:


Documents using Transitional and Frameset doctypes are rendered in a mode known as "almost standards mode". This is supposed to be the same as "standards mode" except for the way the layouts of tables function.
Documents served as text/html, whether they're HTML or XHTML, use HTML rules for layout. These are a bit different than XML's rules, such as the body element being used as the canvas for text/html documents whereas the html element is the canvas in XHTML documents (when served using an XML or XHTML media type).



I'm fairly certain I just confused you, so to answer your question, I'll reply with a question of my own: do your pages work the way you want in the browsers you're targeting, and do they validate? If they do, then yes, you're using the correct doctype. If you have validation errors related to frames (not iframes), then you would need to switch to a frameset doctype. Otherwise, it's a matter of whether you want to use a Strict doctype or a Transitional doctype. Pages with Strict doctypes are rendered in standards mode, and those with Transitional doctypes are rendered in "almost standards" mode.

Make sense?

Charles
04-04-2009, 03:37 PM
The transitional doctypes were given to us to keep us going until browsers got around to supporting stylesheets. They've been doing that for long enough and so you should always use now the strict. The real question is, Why are you using XHTML? If you don't have a good reason then you might want to switch to HTML. If you do need XHTML then be careful. You have a lot of scripts on that page. If any of them use document.write you might be in trouble.

Danaldinho
04-05-2009, 06:52 AM
Wait, yes I am confused now :( :confused:

@dmboyd - Yes it does work fine and validate well

@Charles - I don't know why I am using XHTML as it came with the Wordpress them I was using, so do I change it or not? And why might I be in trouble with the "document.write"?

Thanks guys

Charles
04-05-2009, 08:40 AM
document.write doesn't work in XHTML. Some browsers might ignore that it's XHTML and treat the document as HTML--which can create some other problems. XHTML opens up a whole list of problems so it's best to avoid it if you can. It is far more important, though, to use the strict doctype and then get the page to validate and work well.