SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Evangelist kooshin.com's Avatar
    Join Date
    Dec 2003
    Location
    http://kooshin.com
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XHTML 1.0 Transitional V XHTML 1.0 Strict

    hi guys. I have a question.I don't know if it has been asked already but as the title suggests which one should be used most of the time? I have seen some people saying it is better to use the XHTML 1.0 Transitional while others say it is XHTML Strict that is the best and the one that should be used.


    XHTML 1.0 Transitional VS XHTML 1.0 Strict

    Your say?



    Thanks in advance.

  2. #2
    Function Curry'er JimmyP's Avatar
    Join Date
    Aug 2007
    Location
    Brighton, UK
    Posts
    2,006
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Always try to use a strict DTD. It may take longer to code in some instances but it is worth it. A strict DTD is more future proof since it does not allow depreciated elements (such as <u>, <iframe> and <center>) and attributes (such as 'background' & 'target') and because it promotes the ideals... i.e. content and presentation being truly seperate.

    For example in a transitionally coded page it is "okay" to do this:

    Code:
    <p align="center">
    While in a strictly coded page you must do this for it to be valid strict:

    Code:
    <p style="text-align:center">
    Actually, ideally, you should do this: (and have the corresponding CSS to handle it)

    Code:
    <p class="center">
    A Tranistional DTD should only really be used when marking up legacy code, but even then you should still take the time to code in strict, which is afterall, the way it's meant to be...

    Using a strict DTD is the way it's meant to be done!

    Actually, you shouldn't be using XHTML at all unless you are prepared to use a content-type of XML... Otherwise it will just be rendered as HTML anyway (I am not entirely sure on this point)...
    James Padolsey
    末末末末末末末末末末末末末末末末末末末
    Awesome JavaScript Zoomer (demo here)
    'Ajaxy' - Ajax integration solution (demo here)

  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The 'best' DTD to use for 99.99999&#37; of us is HTML 4.01 Strict. Very few of us have anything to gain from using XHTML, and as long as Internet Explorer doesn't support it we can't use XHTML for anything serious anyway.

    Sure, you can pretend to use XHTML and serve it as HTML, but you gain nothing, and you rely on browser bugs to make things work.

    If you decide to use pretend-XHTML, go with XHTML 1.0 Strict.
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Evangelist kooshin.com's Avatar
    Join Date
    Dec 2003
    Location
    http://kooshin.com
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi guys thanks for the answers. Some people say when you use the strict DTD it might not work well on some old browsers.I'm not sure about this. Some say it is a little strict and too hard.

  5. #5
    SitePoint Evangelist croatiankid's Avatar
    Join Date
    Mar 2007
    Location
    Zagreb, Croatia
    Posts
    409
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Konqueror 3.2 goes into quirks mode with a transitional XHTML doctype. What is Konquerer?
    Hrvoje Markovic
    Croatiankid designs

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Transitional doctypes are for existing web pages and site templates where you haven't yet had time to rework them to follow the current standards. For new work you should always use a strict doctype. Unless you have a specific reason for selecting XHTML 1.0 you should use HTML 4.01.
    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
    SitePoint Zealot
    Join Date
    Apr 2008
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    transitional allows the use of forbidden tags
    Last edited by web67; Apr 15, 2008 at 20:08.
    Keep Up to date about everthing Website Flipping
    Find out how to same thousands on your Mortgage Broker fees.

  8. #8
    Sesame Street Iimitk's Avatar
    Join Date
    Feb 2006
    Posts
    662
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    ...we can't use XHTML for anything serious anyway.
    Without taking the above quote out of its syntax, could you elaborate more on this Tommy?

    I too prefer to code in HTML 4.01 Strict, but I find myself obliged to use XHTML sometimes, because some CMSs do content formatting and input conversion in XHTML. A clear example of this is converting line breaks to <br /> instead of <br>.

    What can go wrong in the future if I developed a site in XHTML?
    Imagination is more important than knowledge. - Einstein

  9. #9
    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 kooshin.com View Post
    Hi guys thanks for the answers. Some people say when you use the strict DTD it might not work well on some old browsers.I'm not sure about this. Some say it is a little strict and too hard.
    The Transitional DTDs for HTML 4.01 and XHTML 1.0 allow the use of presentational elements and attributes, and are meant as an intermediate (transitional) step when converting old pre-HTML4 documents to more modern markup. The idea is that you use a Transitional doctype declaration so that you can validate the markup and get rid of all the syntax errors. Then you remove the presentational markup and add a CSS style sheet to handle presentation. Finally, you replace the Transitional doctype declaration with the Strict version and validate to make sure you've got everything right.

    Really old browsers don't have adequate CSS support, and some things won't be possible to achieve in those browsers. On the other hand, very few people use such old browsers these days and they should accept a degraded experience (in my opinion) since there are better alternatives available for free.

    As Stephen said, for new documents you should only consider a Strict DTD.

    Quote Originally Posted by simsim View Post
    Without taking the above quote out of its syntax, could you elaborate more on this Tommy?
    Internet Explorer doesn't support XHTML, which means you can only use pretend-XHTML. But that's really just HTML with syntax errors – it's not XML, so you can't use any XML features (like other namespaces). In fact, you can't use anything that isn't supported in HTML.

    See the XHTML vs HTML FAQ for details.

    Quote Originally Posted by simsim View Post
    What can go wrong in the future if I developed a site in XHTML?
    Let's say you develop a site with pretend-XHTML. You don't check it to see if it works as real XHTML, because you don't understand the fundamental difference. It looks okay in all browsers and you're happy.

    Then, one sunny day Microsoft releases a new version of IE with full XHTML support. People update their browsers and soon the market share of old IE versions has dropped to the point where you can actually contemplate using real XHTML.

    You instruct the server to send the Content-Type HTTP header as application/xhtml+xml and are shocked to find that nothing works anymore. All your visitors get is an error message about a well-formedness error because you've used named character entities. Or parts of the page is missing because you've generated it dynamically with document.write() in JavaScript. Or it looks out of whack because you've used uppercase type selectors in your CSS.

    XHTML is an XML version of HTML. But XML isn't intended for marking up web pages; it's for data storage and inter-application communication.
    Birnam wood is come to Dunsinane

  10. #10
    Sesame Street Iimitk's Avatar
    Join Date
    Feb 2006
    Posts
    662
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo View Post
    You instruct the server to send the Content-Type HTTP header as application/xhtml+xml and are shocked to find that nothing works anymore. All your visitors get is an error message about a well-formedness error because you've used named character entities. Or parts of the page is missing because you've generated it dynamically with document.write() in JavaScript. Or it looks out of whack because you've used uppercase type selectors in your CSS.
    So if I understood you correctly serving XHTML documents as HTML by setting the Content-Type to text/html forces even browsers who fully support XHTML (Firefox, Opera, etc.) to serve it as HTML as well? As if I'm punishing myself & the good browsers for the sake of the bad one? How ugly!

    Still the problem occurs when you face situations that force you to use XHTML. For example, the Textpattern CMS (linked to in my sig), uses a special internal tagging system to introduce various functionality. That system is built with compliance with XHTML syntax for strictness. For example you would write <txp:permlink /> to output a formatted link to the page. All such tags use XHTML syntax for all empty elements by default and there's no simple way of changing it.

    I wonder why not the HTML5 working group support the XHTML strict syntax, at least as an alternative that would not invalidate so properly written documents only because they don't have trailing slashes at the end of empty elements.
    Imagination is more important than knowledge. - Einstein

  11. #11
    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 simsim View Post
    So if I understood you correctly serving XHTML documents as HTML by setting the Content-Type to text/html forces even browsers who fully support XHTML (Firefox, Opera, etc.) to serve it as HTML as well?
    Anything served as text/html must be parsed and interpreted as HTML. Even if it's an XHTML document, a Word document or a JPEG image.

    If you want your XHTML markup to be recognised and treated as XHTML, you must serve it as an 'application of XML'. The preferred MIME type is application/xhtml+xml, but you could also use application/xml. (The old text/xml is a theoretical possibility, but its use is deprecated due to its odd rules about character encoding.)
    Birnam wood is come to Dunsinane

  12. #12
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You can test for MIME type support and serve HTML to browsers that don't support XHTML (ie. IE) and XHTML to everything else but since that means that your XHTML needs to be able to be processed as HTML with a few extra / and you need the JavaScript to use createElement() for one and createElementNS() for the other the difficulties of doing so far outweigh the benefits.
    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="^$">

  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)
    If you do that, you should rewrite the content as HTML for user agents that don't support XHTML. Unless you've got an advanced DOM-based system, that's risky, though.

    Content negotiation is useless for HTML/XHTML. If it needs to work as HTML anyway, you might as well serve HTML to everyone. There'll be no gains in serving XHTML to supporting user agents; only disadvantages (draconian error handling, lack of incremental rendering).
    Birnam wood is come to Dunsinane


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
  •