SitePoint Sponsor

User Tag List

Results 1 to 16 of 16
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question XHMTL 1.0 Transitional, Strict or XHTML 1.1

    Hi all,

    i have one question with regards to the DOCTYPE

    1. XHMTL 1.0 Transitional
    2. XHTML 1.0 Strict
    3. XHTML 1.1


    I can see most of the popular site like yahoo/sitepoint/aol, they always use either XHTML strict or Transitional, what about the XHTML 1.1, you have any idea why it is not widely used?

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The current doctype that should be used for new web pages is HTML 4.01 strict.

    Some people use XHTML 1.0 strict instead but unless you have no JavaScript in the page (so as to be able to serve it as HTML to IE and XHTML to other browsers) or are not bothering to support Internet Explorer then the page is really only HTML 4.01 strict with the wrong doctype.

    Transitional doctypes are for use in converting web pages from HTML 3.2 without having to completely rewrite them. They shouldn't be used for new sites.

    XHTML 1.1 can't be used with Internet Explorer at all which is why no one uses it.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by felgall View Post
    Some people use XHTML 1.0 strict instead but unless you have no JavaScript in the page (so as to be able to serve it as HTML to IE and XHTML to other browsers) or are not bothering to support Internet Explorer then the page is really only HTML 4.01 strict with the wrong doctype.
    Felgall as far as I am aware JavaScript would be unable (at least would not be used by default) to trigger the doctype switch in the first place because most JavaScript is activated upon rendering the page - as the specific thing it needs to detect is in response to HTTP_HEADER which would need to be processed upon page rendering. The general way in which people serve the correct doctype to IE and others is through serverside scripting embedded at the very peak of the page (so the processing is done before the page begins loading). Though you can also trigger it through htaccess.

    Though to the origional poster: Just use HTML 4.01, as Internet Explorer cannot make use of ANY XHTML (if its served in a way IE can see, its not XHTML, its simply invalid (x)HTML.) so felgall is correct that you should just forget about it.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by AlexDawson View Post
    Felgall as far as I am aware JavaScript would be unable (at least would not be used by default) to trigger the doctype switch in the first place
    I never said it could.

    I was referring to the fact that when doing anything involving the DOM with JavaScript you need to use either the HTML version of the DOM or the XHTML version of the DOM. As JavaScript has no way to tell which one it needs to call the JavaScript has to be written to work either with HTML or with XHTML. To be able to use server side doctype switching with a web page to be served both ways any JavaScript would need to be duplicated with a completely different JavaScript being referenced for each. This makes it complicated to use JavaScript at all if you are going to use doctype switching since you effectively need two complete copies of the same JavaScript with one written for HTML and one for XHTML. The only two ways to avoid that are to either not use JavaScript in the page at all or to not use doctype switching and always serve it as HTML.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  5. #5
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Arguably you would use XHTML 1.0 for IE (as you can legitimately use text/html for compatibility reasons) and XHTML 1.1 for other browsers, and you would not require any JavaScript or even touch your scripts to be able to make use of the doctype switch.

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by AlexDawson View Post
    Arguably you would use XHTML 1.0 for IE (as you can legitimately use text/html for compatibility reasons) and XHTML 1.1 for other browsers, and you would not require any JavaScript or even touch your scripts to be able to make use of the doctype switch.
    You are still missing the point I am trying to make.

    IF you use a doctype switch (server side obviously) then you need two separate versions of any JavaScript that the page uses since JavaScript written to use the HTML DOM will not work if the page is served as XHTML and JavaScript written to work with XHTML will not work if the page is served as HTML. If your page is going to use a doctype switch then it must either not contain JavaScript or must switch the JavaScript code completely so that the JavaScript uses the appropriate calls based on the doctype. You can't use feature sensing to determine what code to run in JavaScript because both createElement() and createElementNS() both exist in JavaScript, just only one will work at any one time depending on whether the page is HTML or XHTML.

    Adding a doctype switch to a web page that contains non-trivial JavaScript will break the JavaScript.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    And you are missing the point I made... if you declare it as XHTML 1.0 for Internet Explorer users it is still XHTML, it does not require independant JavaScripts and it will work in accordance with the W3C specification which allows XHTML 1.0 to be declared as text/html for the purpose of compatibility. Your entire topic about JavaScript is quite frankly overcomplicating the matter as having XHTML 1.1 for those which support XHTML and XHTML 1.0 (text/html) for those that don't are perfectly acceptable methods of implementing the doctype switch without affecting the content of the pages, scripting or otherwise.

  8. #8
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AlexDawson View Post
    if you declare it as XHTML 1.0 for Internet Explorer users it is still XHTML, it does not require independant JavaScripts and it will work in accordance with the W3C specification which allows XHTML 1.0 to be declared as text/html for the purpose of compatibility.
    No, Alex, you're wrong. If you serve the document as text/html to Internet Explorer, then it IS HTML. No matter what doctype declaration you use. You need to use the HTML DOM for JavaScript. If you're using content negotiation to serve the same document as an application of XML to supporting browsers, then you may need to fork your JavaScript code to use the XML DOM for those.

    @brown_eyes: As Stephen said, the best doctype to use at this time is HTML 4.01 Strict. HTML 4.01 is the most modern markup language with widespread support, and new documents should always use the Strict DTD and use CSS to control the presentation.
    Birnam wood is come to Dunsinane

  9. #9
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    Interesting Tommy, I'll have to remember that if I do any more XHTML work, then again I feel less inclined to do XHTML since everyone jumped ship on v2 so I stand by my origional post to the OP that 4.01 as it currently stands would be the best to use.

  10. #10
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    @brown_eyes: As Stephen said, the best doctype to use at this time is HTML 4.01 Strict. HTML 4.01 is the most modern markup language with widespread support, and new documents should always use the Strict DTD and use CSS to control the presentation.
    So could you tell me why Sitepoint.com use XHTML 1.0 Strict?

    and also let me sum up what all of you have said here:
    1. use HTML 4.01 strict for new design
    2. use html 4.01 transitional for old design for compatibility

    by the way, I just read an article on sitepoint that says that "for new site, we should use XHMTL 1.0 strict, and old design use XHTML 1.0 transitional".

    though, I am unable to post the link here as I do not have enough rights

  11. #11
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    May I first apologize for my question.

    Quote Originally Posted by felgall View Post
    Some people use XHTML 1.0 strict instead but unless you have no JavaScript in the page (so as to be able to serve it as HTML to IE and XHTML to other browsers) or are not bothering to support Internet Explorer then the page is really only HTML 4.01 strict with the wrong doctype.
    @felgall
    I still do not understand what you mentioned; Some people use XHTML 1.0 strict instead but unless you have no JavaScript in the page????

    because usually, for any new website design, I just jump directly to use XHTML 1.0 strict, yes, I just follow the concept of separating content from presentation. and I just know IE doesn't support XHTML.

    so in my page, i have Doctype XHTML 1.0 and then I add this line:
    HTML Code:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    Does this mean I am still using XHTML 1.0 mark-ups and tell the browser the contents inside the page is HTML?

    I am getting confused here.

  12. #12
    Follow: @AlexDawsonUK silver trophybronze trophy AlexDawson's Avatar
    Join Date
    Feb 2009
    Location
    England, UK
    Posts
    8,111
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    brown_eyes, it means that you are serving XHTML as HTML, which means that in reference to XHTML, your code may be valid but its being served invalidly, or in the case of HTML, its being served correctly, but the syntax doesnt conform to normal HTML, ergo... either way you use it, purists would say its bad code.

  13. #13
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by brown_eyes View Post
    So could you tell me why Sitepoint.com use XHTML 1.0 Strict?
    My guess is because the forum software generates XHTML markup and it's too much work (and no real point) in changing that. Also, some of the guys at SitePoint headquarters still seem to believe that pretend-XHTML (served as HTML) has some sort of benefit over honest HTML. (It doesn't. It can't, because it is HTML.)

    Quote Originally Posted by brown_eyes View Post
    and also let me sum up what all of you have said here:
    1. use HTML 4.01 strict for new design
    2. use html 4.01 transitional for old design for compatibility
    Well, yes...ish.
    The only reasons to use a Transitional DTD are,
    1. in the transitional (duh!) phase when converting pre-HTML4 documents to modern standards
    2. if you really need to cater to 10-year-old browsers with poor or no support for CSS.


    Quote Originally Posted by brown_eyes View Post
    by the way, I just read an article on sitepoint that says that "for new site, we should use XHMTL 1.0 strict, and old design use XHTML 1.0 transitional".
    There are all sorts of people saying all sorts of things. Unless they can back up their claims with solid arguments I tend to ignore them.

    You should be very sceptic about anything you read on the web. The freedom of expression the web has brought us also means that anyone can – and will – say anything. It's a good idea to double-check everything and to examine the credentials of the author before believing anything you read.

    Quote Originally Posted by brown_eyes View Post
    so in my page, i have Doctype XHTML 1.0 and then I add this line:
    HTML Code:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    Does this mean I am still using XHTML 1.0 mark-ups and tell the browser the contents inside the page is HTML?
    Actually, that line of code doesn't do anything useful at all, except for declaring the character encoding (if you server doesn't set the charset attribute in the Content-Type header).

    You cannot set the MIME type with a <meta> element, because a browser needs to know what to expect before it starts reading and parsing the content. This information must be sent in a real Content-Type HTTP header by the server.

    See the XHTML vs HTML FAQ for more details about the differences between XHTML and HTML.
    Birnam wood is come to Dunsinane

  14. #14
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    If you serve the document as text/html to Internet Explorer, then it IS HTML. No matter what doctype declaration you use. You need to use the HTML DOM for JavaScript. If you're using content negotiation to serve the same document as an application of XML to supporting browsers, then you may need to fork your JavaScript code to use the XML DOM for those.
    I didn't know this either. Good to know before I start writing JS for any of my pages, since some of them are legacy in XHTML (matching older web pages I copied/rewrote).

    @felgall
    I still do not understand what you mentioned; Some people use XHTML 1.0 strict instead but unless you have no JavaScript in the page????
    It doesn't matter if there's Javascript for those people using XHTML1.0 because they're just using that Doctype. What felgall meant was, people using Javascript on a page where they write real XHTML (with that application: xhtml+xml in the meta tag) but then have the server send HTML4 to IE (so then, the Javascript you have on your real XHTML page won't work for IE or anyone else getting the HTML4 version).

    The guys above are also saying that as far as Javascript and IE and actually all other browsers are concerned, if your meta tag/MIME type says "text/html" then it's pretty much the same as HTML4 to the browsers. Even if the Doctype at the top still says "XHTML".

    Does this mean I am still using XHTML 1.0 mark-ups and tell the browser the contents inside the page is HTML?
    Yes, *if that's your MIME type*, and the browsers look at your markup as errors, but errors they know how to deal with. Well, it's a bit more complicated because for instance you're supposed to be able to do this in HTML:
    <a href="somewhere"/>
    Make an element empty, and close it like that. You can't do that (well, that and anchors aren't supposed to be empty anyway, but I'm talking about the closing "/"). The browsers didn't get absolutely everything right when trying to implement SGML (what HTML is).

    This is why, in your XHTML1.0 pages, when you have those empty elements who must be closed, you were probably told to add a space first.

    <img src="" alt="" />
    instead of
    <img src="" alt=""/>

    That was because the browsers were seeing the document as HTML, didn't follow the rules that said that was actually ok in HTML, and so the older browsers wouldn't do the last one correctly (unless the page really was XHTML). I'm not sure if there are still browsers who can't deal with the closing tag without the space?

    So could you tell me why Sitepoint.com use XHTML 1.0 Strict?
    Some people think the X is seXy. Well, X's are sexy, no denying that. X-Men? X-Files? Yes, it's sexy. And once, it was The Future. You know, with flying cars and everything. Many developers feel XHTML is "stricter" but don't let that fool you— YOU the AUTHOR are the strict one, not the doctype. Though my next paragraph sounds like it's the other way:

    There's also a side-benefit if you're new: a "fake" XHTML page still requires you to close all your tags, which is just Very Good Practice in HTML4. So sending your pages to the validator, if you accidentally (not intentionally) forgot to close a <p> or a <li>, the XHTML validator will call you on it, while the HTML4 validator will not say a thing. So when you're new, it's not bad to get some extra reminders for small things.

    Sometimes I tell the validator to pretend my page is XHTML (when the doctype is HTML4) just to make sure on a very long page I didn't accidentally not close something. Esp with a lot of copy-pasting, that can happen.

    by the way, I just read an article on sitepoint that says that "for new site, we should use XHMTL 1.0 strict, and old design use XHTML 1.0 transitional".
    In your head, when you read that again, change it to:
    "for new site, we should use strict, and old design use transitional".
    And of course, "old" has to mean, "don't have time to get rid of all those <font> and <center> tags because the site is 1000 pages of steaming piles of tabled spaghetti code" : )

    *edit Tommy's post came while I was posting, though I blame it on the 5 minutes I spent waiting for the comment to go through : )

  15. #15
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The one situation where there is a benefit to XHTML that will be served as HTML is where your source is XML that is being converted into dozens of different XML formats for different purposes. Then your web pages are not the odd one out from all the rest because the code for all still really is XML.


    Whether the browser treats the file as HTML or XHTML depends on the MIME type set in the headers that come before the doctype.

    What we really need in order to be able to properly use XHTML with the web is a stylesheet that will allow an XHTML page served to IE as XML to be displayed correctly. Then we could use a doctype switch to serve the page to all browsers except IE as XHTML and serve it as XML to IE (along with the extra stylesheet to make it look the same). Then the same JavaScript could work in both places and our web documents would be valid XML the same as the copies of those same documents everywhere else and the web would no longer be the odd one out.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  16. #16
    SitePoint Member
    Join Date
    May 2008
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all Right now, I am using XHTML 1.0 Strict but I have no idea which to keep an eye on.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •